From 18dffb26e7aba09074704d169517285ac3870e86 Mon Sep 17 00:00:00 2001 From: Aditya Manthramurthy Date: Thu, 25 Aug 2022 00:17:05 -0700 Subject: [PATCH] Allow querying a single target in config get API (#15587) --- cmd/admin-handlers-config-kv.go | 25 ++++++++++++++++++++++--- go.mod | 2 +- go.sum | 4 ++-- internal/config/config.go | 20 ++++++++++++++++++-- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/cmd/admin-handlers-config-kv.go b/cmd/admin-handlers-config-kv.go index 4c0fe7107..63c6d3fe4 100644 --- a/cmd/admin-handlers-config-kv.go +++ b/cmd/admin-handlers-config-kv.go @@ -177,6 +177,11 @@ func (a adminAPIHandlers) SetConfigKVHandler(w http.ResponseWriter, r *http.Requ } // GetConfigKVHandler - GET /minio/admin/v3/get-config-kv?key={key} +// +// `key` can be one of three forms: +// 1. `subsys:target` -> request for config of a single subsystem and target pair. +// 2. `subsys:` -> request for config of a single subsystem and the default target. +// 3. `subsys` -> request for config of all targets for the given subsystem. func (a adminAPIHandlers) GetConfigKVHandler(w http.ResponseWriter, r *http.Request) { ctx := newContext(r, w, "GetConfigKV") @@ -189,8 +194,22 @@ func (a adminAPIHandlers) GetConfigKVHandler(w http.ResponseWriter, r *http.Requ cfg := globalServerConfig.Clone() vars := mux.Vars(r) - subSys := vars["key"] - subSysConfigs, err := cfg.GetSubsysInfo(subSys) + key := vars["key"] + + var subSys, target string + { + ws := strings.SplitN(key, madmin.SubSystemSeparator, 2) + subSys = ws[0] + if len(ws) == 2 { + if ws[1] == "" { + target = madmin.Default + } else { + target = ws[1] + } + } + } + + subSysConfigs, err := cfg.GetSubsysInfo(subSys, target) if err != nil { writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) return @@ -433,7 +452,7 @@ func (a adminAPIHandlers) GetConfigHandler(w http.ResponseWriter, r *http.Reques } for _, hkv := range hkvs { // We ignore the error below, as we cannot get one. - cfgSubsysItems, _ := cfg.GetSubsysInfo(hkv.Key) + cfgSubsysItems, _ := cfg.GetSubsysInfo(hkv.Key, "") for _, item := range cfgSubsysItems { off := item.Config.Get(config.Enable) == config.EnableOff diff --git a/go.mod b/go.mod index f5daa2ad0..e54e053d0 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( github.com/minio/dperf v0.4.2 github.com/minio/highwayhash v1.0.2 github.com/minio/kes v0.20.0 - github.com/minio/madmin-go v1.4.24 + github.com/minio/madmin-go v1.4.25 github.com/minio/minio-go/v7 v7.0.34 github.com/minio/pkg v1.3.0 github.com/minio/selfupdate v0.5.0 diff --git a/go.sum b/go.sum index 8eb992ab8..7787fcf7c 100644 --- a/go.sum +++ b/go.sum @@ -623,8 +623,8 @@ github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLT github.com/minio/kes v0.20.0 h1:1tyC51Rr8zTregTESuT/QN/iebNMX7B9t7d3xLNMEpE= github.com/minio/kes v0.20.0/go.mod h1:3FW1BQkMGQW78yhy+69tUq5bdcf5rnXJizyeKB9a/tc= github.com/minio/madmin-go v1.3.5/go.mod h1:vGKGboQgGIWx4DuDUaXixjlIEZOCIp6ivJkQoiVaACc= -github.com/minio/madmin-go v1.4.24 h1:AFn8/N/E64RUXV4ztGwQcmsKb2uTlwSwiGyk6B37PWY= -github.com/minio/madmin-go v1.4.24/go.mod h1:ez87VmMtsxP7DRxjKJKD4RDNW+nhO2QF9KSzwxBDQ98= +github.com/minio/madmin-go v1.4.25 h1:IEJpsTXlHz18/yRI5HxY84KaJdDjUUYdMiC5f8fId4g= +github.com/minio/madmin-go v1.4.25/go.mod h1:ez87VmMtsxP7DRxjKJKD4RDNW+nhO2QF9KSzwxBDQ98= github.com/minio/mc v0.0.0-20220818165341-8c239d16aa37 h1:UE9kHgdza2HB4DDx0nIn0jHRl6YASUomVoKjciMfqjM= github.com/minio/mc v0.0.0-20220818165341-8c239d16aa37/go.mod h1:O3pvs5/n57bZ0mpcG/skBuD4pHX6m+wVbW7lw8LO5go= github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw= diff --git a/internal/config/config.go b/internal/config/config.go index 54c9b1fa1..cd3d63780 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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