Allow querying a single target in config get API (#15587)

This commit is contained in:
Aditya Manthramurthy
2022-08-25 00:17:05 -07:00
committed by GitHub
parent edba7c987b
commit 18dffb26e7
4 changed files with 43 additions and 8 deletions

View File

@@ -1221,8 +1221,10 @@ type SubsysInfo struct {
EnvMap map[string]EnvPair
}
// GetSubsysInfo returns `SubsysInfo`s for all targets for the subsystem.
func (c Config) GetSubsysInfo(subSys string) ([]SubsysInfo, error) {
// GetSubsysInfo returns `SubsysInfo`s for all targets for the subsystem, when
// target is empty. Otherwise returns `SubsysInfo` for the desired target only.
// To request the default target only, target must be set to `Default`.
func (c Config) GetSubsysInfo(subSys, target string) ([]SubsysInfo, error) {
// Check if config param requested is valid.
defKVS1, ok := DefaultKVS[subSys]
if !ok {
@@ -1234,6 +1236,20 @@ func (c Config) GetSubsysInfo(subSys string) ([]SubsysInfo, error) {
return nil, err
}
if target != "" {
found := false
for _, t := range targets {
if t == target {
found = true
break
}
}
if !found {
return nil, Errorf("there is no target `%s` for subsystem `%s`", target, subSys)
}
targets = []string{target}
}
// The `Comment` configuration variable is optional but is available to be
// set for all sub-systems. It is not present in the `DefaultKVS` map's
// values. To enable fetching a configured comment value from the