From d7828141f620d4452f0833dd30ba0954d91eaa92 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 11:51:35 +0100 Subject: [PATCH] fix log inheritance for accounts --- accounts/pkg/command/root.go | 16 +--------------- accounts/pkg/config/config.go | 14 ++++---------- ocis/pkg/command/accounts.go | 26 ++------------------------ 3 files changed, 7 insertions(+), 49 deletions(-) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 305e6ae70..af4578977 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -90,11 +90,7 @@ type SutureService struct { // NewSutureService creates a new accounts.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - inheritLogging(cfg) - if cfg.Mode == 0 { - cfg.Accounts.Supervised = true - } - cfg.Accounts.Log.File = cfg.Log.File + cfg.Accounts.Log = cfg.Log return SutureService{ cfg: cfg.Accounts, } @@ -108,13 +104,3 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } - -// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging -// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, -// being overwritten when the extension parses its config file / env variables. -func inheritLogging(cfg *ociscfg.Config) { - cfg.Accounts.Log.File = cfg.Log.File - cfg.Accounts.Log.Color = cfg.Log.Color - cfg.Accounts.Log.Pretty = cfg.Log.Pretty - cfg.Accounts.Log.Level = cfg.Log.Level -} diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index 340f07f04..329a29048 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -7,6 +7,8 @@ import ( "path" "reflect" + "github.com/owncloud/ocis/ocis-pkg/shared" + gofig "github.com/gookit/config/v2" "github.com/owncloud/ocis/ocis-pkg/config/defaults" @@ -76,14 +78,6 @@ type TokenManager struct { JWTSecret string `mapstructure:"jwt_secret"` } -// Log defines the available logging configuration. -type Log struct { - Level string `mapstructure:"level"` - Pretty bool `mapstructure:"pretty"` - Color bool `mapstructure:"color"` - File string `mapstructure:"file"` -} - // Repo defines which storage implementation is to be used. type Repo struct { Backend string `mapstructure:"backend"` @@ -140,7 +134,7 @@ type Config struct { GRPC GRPC `mapstructure:"grpc"` Server Server `mapstructure:"server"` Asset Asset `mapstructure:"asset"` - Log Log `mapstructure:"log"` + Log shared.Log `mapstructure:"log"` TokenManager TokenManager `mapstructure:"token_manager"` Repo Repo `mapstructure:"repo"` Index Index `mapstructure:"index"` @@ -181,7 +175,7 @@ func DefaultConfig() *Config { DemoUsersAndGroups: true, }, Asset: Asset{}, - Log: Log{}, + Log: shared.Log{}, TokenManager: TokenManager{ JWTSecret: "Pive-Fumkiu4", }, diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 13594bf26..12d16109d 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -5,9 +5,7 @@ package command import ( "github.com/owncloud/ocis/accounts/pkg/command" - svcconfig "github.com/owncloud/ocis/accounts/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" ) @@ -30,33 +28,13 @@ func AccountsCommand(cfg *config.Config) *cli.Command { return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureAccounts(cfg)) + cfg.Accounts.Log = cfg.Log + origCmd := command.Server(cfg.Accounts) return handleOriginalAction(c, origCmd) }, } } -func configureAccounts(cfg *config.Config) *svcconfig.Config { - cfg.Accounts.Log.Level = cfg.Log.Level - cfg.Accounts.Log.Pretty = cfg.Log.Pretty - cfg.Accounts.Log.Color = cfg.Log.Color - cfg.Accounts.Server.Version = version.String - - if cfg.Tracing.Enabled { - cfg.Accounts.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Accounts.Tracing.Type = cfg.Tracing.Type - cfg.Accounts.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Accounts.Tracing.Collector = cfg.Tracing.Collector - } - - if cfg.TokenManager.JWTSecret != "" { - cfg.Accounts.TokenManager.JWTSecret = cfg.TokenManager.JWTSecret - cfg.Accounts.Repo.CS3.JWTSecret = cfg.TokenManager.JWTSecret - } - - return cfg.Accounts -} - func init() { register.AddCommand(AccountsCommand) }