feat: verifying and enabling necessary extensions for ui (#1369)

Signed-off-by: Ana-Roberta Lisca <ana.kagome@yahoo.com>
This commit is contained in:
Lisca Ana-Roberta
2023-05-12 19:43:14 +03:00
committed by GitHub
parent 7d7bc9d5e4
commit e262fbea64
5 changed files with 169 additions and 42 deletions
+16 -9
View File
@@ -66,17 +66,24 @@ type mgmt struct {
log log.Logger
}
func (mgmt *mgmt) handler(response http.ResponseWriter, request *http.Request) {
sanitizedConfig := mgmt.config.Sanitize()
func (mgmt *mgmt) handler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
sanitizedConfig := mgmt.config.Sanitize()
buf, err := common.MarshalThroughStruct(sanitizedConfig, &StrippedConfig{})
if err != nil {
mgmt.log.Error().Err(err).Msg("mgmt: couldn't marshal config response")
w.WriteHeader(http.StatusInternalServerError)
}
_, _ = w.Write(buf)
})
}
buf, err := common.MarshalThroughStruct(sanitizedConfig, &StrippedConfig{})
if err != nil {
mgmt.log.Error().Err(err).Msg("mgmt: couldn't marshal config response")
func addMgmtSecurityHeaders(h http.Handler) http.HandlerFunc { //nolint:varnamelen
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Content-Type-Options", "nosniff")
response.WriteHeader(http.StatusInternalServerError)
h.ServeHTTP(w, r)
}
_, _ = response.Write(buf)
}
func SetupMgmtRoutes(config *config.Config, router *mux.Router, log log.Logger) {
@@ -85,6 +92,6 @@ func SetupMgmtRoutes(config *config.Config, router *mux.Router, log log.Logger)
mgmt := mgmt{config: config, log: log}
router.PathPrefix(constants.ExtMgmtPrefix).Methods("GET").HandlerFunc(mgmt.handler)
router.PathPrefix(constants.ExtMgmtPrefix).Methods("GET").Handler(addMgmtSecurityHeaders(mgmt.handler()))
}
}