@ -20,6 +20,7 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"reflect"
"sync"
"sync"
"github.com/minio/minio/pkg/auth"
"github.com/minio/minio/pkg/auth"
@ -48,34 +49,22 @@ var (
// GetVersion get current config version.
// GetVersion get current config version.
func ( s * serverConfig ) GetVersion ( ) string {
func ( s * serverConfig ) GetVersion ( ) string {
s . RLock ( )
defer s . RUnlock ( )
return s . Version
return s . Version
}
}
// SetRegion set a new region.
// SetRegion set a new region.
func ( s * serverConfig ) SetRegion ( region string ) {
func ( s * serverConfig ) SetRegion ( region string ) {
s . Lock ( )
defer s . Unlock ( )
// Save new region.
// Save new region.
s . Region = region
s . Region = region
}
}
// GetRegion get current region.
// GetRegion get current region.
func ( s * serverConfig ) GetRegion ( ) string {
func ( s * serverConfig ) GetRegion ( ) string {
s . RLock ( )
defer s . RUnlock ( )
return s . Region
return s . Region
}
}
// SetCredential sets new credential and returns the previous credential.
// SetCredential sets new credential and returns the previous credential.
func ( s * serverConfig ) SetCredential ( creds auth . Credentials ) ( prevCred auth . Credentials ) {
func ( s * serverConfig ) SetCredential ( creds auth . Credentials ) ( prevCred auth . Credentials ) {
s . Lock ( )
defer s . Unlock ( )
// Save previous credential.
// Save previous credential.
prevCred = s . Credential
prevCred = s . Credential
@ -88,25 +77,16 @@ func (s *serverConfig) SetCredential(creds auth.Credentials) (prevCred auth.Cred
// GetCredentials get current credentials.
// GetCredentials get current credentials.
func ( s * serverConfig ) GetCredential ( ) auth . Credentials {
func ( s * serverConfig ) GetCredential ( ) auth . Credentials {
s . RLock ( )
defer s . RUnlock ( )
return s . Credential
return s . Credential
}
}
// SetBrowser set if browser is enabled.
// SetBrowser set if browser is enabled.
func ( s * serverConfig ) SetBrowser ( b bool ) {
func ( s * serverConfig ) SetBrowser ( b bool ) {
s . Lock ( )
defer s . Unlock ( )
// Set the new value.
// Set the new value.
s . Browser = BrowserFlag ( b )
s . Browser = BrowserFlag ( b )
}
}
func ( s * serverConfig ) SetStorageClass ( standardClass , rrsClass storageClass ) {
func ( s * serverConfig ) SetStorageClass ( standardClass , rrsClass storageClass ) {
s . Lock ( )
defer s . Unlock ( )
s . StorageClass . Standard = standardClass
s . StorageClass . Standard = standardClass
s . StorageClass . RRS = rrsClass
s . StorageClass . RRS = rrsClass
}
}
@ -114,9 +94,6 @@ func (s *serverConfig) SetStorageClass(standardClass, rrsClass storageClass) {
// GetStorageClass reads storage class fields from current config, parses and validates it.
// GetStorageClass reads storage class fields from current config, parses and validates it.
// It returns the standard and reduced redundancy storage class struct
// It returns the standard and reduced redundancy storage class struct
func ( s * serverConfig ) GetStorageClass ( ) ( storageClass , storageClass ) {
func ( s * serverConfig ) GetStorageClass ( ) ( storageClass , storageClass ) {
s . RLock ( )
defer s . RUnlock ( )
var err error
var err error
// Storage Class from config.json is already parsed and stored in s.StorageClass
// Storage Class from config.json is already parsed and stored in s.StorageClass
// Now validate the storage class fields
// Now validate the storage class fields
@ -140,21 +117,59 @@ func (s *serverConfig) GetStorageClass() (storageClass, storageClass) {
// GetCredentials get current credentials.
// GetCredentials get current credentials.
func ( s * serverConfig ) GetBrowser ( ) bool {
func ( s * serverConfig ) GetBrowser ( ) bool {
s . RLock ( )
defer s . RUnlock ( )
return bool ( s . Browser )
return bool ( s . Browser )
}
}
// Save config.
// Save config.
func ( s * serverConfig ) Save ( ) error {
func ( s * serverConfig ) Save ( ) error {
s . RLock ( )
defer s . RUnlock ( )
// Save config file.
// Save config file.
return quick . Save ( getConfigFile ( ) , s )
return quick . Save ( getConfigFile ( ) , s )
}
}
// 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"
case ! reflect . DeepEqual ( s . Notify . ElasticSearch , t . Notify . ElasticSearch ) :
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"
}
}
func newServerConfig ( ) * serverConfig {
func newServerConfig ( ) * serverConfig {
srvCfg := & serverConfig {
srvCfg := & serverConfig {
Version : serverConfigVersion ,
Version : serverConfigVersion ,
@ -162,7 +177,7 @@ func newServerConfig() *serverConfig {
Region : globalMinioDefaultRegion ,
Region : globalMinioDefaultRegion ,
Browser : true ,
Browser : true ,
StorageClass : storageClassConfig { } ,
StorageClass : storageClassConfig { } ,
Notify : & notifier { } ,
Notify : notifier { } ,
}
}
// Make sure to initialize notification configs.
// Make sure to initialize notification configs.