Fix env var output in config get/export APIs (#15528)

Fix a bug where env vars are not output when the config for the
subsystem is specified solely via env vars.
This commit is contained in:
Aditya Manthramurthy 2022-08-13 10:39:01 -07:00 committed by GitHub
parent c5b3666089
commit 9986e103cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 15 deletions

View File

@ -436,24 +436,24 @@ func (a adminAPIHandlers) GetConfigHandler(w http.ResponseWriter, r *http.Reques
cfgSubsysItems, _ := cfg.GetSubsysInfo(hkv.Key) cfgSubsysItems, _ := cfg.GetSubsysInfo(hkv.Key)
for _, item := range cfgSubsysItems { for _, item := range cfgSubsysItems {
off := item.Params.Get(config.Enable) == config.EnableOff off := item.Config.Get(config.Enable) == config.EnableOff
switch hkv.Key { switch hkv.Key {
case config.EtcdSubSys: case config.EtcdSubSys:
off = !etcd.Enabled(item.Params) off = !etcd.Enabled(item.Config)
case config.CacheSubSys: case config.CacheSubSys:
off = !cache.Enabled(item.Params) off = !cache.Enabled(item.Config)
case config.StorageClassSubSys: case config.StorageClassSubSys:
off = !storageclass.Enabled(item.Params) off = !storageclass.Enabled(item.Config)
case config.PolicyPluginSubSys: case config.PolicyPluginSubSys:
off = !polplugin.Enabled(item.Params) off = !polplugin.Enabled(item.Config)
case config.IdentityOpenIDSubSys: case config.IdentityOpenIDSubSys:
off = !openid.Enabled(item.Params) off = !openid.Enabled(item.Config)
case config.IdentityLDAPSubSys: case config.IdentityLDAPSubSys:
off = !xldap.Enabled(item.Params) off = !xldap.Enabled(item.Config)
case config.IdentityTLSSubSys: case config.IdentityTLSSubSys:
off = !globalSTSTLSConfig.Enabled off = !globalSTSTLSConfig.Enabled
case config.IdentityPluginSubSys: case config.IdentityPluginSubSys:
off = !idplugin.Enabled(item.Params) off = !idplugin.Enabled(item.Config)
} }
item.AddString(&s, off) item.AddString(&s, off)
} }

View File

@ -1217,7 +1217,8 @@ type EnvPair struct {
// SubsysInfo holds config info for a subsystem target. // SubsysInfo holds config info for a subsystem target.
type SubsysInfo struct { type SubsysInfo struct {
SubSys, Target string SubSys, Target string
Params KVS Defaults KVS
Config KVS
// map of config parameter name to EnvPair. // map of config parameter name to EnvPair.
EnvMap map[string]EnvPair EnvMap map[string]EnvPair
@ -1250,7 +1251,8 @@ func (c Config) GetSubsysInfo(subSys string) ([]SubsysInfo, error) {
cs := SubsysInfo{ cs := SubsysInfo{
SubSys: subSys, SubSys: subSys,
Target: target, Target: target,
Params: kvs, Defaults: defKVS,
Config: kvs,
EnvMap: make(map[string]EnvPair), EnvMap: make(map[string]EnvPair),
} }
@ -1274,7 +1276,7 @@ func (c Config) GetSubsysInfo(subSys string) ([]SubsysInfo, error) {
// AddEnvString adds env vars to the given string builder. // AddEnvString adds env vars to the given string builder.
func (cs *SubsysInfo) AddEnvString(b *strings.Builder) { func (cs *SubsysInfo) AddEnvString(b *strings.Builder) {
for _, v := range cs.Params { for _, v := range cs.Defaults {
if ep, ok := cs.EnvMap[v.Key]; ok { if ep, ok := cs.EnvMap[v.Key]; ok {
b.WriteString(KvComment) b.WriteString(KvComment)
b.WriteString(KvSpaceSeparator) b.WriteString(KvSpaceSeparator)
@ -1301,6 +1303,6 @@ func (cs *SubsysInfo) AddString(b *strings.Builder, off bool) {
b.WriteString(cs.Target) b.WriteString(cs.Target)
} }
b.WriteString(KvSpaceSeparator) b.WriteString(KvSpaceSeparator)
b.WriteString(cs.Params.String()) b.WriteString(cs.Config.String())
b.WriteString(KvNewline) b.WriteString(KvNewline)
} }