github.com/minio/madmin-go/v2@v2.2.1/config-help-commands.go (about) 1 // 2 // Copyright (c) 2015-2022 MinIO, Inc. 3 // 4 // This file is part of MinIO Object Storage stack 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU Affero General Public License as 8 // published by the Free Software Foundation, either version 3 of the 9 // License, or (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU Affero General Public License for more details. 15 // 16 // You should have received a copy of the GNU Affero General Public License 17 // along with this program. If not, see <http://www.gnu.org/licenses/>. 18 // 19 20 package madmin 21 22 import ( 23 "context" 24 "encoding/json" 25 "net/http" 26 "net/url" 27 ) 28 29 // Help - return sub-system level help 30 type Help struct { 31 SubSys string `json:"subSys"` 32 Description string `json:"description"` 33 MultipleTargets bool `json:"multipleTargets"` 34 KeysHelp HelpKVS `json:"keysHelp"` 35 } 36 37 // HelpKV - implements help messages for keys 38 // with value as description of the keys. 39 type HelpKV struct { 40 Key string `json:"key"` 41 Description string `json:"description"` 42 Optional bool `json:"optional"` 43 Type string `json:"type"` 44 MultipleTargets bool `json:"multipleTargets"` 45 } 46 47 // HelpKVS - implement order of keys help messages. 48 type HelpKVS []HelpKV 49 50 // Keys returns help keys 51 func (h Help) Keys() []string { 52 keys := make([]string, 0, len(h.KeysHelp)) 53 for _, kh := range h.KeysHelp { 54 keys = append(keys, kh.Key) 55 } 56 return keys 57 } 58 59 // HelpConfigKV - return help for a given sub-system. 60 func (adm *AdminClient) HelpConfigKV(ctx context.Context, subSys, key string, envOnly bool) (Help, error) { 61 v := url.Values{} 62 v.Set("subSys", subSys) 63 v.Set("key", key) 64 if envOnly { 65 v.Set("env", "") 66 } 67 68 reqData := requestData{ 69 relPath: adminAPIPrefix + "/help-config-kv", 70 queryValues: v, 71 } 72 73 // Execute GET on /minio/admin/v3/help-config-kv 74 resp, err := adm.executeMethod(ctx, http.MethodGet, reqData) 75 if err != nil { 76 return Help{}, err 77 } 78 defer closeResponse(resp) 79 80 if resp.StatusCode != http.StatusOK { 81 return Help{}, httpRespToErrorResponse(resp) 82 } 83 84 help := Help{} 85 d := json.NewDecoder(resp.Body) 86 d.DisallowUnknownFields() 87 if err = d.Decode(&help); err != nil { 88 return help, err 89 } 90 91 return help, nil 92 }