Skip to content

Commit

Permalink
Merge pull request #2681 from dmcgowan/update-yaml
Browse files Browse the repository at this point in the history
Update yaml parser
  • Loading branch information
dmp42 authored Aug 20, 2018
2 parents 633401c + f0ee572 commit 6411087
Show file tree
Hide file tree
Showing 19 changed files with 885 additions and 522 deletions.
18 changes: 13 additions & 5 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
14 changes: 8 additions & 6 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,6 @@ func configureReporting(app *handlers.App) http.Handler {
// configureLogging prepares the context with a logger using the
// configuration.
func configureLogging(ctx context.Context, config *configuration.Configuration) (context.Context, error) {
if config.Log.Level == "" && config.Log.Formatter == "" {
// If no config for logging is set, fallback to deprecated "Loglevel".
log.SetLevel(logLevel(config.Loglevel))
ctx = dcontext.WithLogger(ctx, dcontext.GetLogger(ctx))
return ctx, nil
}

log.SetLevel(logLevel(config.Log.Level))

formatter := config.Log.Formatter
Expand Down
2 changes: 1 addition & 1 deletion vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ google.golang.org/cloud 975617b05ea8a58727e6c1a06b6161ff4185a9f2
google.golang.org/grpc d3ddb4469d5a1b949fc7a7da7c1d6a0d1b6de994
gopkg.in/check.v1 64131543e7896d5bcc6bd5a76287eb75ea96c673
gopkg.in/square/go-jose.v1 40d457b439244b546f023d056628e5184136899b
gopkg.in/yaml.v2 bef53efd0c76e49e6de55ead051f886bea7e9420
gopkg.in/yaml.v2 v2.2.1
rsc.io/letsencrypt e770c10b0f1a64775ae91d240407ce00d1a5bdeb https://github.com/dmcgowan/letsencrypt.git
github.com/opencontainers/go-digest a6d0ee40d4207ea02364bd3b9e8e77b9159ba1eb
github.com/opencontainers/image-spec ab7389ef9f50030c9b245bc16b981c7ddf192882
Loading

0 comments on commit 6411087

Please sign in to comment.