From 3d90b21e3b3e6d64f4ef7faea499924ed36f00c1 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 13:48:07 +0100 Subject: [PATCH] new config framework in glauth --- glauth/pkg/command/root.go | 6 +++++- glauth/pkg/command/server.go | 20 ++++++++++++++++++++ ocis/pkg/command/glauth.go | 34 ++++++++++++++-------------------- ocis/pkg/command/idp.go | 21 +-------------------- ocis/pkg/command/proxy.go | 2 -- 5 files changed, 40 insertions(+), 43 deletions(-) diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 6c8baa610..18ada7b92 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "context" "os" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/owncloud/ocis/glauth/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" @@ -79,7 +81,9 @@ type SutureService struct { // NewSutureService creates a new glauth.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.GLAuth.Log = cfg.Log + if (cfg.GLAuth.Log == shared.Log{}) { + cfg.GLAuth.Log = cfg.Log + } return SutureService{ cfg: cfg.GLAuth, } diff --git a/glauth/pkg/command/server.go b/glauth/pkg/command/server.go index d3e903503..380eba419 100644 --- a/glauth/pkg/command/server.go +++ b/glauth/pkg/command/server.go @@ -4,6 +4,10 @@ import ( "context" "strings" + gofig "github.com/gookit/config/v2" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" + glauthcfg "github.com/glauth/glauth/v2/pkg/config" "github.com/oklog/run" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" @@ -24,6 +28,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, "/") } @@ -32,6 +39,19 @@ func Server(cfg *config.Config) *cli.Command { 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/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index 4b9dbade5..dcbfda8bd 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -2,45 +2,39 @@ package command import ( "github.com/owncloud/ocis/glauth/pkg/command" - svcconfig "github.com/owncloud/ocis/glauth/pkg/config" "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/urfave/cli/v2" ) // GLAuthCommand is the entrypoint for the glauth command. func GLAuthCommand(cfg *config.Config) *cli.Command { + var globalLog shared.Log + return &cli.Command{ Name: "glauth", Usage: "Start glauth server", Category: "Extensions", 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(configureGLAuth(cfg)) + // if Glauth logging is empty in ocis.yaml + if (cfg.GLAuth.Log == shared.Log{}) && (globalLog != shared.Log{}) { + // we can safely inherit the global logging values. + cfg.GLAuth.Log = globalLog + } + origCmd := command.Server(cfg.GLAuth) return handleOriginalAction(c, origCmd) }, } } -func configureGLAuth(cfg *config.Config) *svcconfig.Config { - cfg.GLAuth.Log.Level = cfg.Log.Level - cfg.GLAuth.Log.Pretty = cfg.Log.Pretty - cfg.GLAuth.Log.Color = cfg.Log.Color - cfg.GLAuth.Version = version.String - - if cfg.Tracing.Enabled { - cfg.GLAuth.Tracing.Enabled = cfg.Tracing.Enabled - cfg.GLAuth.Tracing.Type = cfg.Tracing.Type - cfg.GLAuth.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.GLAuth.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.GLAuth -} - func init() { register.AddCommand(GLAuthCommand) } diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 7663c9449..9ee679aad 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -2,9 +2,7 @@ package command import ( "github.com/owncloud/ocis/idp/pkg/command" - svcconfig "github.com/owncloud/ocis/idp/pkg/config" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -22,7 +20,7 @@ func IDPCommand(cfg *config.Config) *cli.Command { return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { - idpCommand := command.Server(configureIDP(cfg)) + idpCommand := command.Server(cfg.IDP) if err := idpCommand.Before(c); err != nil { return err @@ -33,23 +31,6 @@ func IDPCommand(cfg *config.Config) *cli.Command { } } -func configureIDP(cfg *config.Config) *svcconfig.Config { - cfg.IDP.Log.Level = cfg.Log.Level - cfg.IDP.Log.Pretty = cfg.Log.Pretty - cfg.IDP.Log.Color = cfg.Log.Color - cfg.IDP.HTTP.TLS = false - cfg.IDP.Service.Version = version.String - - if cfg.Tracing.Enabled { - cfg.IDP.Tracing.Enabled = cfg.Tracing.Enabled - cfg.IDP.Tracing.Type = cfg.Tracing.Type - cfg.IDP.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.IDP.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.IDP -} - func init() { register.AddCommand(IDPCommand) } diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index f2cfe5e2b..3f327d816 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -26,9 +26,7 @@ func ProxyCommand(cfg *config.Config) *cli.Command { if err := ParseConfig(ctx, cfg); err != nil { return err } - globalLog = cfg.Log - return nil }, Action: func(c *cli.Context) error {