From a03433d53880439796a30ee8f7dbe9263fae79ba Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 10 Oct 2019 11:56:38 +0800 Subject: [PATCH] strip senstive information --- pkg/server/config/config.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/pkg/server/config/config.go b/pkg/server/config/config.go index e1a064125..ef6329d91 100644 --- a/pkg/server/config/config.go +++ b/pkg/server/config/config.go @@ -22,6 +22,8 @@ import ( "kubesphere.io/kubesphere/pkg/simple/client/servicemesh" "kubesphere.io/kubesphere/pkg/simple/client/sonarqube" "net/http" + "reflect" + "strings" ) // Package config saves configuration for running KubeSphere components @@ -64,7 +66,7 @@ func InstallAPI(c *restful.Container) { conf.stripEmptyOptions() - response.WriteAsJson(conf) + response.WriteAsJson(convertToMap(&conf)) }). Doc("Get system components configuration"). Produces(restful.MIME_JSON). @@ -74,6 +76,33 @@ func InstallAPI(c *restful.Container) { c.Add(ws) } +// convertToMap simply converts config to map[string]bool +// to hide sensitive information +func convertToMap(conf *Config) map[string]bool { + result := make(map[string]bool, 0) + + if conf == nil { + return result + } + + c := reflect.Indirect(reflect.ValueOf(conf)) + + for i := 0; i < c.NumField(); i++ { + name := strings.Split(c.Type().Field(i).Tag.Get("json"), ",")[0] + if strings.HasPrefix(name, "-") { + continue + } + + if c.Field(i).IsNil() { + result[name] = false + } else { + result[name] = true + } + } + + return result +} + // Load loads configuration after setup func Load() error { sharedConfig = newConfig()