config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
|
/*
|
2018-03-15 16:03:41 -04:00
|
|
|
|
* Minio Cloud Storage, (C) 2016, 2017, 2018 Minio, Inc.
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
|
package cmd
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
|
|
|
|
|
|
import (
|
2017-03-01 12:17:04 -05:00
|
|
|
|
"errors"
|
2017-03-16 14:06:17 -04:00
|
|
|
|
"fmt"
|
2017-03-15 19:30:34 -04:00
|
|
|
|
"io/ioutil"
|
2018-01-31 11:15:54 -05:00
|
|
|
|
"reflect"
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
|
"sync"
|
|
|
|
|
|
2017-10-31 14:54:32 -04:00
|
|
|
|
"github.com/minio/minio/pkg/auth"
|
2018-03-15 16:03:41 -04:00
|
|
|
|
"github.com/minio/minio/pkg/event"
|
|
|
|
|
"github.com/minio/minio/pkg/event/target"
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
|
"github.com/minio/minio/pkg/quick"
|
2017-03-15 19:30:34 -04:00
|
|
|
|
"github.com/tidwall/gjson"
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
|
)
|
|
|
|
|
|
2017-11-29 16:12:47 -05:00
|
|
|
|
// Steps to move from version N to version N+1
|
|
|
|
|
// 1. Add new struct serverConfigVN+1 in config-versions.go
|
2017-12-18 00:00:12 -05:00
|
|
|
|
// 2. Set serverConfigVersion to "N+1"
|
|
|
|
|
// 3. Set serverConfig to serverConfigVN+1
|
2017-11-29 16:12:47 -05:00
|
|
|
|
// 4. Add new migration function (ex. func migrateVNToVN+1()) in config-migrate.go
|
|
|
|
|
// 5. Call migrateVNToVN+1() from migrateConfig() in config-migrate.go
|
|
|
|
|
// 6. Make changes in config-current_test.go for any test change
|
|
|
|
|
|
2017-03-27 14:27:25 -04:00
|
|
|
|
// Config version
|
2017-12-22 06:28:13 -05:00
|
|
|
|
const serverConfigVersion = "22"
|
2017-11-29 16:12:47 -05:00
|
|
|
|
|
2017-12-22 06:28:13 -05:00
|
|
|
|
type serverConfig = serverConfigV22
|
2017-03-27 14:27:25 -04:00
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
var (
|
2017-11-29 16:12:47 -05:00
|
|
|
|
// globalServerConfig server config.
|
|
|
|
|
globalServerConfig *serverConfig
|
|
|
|
|
globalServerConfigMu sync.RWMutex
|
2017-03-31 01:26:24 -04:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// GetVersion get current config version.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) GetVersion() string {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
return s.Version
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 15:14:32 -04:00
|
|
|
|
// SetRegion set a new region.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) SetRegion(region string) {
|
2017-08-08 15:14:32 -04:00
|
|
|
|
// Save new region.
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.Region = region
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetRegion get current region.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) GetRegion() string {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
return s.Region
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-06 02:18:29 -05:00
|
|
|
|
// SetCredential sets new credential and returns the previous credential.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) SetCredential(creds auth.Credentials) (prevCred auth.Credentials) {
|
2017-08-08 15:14:32 -04:00
|
|
|
|
// Save previous credential.
|
|
|
|
|
prevCred = s.Credential
|
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// Set updated credential.
|
|
|
|
|
s.Credential = creds
|
2017-08-08 15:14:32 -04:00
|
|
|
|
|
|
|
|
|
// Return previous credential.
|
|
|
|
|
return prevCred
|
2017-03-31 01:26:24 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetCredentials get current credentials.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) GetCredential() auth.Credentials {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
return s.Credential
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetBrowser set if browser is enabled.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) SetBrowser(b bool) {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// Set the new value.
|
|
|
|
|
s.Browser = BrowserFlag(b)
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-22 06:28:13 -05:00
|
|
|
|
func (s *serverConfig) SetStorageClass(standardClass, rrsClass storageClass) {
|
2018-01-09 01:26:13 -05:00
|
|
|
|
s.StorageClass.Standard = standardClass
|
|
|
|
|
s.StorageClass.RRS = rrsClass
|
2017-12-22 06:28:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-01 02:30:07 -05:00
|
|
|
|
// GetStorageClass reads storage class fields from current config.
|
2017-12-28 03:49:45 -05:00
|
|
|
|
// It returns the standard and reduced redundancy storage class struct
|
2018-01-09 01:26:13 -05:00
|
|
|
|
func (s *serverConfig) GetStorageClass() (storageClass, storageClass) {
|
|
|
|
|
return s.StorageClass.Standard, s.StorageClass.RRS
|
2017-12-22 06:28:13 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// GetCredentials get current credentials.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) GetBrowser() bool {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
return bool(s.Browser)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save config.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func (s *serverConfig) Save() error {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// Save config file.
|
|
|
|
|
return quick.Save(getConfigFile(), s)
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-31 11:15:54 -05:00
|
|
|
|
// Returns the string describing a difference with the given
|
|
|
|
|
// configuration object. If the given configuration object is
|
|
|
|
|
// identical, an empty string is returned.
|
|
|
|
|
func (s *serverConfig) ConfigDiff(t *serverConfig) string {
|
|
|
|
|
switch {
|
|
|
|
|
case t == nil:
|
|
|
|
|
return "Given configuration is empty"
|
|
|
|
|
case s.Credential != t.Credential:
|
|
|
|
|
return "Credential configuration differs"
|
|
|
|
|
case s.Region != t.Region:
|
|
|
|
|
return "Region configuration differs"
|
|
|
|
|
case s.Browser != t.Browser:
|
|
|
|
|
return "Browser configuration differs"
|
|
|
|
|
case s.Domain != t.Domain:
|
|
|
|
|
return "Domain configuration differs"
|
|
|
|
|
case s.StorageClass != t.StorageClass:
|
|
|
|
|
return "StorageClass configuration differs"
|
|
|
|
|
case !reflect.DeepEqual(s.Notify.AMQP, t.Notify.AMQP):
|
|
|
|
|
return "AMQP Notification configuration differs"
|
|
|
|
|
case !reflect.DeepEqual(s.Notify.NATS, t.Notify.NATS):
|
|
|
|
|
return "NATS Notification configuration differs"
|
2018-03-15 16:03:41 -04:00
|
|
|
|
case !reflect.DeepEqual(s.Notify.Elasticsearch, t.Notify.Elasticsearch):
|
2018-01-31 11:15:54 -05:00
|
|
|
|
return "ElasticSearch Notification configuration differs"
|
|
|
|
|
case !reflect.DeepEqual(s.Notify.Redis, t.Notify.Redis):
|
|
|
|
|
return "Redis Notification configuration differs"
|
|
|
|
|
case !reflect.DeepEqual(s.Notify.PostgreSQL, t.Notify.PostgreSQL):
|
|
|
|
|
return "PostgreSQL Notification configuration differs"
|
|
|
|
|
case !reflect.DeepEqual(s.Notify.Kafka, t.Notify.Kafka):
|
|
|
|
|
return "Kafka Notification configuration differs"
|
|
|
|
|
case !reflect.DeepEqual(s.Notify.Webhook, t.Notify.Webhook):
|
|
|
|
|
return "Webhook Notification configuration differs"
|
|
|
|
|
case !reflect.DeepEqual(s.Notify.MySQL, t.Notify.MySQL):
|
|
|
|
|
return "MySQL Notification configuration differs"
|
|
|
|
|
case !reflect.DeepEqual(s.Notify.MQTT, t.Notify.MQTT):
|
|
|
|
|
return "MQTT Notification configuration differs"
|
|
|
|
|
case reflect.DeepEqual(s, t):
|
|
|
|
|
return ""
|
|
|
|
|
default:
|
|
|
|
|
// This case will not happen unless this comparison
|
|
|
|
|
// function has become stale.
|
|
|
|
|
return "Configuration differs"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func newServerConfig() *serverConfig {
|
|
|
|
|
srvCfg := &serverConfig{
|
2018-02-01 02:30:07 -05:00
|
|
|
|
Version: serverConfigVersion,
|
|
|
|
|
Credential: auth.MustGetNewCredentials(),
|
|
|
|
|
Region: globalMinioDefaultRegion,
|
|
|
|
|
Browser: true,
|
|
|
|
|
StorageClass: storageClassConfig{
|
|
|
|
|
Standard: storageClass{},
|
|
|
|
|
RRS: storageClass{},
|
|
|
|
|
},
|
|
|
|
|
Notify: notifier{},
|
2017-02-27 17:59:53 -05:00
|
|
|
|
}
|
2017-03-26 15:00:27 -04:00
|
|
|
|
|
2017-02-07 15:51:43 -05:00
|
|
|
|
// Make sure to initialize notification configs.
|
2018-03-15 16:03:41 -04:00
|
|
|
|
srvCfg.Notify.AMQP = make(map[string]target.AMQPArgs)
|
|
|
|
|
srvCfg.Notify.AMQP["1"] = target.AMQPArgs{}
|
|
|
|
|
srvCfg.Notify.MQTT = make(map[string]target.MQTTArgs)
|
|
|
|
|
srvCfg.Notify.MQTT["1"] = target.MQTTArgs{}
|
|
|
|
|
srvCfg.Notify.Elasticsearch = make(map[string]target.ElasticsearchArgs)
|
|
|
|
|
srvCfg.Notify.Elasticsearch["1"] = target.ElasticsearchArgs{}
|
|
|
|
|
srvCfg.Notify.Redis = make(map[string]target.RedisArgs)
|
|
|
|
|
srvCfg.Notify.Redis["1"] = target.RedisArgs{}
|
|
|
|
|
srvCfg.Notify.NATS = make(map[string]target.NATSArgs)
|
|
|
|
|
srvCfg.Notify.NATS["1"] = target.NATSArgs{}
|
|
|
|
|
srvCfg.Notify.PostgreSQL = make(map[string]target.PostgreSQLArgs)
|
|
|
|
|
srvCfg.Notify.PostgreSQL["1"] = target.PostgreSQLArgs{}
|
|
|
|
|
srvCfg.Notify.MySQL = make(map[string]target.MySQLArgs)
|
|
|
|
|
srvCfg.Notify.MySQL["1"] = target.MySQLArgs{}
|
|
|
|
|
srvCfg.Notify.Kafka = make(map[string]target.KafkaArgs)
|
|
|
|
|
srvCfg.Notify.Kafka["1"] = target.KafkaArgs{}
|
|
|
|
|
srvCfg.Notify.Webhook = make(map[string]target.WebhookArgs)
|
|
|
|
|
srvCfg.Notify.Webhook["1"] = target.WebhookArgs{}
|
2017-02-07 15:51:43 -05:00
|
|
|
|
|
2017-03-01 12:17:04 -05:00
|
|
|
|
return srvCfg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// newConfig - initialize a new server config, saves env parameters if
|
|
|
|
|
// found, otherwise use default parameters
|
2017-03-30 14:21:19 -04:00
|
|
|
|
func newConfig() error {
|
2017-03-01 12:17:04 -05:00
|
|
|
|
// Initialize server config.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
srvCfg := newServerConfig()
|
2017-03-01 12:17:04 -05:00
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// If env is set override the credentials from config file.
|
2017-03-01 12:17:04 -05:00
|
|
|
|
if globalIsEnvCreds {
|
2017-03-30 14:21:19 -04:00
|
|
|
|
srvCfg.SetCredential(globalActiveCred)
|
2017-03-01 12:17:04 -05:00
|
|
|
|
}
|
2017-03-31 06:34:26 -04:00
|
|
|
|
|
2017-03-01 12:17:04 -05:00
|
|
|
|
if globalIsEnvBrowser {
|
2017-03-30 14:21:19 -04:00
|
|
|
|
srvCfg.SetBrowser(globalIsBrowserEnabled)
|
2017-03-01 12:17:04 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-09 13:44:10 -04:00
|
|
|
|
if globalIsEnvRegion {
|
|
|
|
|
srvCfg.SetRegion(globalServerRegion)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 19:56:24 -05:00
|
|
|
|
if globalIsEnvDomainName {
|
|
|
|
|
srvCfg.Domain = globalDomainName
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-22 06:28:13 -05:00
|
|
|
|
if globalIsStorageClass {
|
|
|
|
|
srvCfg.SetStorageClass(globalStandardStorageClass, globalRRStorageClass)
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-07 15:51:43 -05:00
|
|
|
|
// hold the mutex lock before a new config is assigned.
|
|
|
|
|
// Save the new config globally.
|
|
|
|
|
// unlock the mutex.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
globalServerConfigMu.Lock()
|
|
|
|
|
globalServerConfig = srvCfg
|
|
|
|
|
globalServerConfigMu.Unlock()
|
2017-02-07 15:51:43 -05:00
|
|
|
|
|
|
|
|
|
// Save config into file.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
return globalServerConfig.Save()
|
2017-02-07 15:51:43 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-15 19:30:34 -04:00
|
|
|
|
// doCheckDupJSONKeys recursively detects duplicate json keys
|
|
|
|
|
func doCheckDupJSONKeys(key, value gjson.Result) error {
|
|
|
|
|
// Key occurrences map of the current scope to count
|
|
|
|
|
// if there is any duplicated json key.
|
|
|
|
|
keysOcc := make(map[string]int)
|
|
|
|
|
|
|
|
|
|
// Holds the found error
|
|
|
|
|
var checkErr error
|
|
|
|
|
|
|
|
|
|
// Iterate over keys in the current json scope
|
|
|
|
|
value.ForEach(func(k, v gjson.Result) bool {
|
|
|
|
|
// If current key is not null, check if its
|
|
|
|
|
// value contains some duplicated keys.
|
|
|
|
|
if k.Type != gjson.Null {
|
|
|
|
|
keysOcc[k.String()]++
|
|
|
|
|
checkErr = doCheckDupJSONKeys(k, v)
|
|
|
|
|
}
|
|
|
|
|
return checkErr == nil
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Check found err
|
|
|
|
|
if checkErr != nil {
|
|
|
|
|
return errors.New(key.String() + " => " + checkErr.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for duplicated keys
|
|
|
|
|
for k, v := range keysOcc {
|
|
|
|
|
if v > 1 {
|
|
|
|
|
return errors.New(key.String() + " => `" + k + "` entry is duplicated")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check recursively if a key is duplicated in the same json scope
|
|
|
|
|
// e.g.:
|
|
|
|
|
// `{ "key" : { "key" ..` is accepted
|
|
|
|
|
// `{ "key" : { "subkey" : "val1", "subkey": "val2" ..` throws subkey duplicated error
|
|
|
|
|
func checkDupJSONKeys(json string) error {
|
|
|
|
|
// Parse config with gjson library
|
|
|
|
|
config := gjson.Parse(json)
|
|
|
|
|
|
|
|
|
|
// Create a fake rootKey since root json doesn't seem to have representation
|
|
|
|
|
// in gjson library.
|
|
|
|
|
rootKey := gjson.Result{Type: gjson.String, Str: minioConfigFile}
|
|
|
|
|
|
|
|
|
|
// Check if loaded json contains any duplicated keys
|
|
|
|
|
return doCheckDupJSONKeys(rootKey, config)
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// getValidConfig - returns valid server configuration
|
2017-11-29 16:12:47 -05:00
|
|
|
|
func getValidConfig() (*serverConfig, error) {
|
|
|
|
|
srvCfg := &serverConfig{
|
2017-03-26 15:00:27 -04:00
|
|
|
|
Region: globalMinioDefaultRegion,
|
|
|
|
|
Browser: true,
|
|
|
|
|
}
|
2017-03-15 19:30:34 -04:00
|
|
|
|
|
2017-03-26 15:00:27 -04:00
|
|
|
|
configFile := getConfigFile()
|
2017-03-22 13:23:25 -04:00
|
|
|
|
if _, err := quick.Load(configFile, srvCfg); err != nil {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
return nil, err
|
2017-03-15 19:30:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 16:12:47 -05:00
|
|
|
|
if srvCfg.Version != serverConfigVersion {
|
|
|
|
|
return nil, fmt.Errorf("configuration version mismatch. Expected: ‘%s’, Got: ‘%s’", serverConfigVersion, srvCfg.Version)
|
2017-03-15 19:30:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Load config file json and check for duplication json keys
|
|
|
|
|
jsonBytes, err := ioutil.ReadFile(configFile)
|
|
|
|
|
if err != nil {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
return nil, err
|
2017-03-15 19:30:34 -04:00
|
|
|
|
}
|
2017-03-31 01:26:24 -04:00
|
|
|
|
if err = checkDupJSONKeys(string(jsonBytes)); err != nil {
|
|
|
|
|
return nil, err
|
2017-03-15 19:30:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-22 19:11:58 -04:00
|
|
|
|
// Validate credential fields only when
|
|
|
|
|
// they are not set via the environment
|
2017-03-31 01:26:24 -04:00
|
|
|
|
|
|
|
|
|
// Error out if global is env credential is not set and config has invalid credential
|
|
|
|
|
if !globalIsEnvCreds && !srvCfg.Credential.IsValid() {
|
|
|
|
|
return nil, errors.New("invalid credential in config file " + configFile)
|
2017-03-15 19:30:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
return srvCfg, nil
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// loadConfig - loads a new config from disk, overrides params from env
|
|
|
|
|
// if found and valid
|
|
|
|
|
func loadConfig() error {
|
|
|
|
|
srvCfg, err := getValidConfig()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
2017-03-16 14:06:17 -04:00
|
|
|
|
}
|
2016-12-07 06:41:54 -05:00
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// If env is set override the credentials from config file.
|
|
|
|
|
if globalIsEnvCreds {
|
|
|
|
|
srvCfg.SetCredential(globalActiveCred)
|
|
|
|
|
}
|
2017-04-09 13:44:10 -04:00
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
if globalIsEnvBrowser {
|
|
|
|
|
srvCfg.SetBrowser(globalIsBrowserEnabled)
|
|
|
|
|
}
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
|
|
2017-04-09 13:44:10 -04:00
|
|
|
|
if globalIsEnvRegion {
|
|
|
|
|
srvCfg.SetRegion(globalServerRegion)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 19:56:24 -05:00
|
|
|
|
if globalIsEnvDomainName {
|
|
|
|
|
srvCfg.Domain = globalDomainName
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-22 06:28:13 -05:00
|
|
|
|
if globalIsStorageClass {
|
|
|
|
|
srvCfg.SetStorageClass(globalStandardStorageClass, globalRRStorageClass)
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
// hold the mutex lock before a new config is assigned.
|
2017-11-29 16:12:47 -05:00
|
|
|
|
globalServerConfigMu.Lock()
|
|
|
|
|
globalServerConfig = srvCfg
|
2017-03-31 01:26:24 -04:00
|
|
|
|
if !globalIsEnvCreds {
|
2017-11-29 16:12:47 -05:00
|
|
|
|
globalActiveCred = globalServerConfig.GetCredential()
|
2017-03-31 01:26:24 -04:00
|
|
|
|
}
|
|
|
|
|
if !globalIsEnvBrowser {
|
2017-11-29 16:12:47 -05:00
|
|
|
|
globalIsBrowserEnabled = globalServerConfig.GetBrowser()
|
2017-03-31 01:26:24 -04:00
|
|
|
|
}
|
2017-04-09 13:44:10 -04:00
|
|
|
|
if !globalIsEnvRegion {
|
2017-11-29 16:12:47 -05:00
|
|
|
|
globalServerRegion = globalServerConfig.GetRegion()
|
2017-04-09 13:44:10 -04:00
|
|
|
|
}
|
2017-11-14 19:56:24 -05:00
|
|
|
|
if !globalIsEnvDomainName {
|
2017-11-29 16:12:47 -05:00
|
|
|
|
globalDomainName = globalServerConfig.Domain
|
2017-11-14 19:56:24 -05:00
|
|
|
|
}
|
2017-12-22 06:28:13 -05:00
|
|
|
|
if !globalIsStorageClass {
|
|
|
|
|
globalStandardStorageClass, globalRRStorageClass = globalServerConfig.GetStorageClass()
|
|
|
|
|
}
|
2017-11-29 16:12:47 -05:00
|
|
|
|
globalServerConfigMu.Unlock()
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
return nil
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
|
}
|
2018-03-15 16:03:41 -04:00
|
|
|
|
|
|
|
|
|
// getNotificationTargets - returns TargetList which contains enabled targets in serverConfig.
|
|
|
|
|
// A new notification target is added like below
|
|
|
|
|
// * Add a new target in pkg/event/target package.
|
|
|
|
|
// * Add newly added target configuration to serverConfig.Notify.<TARGET_NAME>.
|
|
|
|
|
// * Handle the configuration in this function to create/add into TargetList.
|
|
|
|
|
func getNotificationTargets(config *serverConfig) (*event.TargetList, error) {
|
|
|
|
|
targetList := event.NewTargetList()
|
|
|
|
|
|
|
|
|
|
for id, args := range config.Notify.AMQP {
|
|
|
|
|
if args.Enable {
|
|
|
|
|
newTarget, err := target.NewAMQPTarget(id, args)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if err = targetList.Add(newTarget); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for id, args := range config.Notify.Elasticsearch {
|
|
|
|
|
if args.Enable {
|
|
|
|
|
newTarget, err := target.NewElasticsearchTarget(id, args)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if err = targetList.Add(newTarget); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for id, args := range config.Notify.Kafka {
|
|
|
|
|
if args.Enable {
|
|
|
|
|
newTarget, err := target.NewKafkaTarget(id, args)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if err = targetList.Add(newTarget); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for id, args := range config.Notify.MQTT {
|
|
|
|
|
if args.Enable {
|
|
|
|
|
newTarget, err := target.NewMQTTTarget(id, args)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if err = targetList.Add(newTarget); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for id, args := range config.Notify.MySQL {
|
|
|
|
|
if args.Enable {
|
|
|
|
|
newTarget, err := target.NewMySQLTarget(id, args)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if err = targetList.Add(newTarget); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for id, args := range config.Notify.NATS {
|
|
|
|
|
if args.Enable {
|
|
|
|
|
newTarget, err := target.NewNATSTarget(id, args)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if err = targetList.Add(newTarget); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for id, args := range config.Notify.PostgreSQL {
|
|
|
|
|
if args.Enable {
|
|
|
|
|
newTarget, err := target.NewPostgreSQLTarget(id, args)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if err = targetList.Add(newTarget); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for id, args := range config.Notify.Redis {
|
|
|
|
|
if args.Enable {
|
|
|
|
|
newTarget, err := target.NewRedisTarget(id, args)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if err = targetList.Add(newTarget); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for id, args := range config.Notify.Webhook {
|
|
|
|
|
if args.Enable {
|
|
|
|
|
newTarget := target.NewWebhookTarget(id, args)
|
|
|
|
|
if err := targetList.Add(newTarget); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return targetList, nil
|
|
|
|
|
}
|