github.com/minio/mc@v0.0.0-20240503112107-b471de8d1882/cmd/config-utils.go (about)

     1  // Copyright (c) 2015-2022 MinIO, Inc.
     2  //
     3  // This file is part of MinIO Object Storage stack
     4  //
     5  // This program is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Affero General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // This program is distributed in the hope that it will be useful
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU Affero General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Affero General Public License
    16  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package cmd
    19  
    20  import "strings"
    21  
    22  var validAPIs = []string{"S3v4", "S3v2"}
    23  
    24  const (
    25  	accessKeyMinLen = 3
    26  	secretKeyMinLen = 8
    27  )
    28  
    29  // isValidAccessKey - validate access key for right length.
    30  func isValidAccessKey(accessKey string) bool {
    31  	if accessKey == "" {
    32  		return true
    33  	}
    34  	return len(accessKey) >= accessKeyMinLen
    35  }
    36  
    37  // isValidSecretKey - validate secret key for right length.
    38  func isValidSecretKey(secretKey string) bool {
    39  	if secretKey == "" {
    40  		return true
    41  	}
    42  	return len(secretKey) >= secretKeyMinLen
    43  }
    44  
    45  // trimTrailingSeparator - Remove trailing separator.
    46  func trimTrailingSeparator(hostURL string) string {
    47  	separator := string(newClientURL(hostURL).Separator)
    48  	return strings.TrimSuffix(hostURL, separator)
    49  }
    50  
    51  // isValidHostURL - validate input host url.
    52  func isValidHostURL(hostURL string) (ok bool) {
    53  	if strings.TrimSpace(hostURL) != "" {
    54  		url := newClientURL(hostURL)
    55  		if url.Scheme == "https" || url.Scheme == "http" {
    56  			if url.Path == "/" {
    57  				ok = true
    58  			}
    59  		}
    60  	}
    61  	return ok
    62  }
    63  
    64  // isValidAPI - Validates if API signature string of supported type.
    65  func isValidAPI(api string) (ok bool) {
    66  	switch strings.ToLower(api) {
    67  	case "s3v2", "s3v4":
    68  		ok = true
    69  	}
    70  	return ok
    71  }
    72  
    73  // isValidLookup - validates if bucket lookup is of valid type
    74  func isValidLookup(lookup string) (ok bool) {
    75  	l := strings.ToLower(strings.TrimSpace(lookup))
    76  	for _, v := range []string{"dns", "path", "auto"} {
    77  		if l == v {
    78  			return true
    79  		}
    80  	}
    81  	return false
    82  }
    83  
    84  // isValidPath - validates the alias path config
    85  func isValidPath(path string) (ok bool) {
    86  	l := strings.ToLower(strings.TrimSpace(path))
    87  	for _, v := range []string{"on", "off", "auto"} {
    88  		if l == v {
    89  			return true
    90  		}
    91  	}
    92  	return false
    93  }