Allows storagedriver parameter values to be of type interface{}
This enables use of nil, booleans, numeric types, and even complex structures for parameter values, assuming they can be parsed from yaml.
This commit is contained in:
parent
f9b119974d
commit
030b0ff310
5 changed files with 14 additions and 14 deletions
|
@ -103,7 +103,7 @@ func (storage Storage) Parameters() Parameters {
|
||||||
}
|
}
|
||||||
|
|
||||||
// setParameter changes the parameter at the provided key to the new value
|
// setParameter changes the parameter at the provided key to the new value
|
||||||
func (storage Storage) setParameter(key, value string) {
|
func (storage Storage) setParameter(key string, value interface{}) {
|
||||||
storage[storage.Type()][key] = value
|
storage[storage.Type()][key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ func (storage Storage) MarshalYAML() (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parameters defines a key-value parameters mapping
|
// Parameters defines a key-value parameters mapping
|
||||||
type Parameters map[string]string
|
type Parameters map[string]interface{}
|
||||||
|
|
||||||
// Reporting defines error reporting methods.
|
// Reporting defines error reporting methods.
|
||||||
type Reporting struct {
|
type Reporting struct {
|
||||||
|
|
|
@ -21,12 +21,12 @@ var configStruct = Configuration{
|
||||||
"region": "us-east-1",
|
"region": "us-east-1",
|
||||||
"bucket": "my-bucket",
|
"bucket": "my-bucket",
|
||||||
"rootpath": "/registry",
|
"rootpath": "/registry",
|
||||||
"encrypt": "true",
|
"encrypt": true,
|
||||||
"secure": "false",
|
"secure": false,
|
||||||
"accesskey": "SAMPLEACCESSKEY",
|
"accesskey": "SAMPLEACCESSKEY",
|
||||||
"secretkey": "SUPERSECRET",
|
"secretkey": "SUPERSECRET",
|
||||||
"host": "",
|
"host": nil,
|
||||||
"port": "",
|
"port": 42,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Reporting: Reporting{
|
Reporting: Reporting{
|
||||||
|
@ -50,7 +50,7 @@ storage:
|
||||||
accesskey: SAMPLEACCESSKEY
|
accesskey: SAMPLEACCESSKEY
|
||||||
secretkey: SUPERSECRET
|
secretkey: SUPERSECRET
|
||||||
host: ~
|
host: ~
|
||||||
port: ~
|
port: 42
|
||||||
reporting:
|
reporting:
|
||||||
bugsnag:
|
bugsnag:
|
||||||
apikey: BugsnagApiKey
|
apikey: BugsnagApiKey
|
||||||
|
@ -142,7 +142,7 @@ func (suite *ConfigSuite) TestParseWithSameEnvStorage(c *C) {
|
||||||
// Configuration struct
|
// Configuration struct
|
||||||
func (suite *ConfigSuite) TestParseWithDifferentEnvStorageParams(c *C) {
|
func (suite *ConfigSuite) TestParseWithDifferentEnvStorageParams(c *C) {
|
||||||
suite.expectedConfig.Storage.setParameter("region", "us-west-1")
|
suite.expectedConfig.Storage.setParameter("region", "us-west-1")
|
||||||
suite.expectedConfig.Storage.setParameter("secure", "true")
|
suite.expectedConfig.Storage.setParameter("secure", true)
|
||||||
suite.expectedConfig.Storage.setParameter("newparam", "some Value")
|
suite.expectedConfig.Storage.setParameter("newparam", "some Value")
|
||||||
|
|
||||||
os.Setenv("REGISTRY_STORAGE_S3_REGION", "us-west-1")
|
os.Setenv("REGISTRY_STORAGE_S3_REGION", "us-west-1")
|
||||||
|
|
|
@ -16,7 +16,7 @@ type StorageDriverFactory interface {
|
||||||
// Create returns a new storagedriver.StorageDriver with the given parameters
|
// Create returns a new storagedriver.StorageDriver with the given parameters
|
||||||
// Parameters will vary by driver and may be ignored
|
// Parameters will vary by driver and may be ignored
|
||||||
// Each parameter key must only consist of lowercase letters and numbers
|
// Each parameter key must only consist of lowercase letters and numbers
|
||||||
Create(parameters map[string]string) (storagedriver.StorageDriver, error)
|
Create(parameters map[string]interface{}) (storagedriver.StorageDriver, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register makes a storage driver available by the provided name.
|
// Register makes a storage driver available by the provided name.
|
||||||
|
@ -37,7 +37,7 @@ func Register(name string, factory StorageDriverFactory) {
|
||||||
// To run in-process, the StorageDriverFactory must first be registered with the given name
|
// To run in-process, the StorageDriverFactory must first be registered with the given name
|
||||||
// If no in-process drivers are found with the given name, this attempts to create an IPC driver
|
// If no in-process drivers are found with the given name, this attempts to create an IPC driver
|
||||||
// If no in-process or external drivers are found, an InvalidStorageDriverError is returned
|
// If no in-process or external drivers are found, an InvalidStorageDriverError is returned
|
||||||
func Create(name string, parameters map[string]string) (storagedriver.StorageDriver, error) {
|
func Create(name string, parameters map[string]interface{}) (storagedriver.StorageDriver, error) {
|
||||||
driverFactory, ok := driverFactories[name]
|
driverFactory, ok := driverFactories[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, InvalidStorageDriverError{name}
|
return nil, InvalidStorageDriverError{name}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func init() {
|
||||||
// filesystemDriverFactory implements the factory.StorageDriverFactory interface
|
// filesystemDriverFactory implements the factory.StorageDriverFactory interface
|
||||||
type filesystemDriverFactory struct{}
|
type filesystemDriverFactory struct{}
|
||||||
|
|
||||||
func (factory *filesystemDriverFactory) Create(parameters map[string]string) (storagedriver.StorageDriver, error) {
|
func (factory *filesystemDriverFactory) Create(parameters map[string]interface{}) (storagedriver.StorageDriver, error) {
|
||||||
return FromParameters(parameters), nil
|
return FromParameters(parameters), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,12 +36,12 @@ type Driver struct {
|
||||||
// FromParameters constructs a new Driver with a given parameters map
|
// FromParameters constructs a new Driver with a given parameters map
|
||||||
// Optional Parameters:
|
// Optional Parameters:
|
||||||
// - rootdirectory
|
// - rootdirectory
|
||||||
func FromParameters(parameters map[string]string) *Driver {
|
func FromParameters(parameters map[string]interface{}) *Driver {
|
||||||
var rootDirectory = defaultRootDirectory
|
var rootDirectory = defaultRootDirectory
|
||||||
if parameters != nil {
|
if parameters != nil {
|
||||||
rootDir, ok := parameters["rootdirectory"]
|
rootDir, ok := parameters["rootdirectory"]
|
||||||
if ok {
|
if ok {
|
||||||
rootDirectory = rootDir
|
rootDirectory = fmt.Sprint(rootDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return New(rootDirectory)
|
return New(rootDirectory)
|
||||||
|
|
|
@ -21,7 +21,7 @@ func init() {
|
||||||
// inMemoryDriverFacotry implements the factory.StorageDriverFactory interface.
|
// inMemoryDriverFacotry implements the factory.StorageDriverFactory interface.
|
||||||
type inMemoryDriverFactory struct{}
|
type inMemoryDriverFactory struct{}
|
||||||
|
|
||||||
func (factory *inMemoryDriverFactory) Create(parameters map[string]string) (storagedriver.StorageDriver, error) {
|
func (factory *inMemoryDriverFactory) Create(parameters map[string]interface{}) (storagedriver.StorageDriver, error) {
|
||||||
return New(), nil
|
return New(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue