Update yaml parser
Mark the top level Loglevel field as deprecated Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
parent
94deea2951
commit
f0ee5720a5
19 changed files with 855 additions and 492 deletions
|
@ -30,7 +30,7 @@ type Configuration struct {
|
|||
} `yaml:"accesslog,omitempty"`
|
||||
|
||||
// Level is the granularity at which registry operations are logged.
|
||||
Level Loglevel `yaml:"level"`
|
||||
Level Loglevel `yaml:"level,omitempty"`
|
||||
|
||||
// Formatter overrides the default formatter with another. Options
|
||||
// include "text", "json" and "logstash".
|
||||
|
@ -45,8 +45,9 @@ type Configuration struct {
|
|||
Hooks []LogHook `yaml:"hooks,omitempty"`
|
||||
}
|
||||
|
||||
// Loglevel is the level at which registry operations are logged. This is
|
||||
// deprecated. Please use Log.Level in the future.
|
||||
// Loglevel is the level at which registry operations are logged.
|
||||
//
|
||||
// Deprecated: Use Log.Level instead.
|
||||
Loglevel Loglevel `yaml:"loglevel,omitempty"`
|
||||
|
||||
// Storage is the configuration for the registry's storage driver
|
||||
|
@ -640,8 +641,15 @@ func Parse(rd io.Reader) (*Configuration, error) {
|
|||
ParseAs: reflect.TypeOf(v0_1Configuration{}),
|
||||
ConversionFunc: func(c interface{}) (interface{}, error) {
|
||||
if v0_1, ok := c.(*v0_1Configuration); ok {
|
||||
if v0_1.Loglevel == Loglevel("") {
|
||||
v0_1.Loglevel = Loglevel("info")
|
||||
if v0_1.Log.Level == Loglevel("") {
|
||||
if v0_1.Loglevel != Loglevel("") {
|
||||
v0_1.Log.Level = v0_1.Loglevel
|
||||
} else {
|
||||
v0_1.Log.Level = Loglevel("info")
|
||||
}
|
||||
}
|
||||
if v0_1.Loglevel != Loglevel("") {
|
||||
v0_1.Loglevel = Loglevel("")
|
||||
}
|
||||
if v0_1.Storage.Type() == "" {
|
||||
return nil, errors.New("No storage configuration provided")
|
||||
|
|
|
@ -22,14 +22,14 @@ var configStruct = Configuration{
|
|||
AccessLog struct {
|
||||
Disabled bool `yaml:"disabled,omitempty"`
|
||||
} `yaml:"accesslog,omitempty"`
|
||||
Level Loglevel `yaml:"level"`
|
||||
Level Loglevel `yaml:"level,omitempty"`
|
||||
Formatter string `yaml:"formatter,omitempty"`
|
||||
Fields map[string]interface{} `yaml:"fields,omitempty"`
|
||||
Hooks []LogHook `yaml:"hooks,omitempty"`
|
||||
}{
|
||||
Level: "info",
|
||||
Fields: map[string]interface{}{"environment": "test"},
|
||||
},
|
||||
Loglevel: "info",
|
||||
Storage: Storage{
|
||||
"s3": Parameters{
|
||||
"region": "us-east-1",
|
||||
|
@ -126,9 +126,9 @@ var configStruct = Configuration{
|
|||
var configYamlV0_1 = `
|
||||
version: 0.1
|
||||
log:
|
||||
level: info
|
||||
fields:
|
||||
environment: test
|
||||
loglevel: info
|
||||
storage:
|
||||
s3:
|
||||
region: us-east-1
|
||||
|
@ -171,7 +171,8 @@ http:
|
|||
// storage driver with no parameters
|
||||
var inmemoryConfigYamlV0_1 = `
|
||||
version: 0.1
|
||||
loglevel: info
|
||||
log:
|
||||
level: info
|
||||
storage: inmemory
|
||||
auth:
|
||||
silly:
|
||||
|
@ -212,6 +213,7 @@ func (suite *ConfigSuite) TestMarshalRoundtrip(c *C) {
|
|||
configBytes, err := yaml.Marshal(suite.expectedConfig)
|
||||
c.Assert(err, IsNil)
|
||||
config, err := Parse(bytes.NewReader(configBytes))
|
||||
c.Log(string(configBytes))
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(config, DeepEquals, suite.expectedConfig)
|
||||
}
|
||||
|
@ -334,9 +336,9 @@ func (suite *ConfigSuite) TestParseWithSameEnvLoglevel(c *C) {
|
|||
// TestParseWithDifferentEnvLoglevel validates that providing an environment variable defining the
|
||||
// log level will override the value provided in the yaml document
|
||||
func (suite *ConfigSuite) TestParseWithDifferentEnvLoglevel(c *C) {
|
||||
suite.expectedConfig.Loglevel = "error"
|
||||
suite.expectedConfig.Log.Level = "error"
|
||||
|
||||
os.Setenv("REGISTRY_LOGLEVEL", "error")
|
||||
os.Setenv("REGISTRY_LOG_LEVEL", "error")
|
||||
|
||||
config, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
|
||||
c.Assert(err, IsNil)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue