diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index 1f78830a5d..e4cff0b260 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "context" "os" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/owncloud/ocis/idp/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" @@ -82,7 +84,9 @@ type SutureService struct { // NewSutureService creates a new idp.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.IDP.Log = cfg.Log + if (cfg.Accounts.Log == shared.Log{}) { + cfg.Accounts.Log = cfg.Log + } return SutureService{ cfg: cfg.IDP, } diff --git a/idp/pkg/command/server.go b/idp/pkg/command/server.go index 1036f6d6ad..cb56afc2f5 100644 --- a/idp/pkg/command/server.go +++ b/idp/pkg/command/server.go @@ -4,12 +4,15 @@ import ( "context" "strings" + gofig "github.com/gookit/config/v2" "github.com/oklog/run" "github.com/owncloud/ocis/idp/pkg/config" "github.com/owncloud/ocis/idp/pkg/metrics" "github.com/owncloud/ocis/idp/pkg/server/debug" "github.com/owncloud/ocis/idp/pkg/server/http" "github.com/owncloud/ocis/idp/pkg/tracing" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/urfave/cli/v2" ) @@ -20,6 +23,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 cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } @@ -36,7 +42,24 @@ func Server(cfg *config.Config) *cli.Command { // cfg.IDP.SigningPrivateKeyFiles = ctx.StringSlice("signing-private-key") //} - return ParseConfig(ctx, cfg) + 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) diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 9ee679aad2..01f12c210f 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -3,12 +3,15 @@ package command import ( "github.com/owncloud/ocis/idp/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) // IDPCommand is the entrypoint for the idp command. func IDPCommand(cfg *config.Config) *cli.Command { + var globalLog shared.Log + return &cli.Command{ Name: "idp", Usage: "Start idp server", @@ -17,11 +20,21 @@ func IDPCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.IDP), }, 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 { + // if idp logging is empty in ocis.yaml + if (cfg.IDP.Log == shared.Log{}) && (globalLog != shared.Log{}) { + // we can safely inherit the global logging values. + cfg.IDP.Log = globalLog + } idpCommand := command.Server(cfg.IDP) - if err := idpCommand.Before(c); err != nil { return err }