提交 a03433d5 编写于 作者: J Jeff 提交者: zryfish

strip senstive information

上级 aba51265
......@@ -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()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册