From a1be924fa4ca03876991a12cab03454d243c1fd2 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 9 Jan 2023 15:29:22 +0100 Subject: [PATCH] *: strip leading and trailing whitespace when reading config values from files also add a debug endpoint that dumps the go parsed config Signed-off-by: Jens Langhammer --- authentik/lib/config.py | 2 +- internal/config/config.go | 2 +- internal/debug/debug.go | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/authentik/lib/config.py b/authentik/lib/config.py index 0857d0bf4..2df04ceea 100644 --- a/authentik/lib/config.py +++ b/authentik/lib/config.py @@ -93,7 +93,7 @@ class ConfigLoader: if url.scheme == "file": try: with open(url.path, "r", encoding="utf8") as _file: - value = _file.read() + value = _file.read().strip() except OSError as exc: self.log("error", f"Failed to read config value from {url.path}: {exc}") value = url.query diff --git a/internal/config/config.go b/internal/config/config.go index 72cc9f58b..45c7ee1f4 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -135,7 +135,7 @@ func (c *Config) parseScheme(rawVal string) string { if err != nil { return u.RawQuery } - return string(d) + return strings.TrimSpace(string(d)) } return rawVal } diff --git a/internal/debug/debug.go b/internal/debug/debug.go index eefb68c84..9e8055ca4 100644 --- a/internal/debug/debug.go +++ b/internal/debug/debug.go @@ -1,6 +1,7 @@ package debug import ( + "encoding/json" "fmt" "net/http" "net/http/pprof" @@ -23,6 +24,12 @@ func EnableDebugServer() { h.HandleFunc("/debug/pprof/profile", pprof.Profile) h.HandleFunc("/debug/pprof/symbol", pprof.Symbol) h.HandleFunc("/debug/pprof/trace", pprof.Trace) + h.HandleFunc("/debug/dump_config", func(w http.ResponseWriter, r *http.Request) { + enc := json.NewEncoder(w) + enc.SetEscapeHTML(true) + enc.SetIndent("", "\t") + enc.Encode(config.Get()) + }) h.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { _ = h.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error { tpl, err := route.GetPathTemplate()