*: 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 <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer 2023-01-09 15:29:22 +01:00
parent db60427e21
commit a1be924fa4
No known key found for this signature in database
3 changed files with 9 additions and 2 deletions

View File

@ -93,7 +93,7 @@ class ConfigLoader:
if url.scheme == "file": if url.scheme == "file":
try: try:
with open(url.path, "r", encoding="utf8") as _file: with open(url.path, "r", encoding="utf8") as _file:
value = _file.read() value = _file.read().strip()
except OSError as exc: except OSError as exc:
self.log("error", f"Failed to read config value from {url.path}: {exc}") self.log("error", f"Failed to read config value from {url.path}: {exc}")
value = url.query value = url.query

View File

@ -135,7 +135,7 @@ func (c *Config) parseScheme(rawVal string) string {
if err != nil { if err != nil {
return u.RawQuery return u.RawQuery
} }
return string(d) return strings.TrimSpace(string(d))
} }
return rawVal return rawVal
} }

View File

@ -1,6 +1,7 @@
package debug package debug
import ( import (
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"net/http/pprof" "net/http/pprof"
@ -23,6 +24,12 @@ func EnableDebugServer() {
h.HandleFunc("/debug/pprof/profile", pprof.Profile) h.HandleFunc("/debug/pprof/profile", pprof.Profile)
h.HandleFunc("/debug/pprof/symbol", pprof.Symbol) h.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
h.HandleFunc("/debug/pprof/trace", pprof.Trace) 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.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_ = h.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error { _ = h.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
tpl, err := route.GetPathTemplate() tpl, err := route.GetPathTemplate()