Merge pull request #3045 from ywk253100/170814_config

[BAT]Remove useless attributes in configuration API
This commit is contained in:
Wenkai Yin 2017-08-15 12:18:06 +08:00 committed by GitHub
commit bb00c2c2cf

View File

@ -27,17 +27,10 @@ import (
) )
var ( var (
// valid keys of configurations which user can modify // the keys of configurations which user can modify in PUT method and user can
// get in GET method
validKeys = []string{ validKeys = []string{
common.ExtEndpoint,
common.AUTHMode, common.AUTHMode,
common.DatabaseType,
common.MySQLHost,
common.MySQLPort,
common.MySQLUsername,
common.MySQLPassword,
common.MySQLDatabase,
common.SQLiteFile,
common.SelfRegistration, common.SelfRegistration,
common.LDAPURL, common.LDAPURL,
common.LDAPSearchDN, common.LDAPSearchDN,
@ -47,8 +40,6 @@ var (
common.LDAPFilter, common.LDAPFilter,
common.LDAPScope, common.LDAPScope,
common.LDAPTimeout, common.LDAPTimeout,
common.TokenServiceURL,
common.RegistryURL,
common.EmailHost, common.EmailHost,
common.EmailPort, common.EmailPort,
common.EmailUsername, common.EmailUsername,
@ -58,49 +49,31 @@ var (
common.EmailIdentity, common.EmailIdentity,
common.ProjectCreationRestriction, common.ProjectCreationRestriction,
common.VerifyRemoteCert, common.VerifyRemoteCert,
common.MaxJobWorkers,
common.TokenExpiration, common.TokenExpiration,
common.CfgExpiration,
common.JobLogDir,
common.AdminInitialPassword,
common.ScanAllPolicy, common.ScanAllPolicy,
} }
stringKeys = []string{ stringKeys = []string{
common.ExtEndpoint,
common.AUTHMode, common.AUTHMode,
common.DatabaseType,
common.MySQLHost,
common.MySQLUsername,
common.MySQLPassword,
common.MySQLDatabase,
common.SQLiteFile,
common.LDAPURL, common.LDAPURL,
common.LDAPSearchDN, common.LDAPSearchDN,
common.LDAPSearchPwd, common.LDAPSearchPwd,
common.LDAPBaseDN, common.LDAPBaseDN,
common.LDAPUID, common.LDAPUID,
common.LDAPFilter, common.LDAPFilter,
common.TokenServiceURL,
common.RegistryURL,
common.EmailHost, common.EmailHost,
common.EmailUsername, common.EmailUsername,
common.EmailPassword, common.EmailPassword,
common.EmailFrom, common.EmailFrom,
common.EmailIdentity, common.EmailIdentity,
common.ProjectCreationRestriction, common.ProjectCreationRestriction,
common.JobLogDir,
common.AdminInitialPassword,
} }
numKeys = []string{ numKeys = []string{
common.EmailPort, common.EmailPort,
common.LDAPScope, common.LDAPScope,
common.LDAPTimeout, common.LDAPTimeout,
common.MySQLPort,
common.MaxJobWorkers,
common.TokenExpiration, common.TokenExpiration,
common.CfgExpiration,
} }
boolKeys = []string{ boolKeys = []string{
@ -110,10 +83,8 @@ var (
} }
passwordKeys = []string{ passwordKeys = []string{
common.AdminInitialPassword,
common.EmailPassword, common.EmailPassword,
common.LDAPSearchPwd, common.LDAPSearchPwd,
common.MySQLPassword,
} }
) )
@ -142,13 +113,20 @@ type value struct {
// Get returns configurations // Get returns configurations
func (c *ConfigAPI) Get() { func (c *ConfigAPI) Get() {
cfg, err := config.GetSystemCfg() configs, err := config.GetSystemCfg()
if err != nil { if err != nil {
log.Errorf("failed to get configurations: %v", err) log.Errorf("failed to get configurations: %v", err)
c.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) c.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
} }
m, err := convertForGet(cfg) cfgs := map[string]interface{}{}
for _, k := range validKeys {
if v, ok := configs[k]; ok {
cfgs[k] = v
}
}
m, err := convertForGet(cfgs)
if err != nil { if err != nil {
log.Errorf("failed to convert configurations: %v", err) log.Errorf("failed to convert configurations: %v", err)
c.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) c.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))