storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/madmin/config-help-commands.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2019 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  
    18  package madmin
    19  
    20  import (
    21  	"context"
    22  	"encoding/json"
    23  	"net/http"
    24  	"net/url"
    25  )
    26  
    27  // Help - return sub-system level help
    28  type Help struct {
    29  	SubSys          string  `json:"subSys"`
    30  	Description     string  `json:"description"`
    31  	MultipleTargets bool    `json:"multipleTargets"`
    32  	KeysHelp        HelpKVS `json:"keysHelp"`
    33  }
    34  
    35  // HelpKV - implements help messages for keys
    36  // with value as description of the keys.
    37  type HelpKV struct {
    38  	Key             string `json:"key"`
    39  	Description     string `json:"description"`
    40  	Optional        bool   `json:"optional"`
    41  	Type            string `json:"type"`
    42  	MultipleTargets bool   `json:"multipleTargets"`
    43  }
    44  
    45  // HelpKVS - implement order of keys help messages.
    46  type HelpKVS []HelpKV
    47  
    48  // Keys returns help keys
    49  func (h Help) Keys() []string {
    50  	var keys []string
    51  	for _, kh := range h.KeysHelp {
    52  		keys = append(keys, kh.Key)
    53  	}
    54  	return keys
    55  }
    56  
    57  // HelpConfigKV - return help for a given sub-system.
    58  func (adm *AdminClient) HelpConfigKV(ctx context.Context, subSys, key string, envOnly bool) (Help, error) {
    59  	v := url.Values{}
    60  	v.Set("subSys", subSys)
    61  	v.Set("key", key)
    62  	if envOnly {
    63  		v.Set("env", "")
    64  	}
    65  
    66  	reqData := requestData{
    67  		relPath:     adminAPIPrefix + "/help-config-kv",
    68  		queryValues: v,
    69  	}
    70  
    71  	// Execute GET on /minio/admin/v3/help-config-kv
    72  	resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
    73  	if err != nil {
    74  		return Help{}, err
    75  	}
    76  	defer closeResponse(resp)
    77  
    78  	if resp.StatusCode != http.StatusOK {
    79  		return Help{}, httpRespToErrorResponse(resp)
    80  	}
    81  
    82  	var help = Help{}
    83  	d := json.NewDecoder(resp.Body)
    84  	d.DisallowUnknownFields()
    85  	if err = d.Decode(&help); err != nil {
    86  		return help, err
    87  	}
    88  
    89  	return help, nil
    90  }