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()