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-01-18 15:24:34 -05:00
|
|
|
|
* Minio Cloud Storage, (C) 2016, 2017 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"
|
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"
|
|
|
|
|
|
|
|
|
|
"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-03-27 14:27:25 -04:00
|
|
|
|
// Config version
|
2017-06-14 20:27:03 -04:00
|
|
|
|
const v19 = "19"
|
2017-03-27 14:27:25 -04:00
|
|
|
|
|
2017-03-31 01:26:24 -04:00
|
|
|
|
var (
|
|
|
|
|
// serverConfig server config.
|
2017-06-14 20:27:03 -04:00
|
|
|
|
serverConfig *serverConfigV19
|
2017-03-31 01:26:24 -04:00
|
|
|
|
serverConfigMu sync.RWMutex
|
|
|
|
|
)
|
|
|
|
|
|
2017-06-14 20:27:03 -04:00
|
|
|
|
// serverConfigV19 server configuration version '19' which is like
|
|
|
|
|
// version '18' except it adds support for MQTT notifications.
|
|
|
|
|
type serverConfigV19 struct {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
sync.RWMutex
|
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
|
|
|
|
Version string `json:"version"`
|
|
|
|
|
|
|
|
|
|
// S3 API configuration.
|
2017-03-26 15:00:27 -04:00
|
|
|
|
Credential credential `json:"credential"`
|
|
|
|
|
Region string `json:"region"`
|
|
|
|
|
Browser BrowserFlag `json:"browser"`
|
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
|
|
|
|
|
|
|
|
|
// Additional error logging configuration.
|
2017-03-23 19:36:00 -04:00
|
|
|
|
Logger *loggers `json:"logger"`
|
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
|
|
|
|
|
2016-08-05 01:01:58 -04:00
|
|
|
|
// Notification queue configuration.
|
2017-02-09 18:20:54 -05:00
|
|
|
|
Notify *notifier `json:"notify"`
|
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
|
|
|
|
// GetVersion get current config version.
|
2017-06-14 20:27:03 -04:00
|
|
|
|
func (s *serverConfigV19) GetVersion() string {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.RLock()
|
|
|
|
|
defer s.RUnlock()
|
|
|
|
|
|
|
|
|
|
return s.Version
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 15:14:32 -04:00
|
|
|
|
// SetRegion set a new region.
|
2017-06-14 20:27:03 -04:00
|
|
|
|
func (s *serverConfigV19) SetRegion(region string) {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.Lock()
|
|
|
|
|
defer s.Unlock()
|
|
|
|
|
|
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-06-14 20:27:03 -04:00
|
|
|
|
func (s *serverConfigV19) GetRegion() string {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.RLock()
|
|
|
|
|
defer s.RUnlock()
|
|
|
|
|
|
|
|
|
|
return s.Region
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 15:14:32 -04:00
|
|
|
|
// SetCredentials set new credentials. SetCredential returns the previous credential.
|
|
|
|
|
func (s *serverConfigV19) SetCredential(creds credential) (prevCred credential) {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.Lock()
|
|
|
|
|
defer s.Unlock()
|
|
|
|
|
|
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-06-14 20:27:03 -04:00
|
|
|
|
func (s *serverConfigV19) GetCredential() credential {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.RLock()
|
|
|
|
|
defer s.RUnlock()
|
|
|
|
|
|
|
|
|
|
return s.Credential
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetBrowser set if browser is enabled.
|
2017-06-14 20:27:03 -04:00
|
|
|
|
func (s *serverConfigV19) SetBrowser(b bool) {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.Lock()
|
|
|
|
|
defer s.Unlock()
|
|
|
|
|
|
|
|
|
|
// Set the new value.
|
|
|
|
|
s.Browser = BrowserFlag(b)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetCredentials get current credentials.
|
2017-06-14 20:27:03 -04:00
|
|
|
|
func (s *serverConfigV19) GetBrowser() bool {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.RLock()
|
|
|
|
|
defer s.RUnlock()
|
|
|
|
|
|
|
|
|
|
return bool(s.Browser)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save config.
|
2017-06-14 20:27:03 -04:00
|
|
|
|
func (s *serverConfigV19) Save() error {
|
2017-03-31 01:26:24 -04:00
|
|
|
|
s.RLock()
|
|
|
|
|
defer s.RUnlock()
|
|
|
|
|
|
|
|
|
|
// Save config file.
|
|
|
|
|
return quick.Save(getConfigFile(), s)
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-14 20:27:03 -04:00
|
|
|
|
func newServerConfigV19() *serverConfigV19 {
|
|
|
|
|
srvCfg := &serverConfigV19{
|
|
|
|
|
Version: v19,
|
2017-03-26 15:00:27 -04:00
|
|
|
|
Credential: mustGetNewCredential(),
|
|
|
|
|
Region: globalMinioDefaultRegion,
|
|
|
|
|
Browser: true,
|
|
|
|
|
Logger: &loggers{},
|
|
|
|
|
Notify: ¬ifier{},
|
2017-02-27 17:59:53 -05:00
|
|
|
|
}
|
2017-03-26 15:00:27 -04:00
|
|
|
|
|
2017-02-07 15:51:43 -05:00
|
|
|
|
// Enable console logger by default on a fresh run.
|
2017-03-23 19:36:00 -04:00
|
|
|
|
srvCfg.Logger.Console = NewConsoleLogger()
|
2017-02-07 15:51:43 -05:00
|
|
|
|
|
|
|
|
|
// Make sure to initialize notification configs.
|
|
|
|
|
srvCfg.Notify.AMQP = make(map[string]amqpNotify)
|
|
|
|
|
srvCfg.Notify.AMQP["1"] = amqpNotify{}
|
2017-06-14 20:27:03 -04:00
|
|
|
|
srvCfg.Notify.MQTT = make(map[string]mqttNotify)
|
|
|
|
|
srvCfg.Notify.MQTT["1"] = mqttNotify{}
|
2017-02-07 15:51:43 -05:00
|
|
|
|
srvCfg.Notify.ElasticSearch = make(map[string]elasticSearchNotify)
|
|
|
|
|
srvCfg.Notify.ElasticSearch["1"] = elasticSearchNotify{}
|
|
|
|
|
srvCfg.Notify.Redis = make(map[string]redisNotify)
|
|
|
|
|
srvCfg.Notify.Redis["1"] = redisNotify{}
|
|
|
|
|
srvCfg.Notify.NATS = make(map[string]natsNotify)
|
|
|
|
|
srvCfg.Notify.NATS["1"] = natsNotify{}
|
|
|
|
|
srvCfg.Notify.PostgreSQL = make(map[string]postgreSQLNotify)
|
|
|
|
|
srvCfg.Notify.PostgreSQL["1"] = postgreSQLNotify{}
|
2017-03-17 12:29:17 -04:00
|
|
|
|
srvCfg.Notify.MySQL = make(map[string]mySQLNotify)
|
|
|
|
|
srvCfg.Notify.MySQL["1"] = mySQLNotify{}
|
2017-02-07 15:51:43 -05:00
|
|
|
|
srvCfg.Notify.Kafka = make(map[string]kafkaNotify)
|
|
|
|
|
srvCfg.Notify.Kafka["1"] = kafkaNotify{}
|
|
|
|
|
srvCfg.Notify.Webhook = make(map[string]webhookNotify)
|
|
|
|
|
srvCfg.Notify.Webhook["1"] = webhookNotify{}
|
|
|
|
|
|
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-06-14 20:27:03 -04:00
|
|
|
|
srvCfg := newServerConfigV19()
|
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-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.
|
|
|
|
|
serverConfigMu.Lock()
|
|
|
|
|
serverConfig = srvCfg
|
|
|
|
|
serverConfigMu.Unlock()
|
|
|
|
|
|
|
|
|
|
// Save config into file.
|
|
|
|
|
return serverConfig.Save()
|
|
|
|
|
}
|
|
|
|
|
|
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-06-14 20:27:03 -04:00
|
|
|
|
func getValidConfig() (*serverConfigV19, error) {
|
|
|
|
|
srvCfg := &serverConfigV19{
|
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-06-14 20:27:03 -04:00
|
|
|
|
if srvCfg.Version != v19 {
|
|
|
|
|
return nil, fmt.Errorf("configuration version mismatch. Expected: ‘%s’, Got: ‘%s’", v19, 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate logger field
|
2017-03-31 01:26:24 -04:00
|
|
|
|
if err = srvCfg.Logger.Validate(); err != nil {
|
|
|
|
|
return nil, err
|
2017-03-15 19:30:34 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validate notify field
|
2017-03-31 01:26:24 -04:00
|
|
|
|
if err = srvCfg.Notify.Validate(); err != nil {
|
|
|
|
|
return nil, err
|
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-03-31 01:26:24 -04:00
|
|
|
|
// hold the mutex lock before a new config is assigned.
|
2017-02-27 17:59:53 -05:00
|
|
|
|
serverConfigMu.Lock()
|
2017-03-31 01:26:24 -04:00
|
|
|
|
serverConfig = srvCfg
|
|
|
|
|
if !globalIsEnvCreds {
|
|
|
|
|
globalActiveCred = serverConfig.GetCredential()
|
|
|
|
|
}
|
|
|
|
|
if !globalIsEnvBrowser {
|
|
|
|
|
globalIsBrowserEnabled = serverConfig.GetBrowser()
|
|
|
|
|
}
|
2017-04-09 13:44:10 -04:00
|
|
|
|
if !globalIsEnvRegion {
|
|
|
|
|
globalServerRegion = serverConfig.GetRegion()
|
|
|
|
|
}
|
2017-03-31 01:26:24 -04:00
|
|
|
|
serverConfigMu.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
|
|
|
|
}
|