diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index a6054da87d..0562b5d617 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -5,7 +5,6 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "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" @@ -13,8 +12,6 @@ import ( // 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", @@ -27,16 +24,13 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { return err } - globalLog = cfg.Log + if cfg.Commons != nil { + cfg.Thumbnails.Commons = cfg.Commons + } return nil }, Action: func(c *cli.Context) error { - // 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) }, diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index c6c6be4240..5136f0df0c 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -72,7 +72,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { if err != nil { return err } - conf.LoadOSEnv(config.GetEnv(), false) + + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &shared.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil && cfg.Commons == nil { + cfg.Log = &shared.Log{} + } + + conf.LoadOSEnv(config.GetEnv(cfg), false) bindings := config.StructMappings(cfg) return ociscfg.BindEnv(conf, bindings) } @@ -84,9 +97,7 @@ type SutureService struct { // NewSutureService creates a new thumbnails.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.Thumbnails.Log == shared.Log{}) { - cfg.Thumbnails.Log = cfg.Log - } + cfg.Thumbnails.Commons = cfg.Commons return SutureService{ cfg: cfg.Thumbnails, } diff --git a/thumbnails/pkg/command/server.go b/thumbnails/pkg/command/server.go index 8e9db2538d..e929245a47 100644 --- a/thumbnails/pkg/command/server.go +++ b/thumbnails/pkg/command/server.go @@ -4,10 +4,6 @@ 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" @@ -24,26 +20,9 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - // 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 { diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index e91137d13e..8e5e52517b 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -35,12 +35,14 @@ type Tracing struct { // Config combines all available configuration parts. type Config struct { - File string `mapstructure:"file"` - Log shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - Server Server `mapstructure:"server"` - Tracing Tracing `mapstructure:"tracing"` - Thumbnail Thumbnail `mapstructure:"thumbnail"` + *shared.Commons + + File string `mapstructure:"file"` + Log *shared.Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + Server Server `mapstructure:"server"` + Tracing Tracing `mapstructure:"tracing"` + Thumbnail Thumbnail `mapstructure:"thumbnail"` Context context.Context Supervised bool @@ -73,7 +75,6 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9189", Token: "", @@ -104,14 +105,3 @@ func DefaultConfig() *Config { }, } } - -// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list -// with all the environment variables an extension supports. -func GetEnv() []string { - var r = make([]string, len(structMappings(&Config{}))) - for i := range structMappings(&Config{}) { - r = append(r, structMappings(&Config{})[i].EnvVars...) - } - - return r -} diff --git a/thumbnails/pkg/config/mappings.go b/thumbnails/pkg/config/mappings.go index 2a7e181a36..c4e5e07b53 100644 --- a/thumbnails/pkg/config/mappings.go +++ b/thumbnails/pkg/config/mappings.go @@ -2,6 +2,17 @@ package config import "github.com/owncloud/ocis/ocis-pkg/shared" +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv(cfg *Config) []string { + var r = make([]string, len(structMappings(cfg))) + for i := range structMappings(cfg) { + r = append(r, structMappings(cfg)[i].EnvVars...) + } + + return r +} + // StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the // Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets // us propagate changes easier.