fix log inheritance for accounts

This commit is contained in:
A.Unger
2021-11-08 11:51:35 +01:00
parent 4999d4a04c
commit d7828141f6
3 changed files with 7 additions and 49 deletions

View File

@@ -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
}

View File

@@ -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",
},

View File

@@ -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)
}