mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-01 01:41:13 -06:00
config dump endpoint for proxy
This commit is contained in:
@@ -20,6 +20,7 @@ type Options struct {
|
||||
Zpages bool
|
||||
Health func(http.ResponseWriter, *http.Request)
|
||||
Ready func(http.ResponseWriter, *http.Request)
|
||||
ConfigDump func(http.ResponseWriter, *http.Request)
|
||||
CorsAllowedOrigins []string
|
||||
CorsAllowedMethods []string
|
||||
CorsAllowedHeaders []string
|
||||
@@ -100,6 +101,13 @@ func Ready(r func(http.ResponseWriter, *http.Request)) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// ConfigDump to be documented.
|
||||
func ConfigDump(r func(http.ResponseWriter, *http.Request)) Option {
|
||||
return func(o *Options) {
|
||||
o.ConfigDump = r
|
||||
}
|
||||
}
|
||||
|
||||
// CorsAllowedOrigins provides a function to set the CorsAllowedOrigin option.
|
||||
func CorsAllowedOrigins(origins []string) Option {
|
||||
return func(o *Options) {
|
||||
|
||||
@@ -28,6 +28,10 @@ func NewService(opts ...Option) *http.Server {
|
||||
mux.HandleFunc("/healthz", dopts.Health)
|
||||
mux.HandleFunc("/readyz", dopts.Ready)
|
||||
|
||||
if dopts.ConfigDump != nil {
|
||||
mux.HandleFunc("/config", dopts.ConfigDump)
|
||||
}
|
||||
|
||||
if dopts.Pprof {
|
||||
mux.HandleFunc("/debug/pprof/", pprof.Index)
|
||||
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package debug
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
@@ -22,6 +23,7 @@ func Server(opts ...Option) (*http.Server, error) {
|
||||
debug.Zpages(options.Config.Debug.Zpages),
|
||||
debug.Health(health(options.Config)),
|
||||
debug.Ready(ready(options.Config)),
|
||||
debug.ConfigDump(configDump(options.Config)),
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -52,3 +54,17 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// configDump implements the config dump
|
||||
func configDump(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
b, err := json.Marshal(cfg)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
_, _ = w.Write(b)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user