github.com/minio/madmin-go@v1.7.5/config-help-commands.go (about) 1 // 2 // MinIO Object Storage (c) 2021 MinIO, Inc. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 package madmin 18 19 import ( 20 "context" 21 "encoding/json" 22 "net/http" 23 "net/url" 24 ) 25 26 // Help - return sub-system level help 27 type Help struct { 28 SubSys string `json:"subSys"` 29 Description string `json:"description"` 30 MultipleTargets bool `json:"multipleTargets"` 31 KeysHelp HelpKVS `json:"keysHelp"` 32 } 33 34 // HelpKV - implements help messages for keys 35 // with value as description of the keys. 36 type HelpKV struct { 37 Key string `json:"key"` 38 Description string `json:"description"` 39 Optional bool `json:"optional"` 40 Type string `json:"type"` 41 MultipleTargets bool `json:"multipleTargets"` 42 } 43 44 // HelpKVS - implement order of keys help messages. 45 type HelpKVS []HelpKV 46 47 // Keys returns help keys 48 func (h Help) Keys() []string { 49 keys := make([]string, 0, len(h.KeysHelp)) 50 for _, kh := range h.KeysHelp { 51 keys = append(keys, kh.Key) 52 } 53 return keys 54 } 55 56 // HelpConfigKV - return help for a given sub-system. 57 func (adm *AdminClient) HelpConfigKV(ctx context.Context, subSys, key string, envOnly bool) (Help, error) { 58 v := url.Values{} 59 v.Set("subSys", subSys) 60 v.Set("key", key) 61 if envOnly { 62 v.Set("env", "") 63 } 64 65 reqData := requestData{ 66 relPath: adminAPIPrefix + "/help-config-kv", 67 queryValues: v, 68 } 69 70 // Execute GET on /minio/admin/v3/help-config-kv 71 resp, err := adm.executeMethod(ctx, http.MethodGet, reqData) 72 if err != nil { 73 return Help{}, err 74 } 75 defer closeResponse(resp) 76 77 if resp.StatusCode != http.StatusOK { 78 return Help{}, httpRespToErrorResponse(resp) 79 } 80 81 help := Help{} 82 d := json.NewDecoder(resp.Body) 83 d.DisallowUnknownFields() 84 if err = d.Decode(&help); err != nil { 85 return help, err 86 } 87 88 return help, nil 89 }