From 96033dc9b3c7f7aeae8f06ba45e5aa946a7c76ad Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 14:06:29 +0100 Subject: [PATCH] new config framework in thumbnails --- ocis/pkg/command/thumbnails.go | 37 ++++++++++++++------------------ thumbnails/pkg/command/root.go | 6 +++++- thumbnails/pkg/command/server.go | 26 +++++++++++++++++++++- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index b81a0eedb..a6054da87 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -5,16 +5,16 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/version" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/thumbnails/pkg/command" "github.com/urfave/cli/v2" - - svcconfig "github.com/owncloud/ocis/thumbnails/pkg/config" ) // ThumbnailsCommand is the entrypoint for the thumbnails command. func ThumbnailsCommand(cfg *config.Config) *cli.Command { + var globalLog shared.Log + return &cli.Command{ Name: "thumbnails", Usage: "Start thumbnails server", @@ -23,31 +23,26 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.Thumbnails), }, Before: func(ctx *cli.Context) error { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + globalLog = cfg.Log + + return nil }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureThumbnails(cfg)) + // if thumbnails logging is empty in ocis.yaml + if (cfg.Thumbnails.Log == shared.Log{}) && (globalLog != shared.Log{}) { + // we can safely inherit the global logging values. + cfg.Thumbnails.Log = globalLog + } + origCmd := command.Server(cfg.Thumbnails) return handleOriginalAction(c, origCmd) }, } } -func configureThumbnails(cfg *config.Config) *svcconfig.Config { - cfg.Thumbnails.Log.Level = cfg.Log.Level - cfg.Thumbnails.Log.Pretty = cfg.Log.Pretty - cfg.Thumbnails.Log.Color = cfg.Log.Color - cfg.Thumbnails.Server.Version = version.String - - if cfg.Tracing.Enabled { - cfg.Thumbnails.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Thumbnails.Tracing.Type = cfg.Tracing.Type - cfg.Thumbnails.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Thumbnails.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Thumbnails -} - func init() { register.AddCommand(ThumbnailsCommand) } diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index b32d6b9b4..c6c6be424 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "context" "os" + "github.com/owncloud/ocis/ocis-pkg/shared" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" @@ -82,7 +84,9 @@ type SutureService struct { // NewSutureService creates a new thumbnails.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Thumbnails.Log = cfg.Log + if (cfg.Thumbnails.Log == shared.Log{}) { + cfg.Thumbnails.Log = cfg.Log + } return SutureService{ cfg: cfg.Thumbnails, } diff --git a/thumbnails/pkg/command/server.go b/thumbnails/pkg/command/server.go index 822549541..8e9db2538 100644 --- a/thumbnails/pkg/command/server.go +++ b/thumbnails/pkg/command/server.go @@ -4,6 +4,10 @@ import ( "context" "fmt" + gofig "github.com/gookit/config/v2" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/thumbnails/pkg/config" @@ -20,7 +24,27 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - return ParseConfig(ctx, cfg) + // remember shared logging info to prevent empty overwrites + inLog := cfg.Log + + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if (cfg.Log == shared.Log{}) && (inLog != shared.Log{}) { + // set the default to the parent config + cfg.Log = inLog + + // and parse the environment + conf := &gofig.Config{} + conf.LoadOSEnv(config.GetEnv(), false) + bindings := config.StructMappings(cfg) + if err := ociscfg.BindEnv(conf, bindings); err != nil { + return err + } + } + + return nil }, Action: func(c *cli.Context) error { logger := NewLogger(cfg)