github.com/minio/mc@v0.0.0-20240503112107-b471de8d1882/cmd/config-old.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  // ///////////////// Config V1 ///////////////////
    21  type hostConfigV1 struct {
    22  	AccessKeyID     string
    23  	SecretAccessKey string
    24  }
    25  
    26  type configV1 struct {
    27  	Version string
    28  	Aliases map[string]string
    29  	Hosts   map[string]hostConfigV1
    30  }
    31  
    32  // newConfigV1() - get new config version 1.0.0
    33  func newConfigV1() *configV1 {
    34  	conf := new(configV1)
    35  	conf.Version = "1.0.0"
    36  	// make sure to allocate map's otherwise Golang
    37  	// exits silently without providing any errors
    38  	conf.Aliases = make(map[string]string)
    39  	conf.Hosts = make(map[string]hostConfigV1)
    40  	return conf
    41  }
    42  
    43  // ///////////////// Config V101 ///////////////////
    44  type hostConfigV101 hostConfigV1
    45  
    46  type configV101 struct {
    47  	Version string
    48  	Aliases map[string]string
    49  	Hosts   map[string]hostConfigV101
    50  }
    51  
    52  // newConfigV101() - get new config version 1.0.1
    53  func newConfigV101() *configV101 {
    54  	conf := new(configV101)
    55  	conf.Version = "1.0.1"
    56  	conf.Aliases = make(map[string]string)
    57  	conf.Hosts = make(map[string]hostConfigV101)
    58  	return conf
    59  }
    60  
    61  // ///////////////// Config V2 ///////////////////
    62  type hostConfigV2 hostConfigV1
    63  
    64  type configV2 struct {
    65  	Version string
    66  	Aliases map[string]string
    67  	Hosts   map[string]hostConfigV2
    68  }
    69  
    70  // newConfigV2() - get new config version 2
    71  func newConfigV2() *configV2 {
    72  	conf := new(configV2)
    73  	conf.Version = "2"
    74  	conf.Aliases = make(map[string]string)
    75  	conf.Hosts = make(map[string]hostConfigV2)
    76  	return conf
    77  }
    78  
    79  // ///////////////// Config V3 ///////////////////
    80  type hostConfigV3 struct {
    81  	AccessKeyID     string `json:"access-key-id"`
    82  	SecretAccessKey string `json:"secret-access-key"`
    83  }
    84  
    85  type configV3 struct {
    86  	Version string                  `json:"version"`
    87  	Aliases map[string]string       `json:"alias"`
    88  	Hosts   map[string]hostConfigV3 `json:"hosts"`
    89  }
    90  
    91  // newConfigV3 - get new config version 3.
    92  func newConfigV3() *configV3 {
    93  	conf := new(configV3)
    94  	conf.Version = "3"
    95  	conf.Aliases = make(map[string]string)
    96  	conf.Hosts = make(map[string]hostConfigV3)
    97  	return conf
    98  }
    99  
   100  // ///////////////// Config V4 ///////////////////
   101  type hostConfigV4 struct {
   102  	AccessKeyID     string `json:"accessKeyId"`
   103  	SecretAccessKey string `json:"secretAccessKey"`
   104  	Signature       string `json:"signature"`
   105  }
   106  
   107  type configV4 struct {
   108  	Version string                  `json:"version"`
   109  	Aliases map[string]string       `json:"alias"`
   110  	Hosts   map[string]hostConfigV4 `json:"hosts"`
   111  }
   112  
   113  func newConfigV4() *configV4 {
   114  	conf := new(configV4)
   115  	conf.Version = "4"
   116  	conf.Aliases = make(map[string]string)
   117  	conf.Hosts = make(map[string]hostConfigV4)
   118  	return conf
   119  }
   120  
   121  // ///////////////// Config V5 ///////////////////
   122  type hostConfigV5 struct {
   123  	AccessKeyID     string `json:"accessKeyId"`
   124  	SecretAccessKey string `json:"secretAccessKey"`
   125  	API             string `json:"api"`
   126  }
   127  
   128  type configV5 struct {
   129  	Version string                  `json:"version"`
   130  	Aliases map[string]string       `json:"alias"`
   131  	Hosts   map[string]hostConfigV5 `json:"hosts"`
   132  }
   133  
   134  func newConfigV5() *configV5 {
   135  	conf := new(configV5)
   136  	conf.Version = "5"
   137  	conf.Aliases = make(map[string]string)
   138  	conf.Hosts = make(map[string]hostConfigV5)
   139  	return conf
   140  }
   141  
   142  // ///////////////// Config V6 ///////////////////
   143  type hostConfigV6 struct {
   144  	AccessKeyID     string `json:"accessKeyId"`
   145  	SecretAccessKey string `json:"secretAccessKey"`
   146  	API             string `json:"api"`
   147  }
   148  
   149  type configV6 struct {
   150  	Version string                  `json:"version"`
   151  	Aliases map[string]string       `json:"alias"`
   152  	Hosts   map[string]hostConfigV6 `json:"hosts"`
   153  }
   154  
   155  // newConfigV6 - new config version '6'.
   156  func newConfigV6() *configV6 {
   157  	conf := new(configV6)
   158  	conf.Version = "6"
   159  	conf.Aliases = make(map[string]string)
   160  	conf.Hosts = make(map[string]hostConfigV6)
   161  	return conf
   162  }
   163  
   164  // ///////////////// Config V6 ///////////////////
   165  // hostConfig configuration of a host - version '7'.
   166  type hostConfigV7 struct {
   167  	URL       string `json:"url"`
   168  	AccessKey string `json:"accessKey"`
   169  	SecretKey string `json:"secretKey"`
   170  	API       string `json:"api"`
   171  }
   172  
   173  // configV7 config version.
   174  type configV7 struct {
   175  	Version string                  `json:"version"`
   176  	Hosts   map[string]hostConfigV7 `json:"hosts"`
   177  }
   178  
   179  // newConfigV7 - new config version '7'.
   180  func newConfigV7() *configV7 {
   181  	cfg := new(configV7)
   182  	cfg.Version = "7"
   183  	cfg.Hosts = make(map[string]hostConfigV7)
   184  	return cfg
   185  }
   186  
   187  func (c *configV7) loadDefaults() {
   188  	// MinIO server running locally.
   189  	c.setHost("local", hostConfigV7{
   190  		URL:       "http://localhost:9000",
   191  		AccessKey: "",
   192  		SecretKey: "",
   193  		API:       "S3v4",
   194  	})
   195  
   196  	// Amazon S3 cloud storage service.
   197  	c.setHost("s3", hostConfigV7{
   198  		URL:       "https://s3.amazonaws.com",
   199  		AccessKey: defaultAccessKey,
   200  		SecretKey: defaultSecretKey,
   201  		API:       "S3v4",
   202  	})
   203  
   204  	// Google cloud storage service.
   205  	c.setHost("gcs", hostConfigV7{
   206  		URL:       "https://storage.googleapis.com",
   207  		AccessKey: defaultAccessKey,
   208  		SecretKey: defaultSecretKey,
   209  		API:       "S3v2",
   210  	})
   211  
   212  	// MinIO anonymous server for demo.
   213  	c.setHost("play", hostConfigV7{
   214  		URL:       "https://play.min.io",
   215  		AccessKey: "",
   216  		SecretKey: "",
   217  		API:       "S3v4",
   218  	})
   219  
   220  	// MinIO demo server with public secret and access keys.
   221  	c.setHost("player", hostConfigV7{
   222  		URL:       "https://play.min.io:9002",
   223  		AccessKey: "Q3AM3UQ867SPQQA43P2F",
   224  		SecretKey: "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
   225  		API:       "S3v4",
   226  	})
   227  
   228  	// MinIO public download service.
   229  	c.setHost("dl", hostConfigV7{
   230  		URL:       "https://dl.min.io:9000",
   231  		AccessKey: "",
   232  		SecretKey: "",
   233  		API:       "S3v4",
   234  	})
   235  }
   236  
   237  // SetHost sets host config if not empty.
   238  func (c *configV7) setHost(alias string, cfg hostConfigV7) {
   239  	if _, ok := c.Hosts[alias]; !ok {
   240  		c.Hosts[alias] = cfg
   241  	}
   242  }
   243  
   244  // ///////////////// Config V8 ///////////////////
   245  // configV8 config version.
   246  // hostConfig configuration of a host.
   247  type hostConfigV8 struct {
   248  	URL       string `json:"url"`
   249  	AccessKey string `json:"accessKey"`
   250  	SecretKey string `json:"secretKey"`
   251  	API       string `json:"api"`
   252  }
   253  
   254  type configV8 struct {
   255  	Version string                  `json:"version"`
   256  	Hosts   map[string]hostConfigV8 `json:"hosts"`
   257  }
   258  
   259  // newConfigV8 - new config version.
   260  func newConfigV8() *configV8 {
   261  	cfg := new(configV8)
   262  	cfg.Version = globalMCConfigVersion
   263  	cfg.Hosts = make(map[string]hostConfigV8)
   264  	return cfg
   265  }
   266  
   267  // SetHost sets host config if not empty.
   268  func (c *configV8) setHost(alias string, cfg hostConfigV8) {
   269  	if _, ok := c.Hosts[alias]; !ok {
   270  		c.Hosts[alias] = cfg
   271  	}
   272  }
   273  
   274  // load default values for missing entries.
   275  func (c *configV8) loadDefaults() {
   276  	// MinIO server running locally.
   277  	c.setHost("local", hostConfigV8{
   278  		URL:       "http://localhost:9000",
   279  		AccessKey: "",
   280  		SecretKey: "",
   281  		API:       "S3v4",
   282  	})
   283  
   284  	// Amazon S3 cloud storage service.
   285  	c.setHost("s3", hostConfigV8{
   286  		URL:       "https://s3.amazonaws.com",
   287  		AccessKey: defaultAccessKey,
   288  		SecretKey: defaultSecretKey,
   289  		API:       "S3v4",
   290  	})
   291  
   292  	// Google cloud storage service.
   293  	c.setHost("gcs", hostConfigV8{
   294  		URL:       "https://storage.googleapis.com",
   295  		AccessKey: defaultAccessKey,
   296  		SecretKey: defaultSecretKey,
   297  		API:       "S3v2",
   298  	})
   299  
   300  	// MinIO anonymous server for demo.
   301  	c.setHost("play", hostConfigV8{
   302  		URL:       "https://play.min.io",
   303  		AccessKey: "Q3AM3UQ867SPQQA43P2F",
   304  		SecretKey: "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
   305  		API:       "S3v4",
   306  	})
   307  }
   308  
   309  /////////////////// Config V9 ///////////////////
   310  
   311  // hostConfig configuration of a host.
   312  type hostConfigV9 struct {
   313  	URL          string `json:"url"`
   314  	AccessKey    string `json:"accessKey"`
   315  	SecretKey    string `json:"secretKey"`
   316  	SessionToken string `json:"sessionToken,omitempty"`
   317  	API          string `json:"api"`
   318  	Lookup       string `json:"lookup"`
   319  }
   320  
   321  // configV8 config version.
   322  type configV9 struct {
   323  	Version string                  `json:"version"`
   324  	Hosts   map[string]hostConfigV9 `json:"hosts"`
   325  }
   326  
   327  func newConfigV9() *configV9 {
   328  	cfg := new(configV9)
   329  	cfg.Version = "9"
   330  	cfg.Hosts = make(map[string]hostConfigV9)
   331  	return cfg
   332  }
   333  
   334  /////////////////// Config V10 ///////////////////
   335  // RESERVED FOR FUTURE