You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
293 lines
7.4 KiB
293 lines
7.4 KiB
9 years ago
|
/*
|
||
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
||
|
*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
8 years ago
|
package cmd
|
||
9 years ago
|
|
||
|
import (
|
||
|
"os"
|
||
|
"sync"
|
||
|
|
||
|
"github.com/minio/minio/pkg/quick"
|
||
|
)
|
||
|
|
||
8 years ago
|
// serverConfigV10 server configuration version '10' which is like version '9'
|
||
|
// except it drops support of syslog config
|
||
|
type serverConfigV10 struct {
|
||
9 years ago
|
Version string `json:"version"`
|
||
|
|
||
|
// S3 API configuration.
|
||
|
Credential credential `json:"credential"`
|
||
|
Region string `json:"region"`
|
||
|
|
||
|
// Additional error logging configuration.
|
||
|
Logger logger `json:"logger"`
|
||
|
|
||
8 years ago
|
// Notification queue configuration.
|
||
|
Notify notifier `json:"notify"`
|
||
|
|
||
9 years ago
|
// Read Write mutex.
|
||
|
rwMutex *sync.RWMutex
|
||
|
}
|
||
|
|
||
8 years ago
|
// initConfig - initialize server config and indicate if we are creating a new file or we are just loading
|
||
|
func initConfig() (bool, error) {
|
||
9 years ago
|
if !isConfigFileExists() {
|
||
8 years ago
|
// Initialize server config.
|
||
8 years ago
|
srvCfg := &serverConfigV10{}
|
||
9 years ago
|
srvCfg.Version = globalMinioConfigVersion
|
||
|
srvCfg.Region = "us-east-1"
|
||
|
srvCfg.Credential = mustGenAccessKeys()
|
||
8 years ago
|
|
||
9 years ago
|
// Enable console logger by default on a fresh run.
|
||
|
srvCfg.Logger.Console = consoleLogger{
|
||
|
Enable: true,
|
||
|
Level: "fatal",
|
||
|
}
|
||
8 years ago
|
|
||
|
// Make sure to initialize notification configs.
|
||
|
srvCfg.Notify.AMQP = make(map[string]amqpNotify)
|
||
|
srvCfg.Notify.AMQP["1"] = amqpNotify{}
|
||
|
srvCfg.Notify.ElasticSearch = make(map[string]elasticSearchNotify)
|
||
|
srvCfg.Notify.ElasticSearch["1"] = elasticSearchNotify{}
|
||
|
srvCfg.Notify.Redis = make(map[string]redisNotify)
|
||
|
srvCfg.Notify.Redis["1"] = redisNotify{}
|
||
8 years ago
|
srvCfg.Notify.NATS = make(map[string]natsNotify)
|
||
|
srvCfg.Notify.NATS["1"] = natsNotify{}
|
||
8 years ago
|
srvCfg.Notify.PostgreSQL = make(map[string]postgreSQLNotify)
|
||
|
srvCfg.Notify.PostgreSQL["1"] = postgreSQLNotify{}
|
||
9 years ago
|
srvCfg.rwMutex = &sync.RWMutex{}
|
||
8 years ago
|
|
||
9 years ago
|
// Create config path.
|
||
|
err := createConfigPath()
|
||
|
if err != nil {
|
||
8 years ago
|
return false, err
|
||
9 years ago
|
}
|
||
|
|
||
|
// Save the new config globally.
|
||
|
serverConfig = srvCfg
|
||
|
|
||
|
// Save config into file.
|
||
8 years ago
|
return true, serverConfig.Save()
|
||
9 years ago
|
}
|
||
|
configFile, err := getConfigFile()
|
||
|
if err != nil {
|
||
8 years ago
|
return false, err
|
||
9 years ago
|
}
|
||
9 years ago
|
if _, err = os.Stat(configFile); err != nil {
|
||
8 years ago
|
return false, err
|
||
9 years ago
|
}
|
||
8 years ago
|
srvCfg := &serverConfigV10{}
|
||
9 years ago
|
srvCfg.Version = globalMinioConfigVersion
|
||
|
srvCfg.rwMutex = &sync.RWMutex{}
|
||
|
qc, err := quick.New(srvCfg)
|
||
|
if err != nil {
|
||
8 years ago
|
return false, err
|
||
9 years ago
|
}
|
||
|
if err := qc.Load(configFile); err != nil {
|
||
8 years ago
|
return false, err
|
||
9 years ago
|
}
|
||
|
// Save the loaded config globally.
|
||
9 years ago
|
serverConfig = srvCfg
|
||
9 years ago
|
// Set the version properly after the unmarshalled json is loaded.
|
||
|
serverConfig.Version = globalMinioConfigVersion
|
||
8 years ago
|
|
||
8 years ago
|
return false, nil
|
||
9 years ago
|
}
|
||
|
|
||
|
// serverConfig server config.
|
||
8 years ago
|
var serverConfig *serverConfigV10
|
||
9 years ago
|
|
||
|
// GetVersion get current config version.
|
||
8 years ago
|
func (s serverConfigV10) GetVersion() string {
|
||
9 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
|
return s.Version
|
||
|
}
|
||
|
|
||
|
/// Logger related.
|
||
|
|
||
8 years ago
|
func (s *serverConfigV10) SetAMQPNotifyByID(accountID string, amqpn amqpNotify) {
|
||
8 years ago
|
s.rwMutex.Lock()
|
||
|
defer s.rwMutex.Unlock()
|
||
8 years ago
|
s.Notify.AMQP[accountID] = amqpn
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
func (s serverConfigV10) GetAMQP() map[string]amqpNotify {
|
||
8 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
8 years ago
|
return s.Notify.AMQP
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
// GetAMQPNotify get current AMQP logger.
|
||
8 years ago
|
func (s serverConfigV10) GetAMQPNotifyByID(accountID string) amqpNotify {
|
||
8 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
|
return s.Notify.AMQP[accountID]
|
||
|
}
|
||
|
|
||
8 years ago
|
//
|
||
8 years ago
|
func (s *serverConfigV10) SetNATSNotifyByID(accountID string, natsn natsNotify) {
|
||
8 years ago
|
s.rwMutex.Lock()
|
||
|
defer s.rwMutex.Unlock()
|
||
|
s.Notify.NATS[accountID] = natsn
|
||
|
}
|
||
|
|
||
8 years ago
|
func (s serverConfigV10) GetNATS() map[string]natsNotify {
|
||
8 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
|
return s.Notify.NATS
|
||
|
}
|
||
|
|
||
|
// GetNATSNotify get current NATS logger.
|
||
8 years ago
|
func (s serverConfigV10) GetNATSNotifyByID(accountID string) natsNotify {
|
||
8 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
|
return s.Notify.NATS[accountID]
|
||
|
}
|
||
|
|
||
8 years ago
|
func (s *serverConfigV10) SetElasticSearchNotifyByID(accountID string, esNotify elasticSearchNotify) {
|
||
8 years ago
|
s.rwMutex.Lock()
|
||
|
defer s.rwMutex.Unlock()
|
||
8 years ago
|
s.Notify.ElasticSearch[accountID] = esNotify
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
func (s serverConfigV10) GetElasticSearch() map[string]elasticSearchNotify {
|
||
8 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
8 years ago
|
return s.Notify.ElasticSearch
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
// GetElasticSearchNotify get current ElasicSearch logger.
|
||
8 years ago
|
func (s serverConfigV10) GetElasticSearchNotifyByID(accountID string) elasticSearchNotify {
|
||
8 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
|
return s.Notify.ElasticSearch[accountID]
|
||
|
}
|
||
|
|
||
8 years ago
|
func (s *serverConfigV10) SetRedisNotifyByID(accountID string, rNotify redisNotify) {
|
||
8 years ago
|
s.rwMutex.Lock()
|
||
|
defer s.rwMutex.Unlock()
|
||
8 years ago
|
s.Notify.Redis[accountID] = rNotify
|
||
|
}
|
||
|
|
||
8 years ago
|
func (s serverConfigV10) GetRedis() map[string]redisNotify {
|
||
8 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
|
return s.Notify.Redis
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
// GetRedisNotify get current Redis logger.
|
||
8 years ago
|
func (s serverConfigV10) GetRedisNotifyByID(accountID string) redisNotify {
|
||
8 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
8 years ago
|
return s.Notify.Redis[accountID]
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
func (s *serverConfigV10) SetPostgreSQLNotifyByID(accountID string, pgn postgreSQLNotify) {
|
||
8 years ago
|
s.rwMutex.Lock()
|
||
|
defer s.rwMutex.Unlock()
|
||
|
s.Notify.PostgreSQL[accountID] = pgn
|
||
|
}
|
||
|
|
||
8 years ago
|
func (s serverConfigV10) GetPostgreSQL() map[string]postgreSQLNotify {
|
||
8 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
|
return s.Notify.PostgreSQL
|
||
|
}
|
||
|
|
||
8 years ago
|
func (s serverConfigV10) GetPostgreSQLNotifyByID(accountID string) postgreSQLNotify {
|
||
8 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
|
return s.Notify.PostgreSQL[accountID]
|
||
|
}
|
||
|
|
||
9 years ago
|
// SetFileLogger set new file logger.
|
||
8 years ago
|
func (s *serverConfigV10) SetFileLogger(flogger fileLogger) {
|
||
9 years ago
|
s.rwMutex.Lock()
|
||
|
defer s.rwMutex.Unlock()
|
||
|
s.Logger.File = flogger
|
||
|
}
|
||
|
|
||
|
// GetFileLogger get current file logger.
|
||
8 years ago
|
func (s serverConfigV10) GetFileLogger() fileLogger {
|
||
9 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
|
return s.Logger.File
|
||
|
}
|
||
|
|
||
|
// SetConsoleLogger set new console logger.
|
||
8 years ago
|
func (s *serverConfigV10) SetConsoleLogger(clogger consoleLogger) {
|
||
9 years ago
|
s.rwMutex.Lock()
|
||
|
defer s.rwMutex.Unlock()
|
||
|
s.Logger.Console = clogger
|
||
|
}
|
||
|
|
||
|
// GetConsoleLogger get current console logger.
|
||
8 years ago
|
func (s serverConfigV10) GetConsoleLogger() consoleLogger {
|
||
9 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
|
return s.Logger.Console
|
||
|
}
|
||
|
|
||
|
// SetRegion set new region.
|
||
8 years ago
|
func (s *serverConfigV10) SetRegion(region string) {
|
||
9 years ago
|
s.rwMutex.Lock()
|
||
|
defer s.rwMutex.Unlock()
|
||
|
s.Region = region
|
||
|
}
|
||
|
|
||
|
// GetRegion get current region.
|
||
8 years ago
|
func (s serverConfigV10) GetRegion() string {
|
||
9 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
|
return s.Region
|
||
|
}
|
||
|
|
||
|
// SetCredentials set new credentials.
|
||
8 years ago
|
func (s *serverConfigV10) SetCredential(creds credential) {
|
||
9 years ago
|
s.rwMutex.Lock()
|
||
|
defer s.rwMutex.Unlock()
|
||
|
s.Credential = creds
|
||
|
}
|
||
|
|
||
|
// GetCredentials get current credentials.
|
||
8 years ago
|
func (s serverConfigV10) GetCredential() credential {
|
||
9 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
|
return s.Credential
|
||
|
}
|
||
|
|
||
|
// Save config.
|
||
8 years ago
|
func (s serverConfigV10) Save() error {
|
||
9 years ago
|
s.rwMutex.RLock()
|
||
|
defer s.rwMutex.RUnlock()
|
||
|
|
||
|
// get config file.
|
||
|
configFile, err := getConfigFile()
|
||
|
if err != nil {
|
||
9 years ago
|
return err
|
||
9 years ago
|
}
|
||
|
|
||
|
// initialize quick.
|
||
|
qc, err := quick.New(&s)
|
||
|
if err != nil {
|
||
9 years ago
|
return err
|
||
9 years ago
|
}
|
||
|
|
||
|
// Save config file.
|
||
9 years ago
|
return qc.Save(configFile)
|
||
9 years ago
|
}
|