From 3580e167714e5d4c5a86ea6be26a79bac6bdc4f2 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 15:12:37 +0100 Subject: [PATCH] losing my mind --- ocis/pkg/command/settings.go | 12 +++--------- ocis/pkg/runtime/service/service.go | 5 +++++ settings/pkg/command/root.go | 19 +++++++++++++++---- settings/pkg/command/server.go | 20 -------------------- settings/pkg/config/config.go | 16 +++------------- settings/pkg/config/mappings.go | 11 +++++++++++ settings/pkg/store/filesystem/store.go | 14 +++++++------- storage/pkg/command/appprovider.go | 2 +- storage/pkg/command/authbasic.go | 2 +- storage/pkg/command/authbearer.go | 2 +- storage/pkg/command/authmachine.go | 2 +- storage/pkg/command/frontend.go | 2 +- storage/pkg/command/gateway.go | 2 +- storage/pkg/command/groups.go | 2 +- storage/pkg/command/sharing.go | 2 +- storage/pkg/command/storagehome.go | 2 +- storage/pkg/command/storagemetadata.go | 2 +- storage/pkg/command/storagepubliclink.go | 2 +- storage/pkg/command/storageusers.go | 2 +- storage/pkg/command/users.go | 2 +- storage/pkg/config/config.go | 2 ++ 21 files changed, 59 insertions(+), 66 deletions(-) diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 9a2584566..adb37be5b 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.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/settings/pkg/command" "github.com/urfave/cli/v2" @@ -13,8 +12,6 @@ import ( // SettingsCommand is the entry point for the settings command. func SettingsCommand(cfg *config.Config) *cli.Command { - var globalLog shared.Log - return &cli.Command{ Name: "settings", Usage: "Start settings server", @@ -27,16 +24,13 @@ func SettingsCommand(cfg *config.Config) *cli.Command { return err } - globalLog = cfg.Log + if cfg.Commons != nil { + cfg.Settings.Commons = cfg.Commons + } return nil }, Action: func(c *cli.Context) error { - // if accounts logging is empty in ocis.yaml - if (cfg.Settings.Log == shared.Log{}) && (globalLog != shared.Log{}) { - // we can safely inherit the global logging values. - cfg.Settings.Log = globalLog - } origCmd := command.Server(cfg.Settings) return handleOriginalAction(c, origCmd) }, diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 4313a1473..4f041b2a0 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -159,6 +159,11 @@ func Start(o ...Option) error { FailureBackoff: 3 * time.Second, }) + s.cfg.Storage.Log.Color = s.cfg.Log.Color + s.cfg.Storage.Log.Level = s.cfg.Log.Level + s.cfg.Storage.Log.Pretty = s.cfg.Log.Pretty + s.cfg.Storage.Log.File = s.cfg.Log.File + if err = rpc.Register(s); err != nil { if s != nil { s.Log.Fatal().Err(err) diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index 2aba1f46a..74c09626e 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -71,7 +71,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) } @@ -83,9 +96,7 @@ type SutureService struct { // NewSutureService creates a new settings.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.Settings.Log == shared.Log{}) { - cfg.Settings.Log = cfg.Log - } + cfg.Settings.Commons = cfg.Commons return SutureService{ cfg: cfg.Settings, } diff --git a/settings/pkg/command/server.go b/settings/pkg/command/server.go index 22e483af3..894b159ff 100644 --- a/settings/pkg/command/server.go +++ b/settings/pkg/command/server.go @@ -4,10 +4,6 @@ import ( "context" "strings" - 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/settings/pkg/config" @@ -25,9 +21,6 @@ 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,19 +29,6 @@ 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/settings/pkg/config/config.go b/settings/pkg/config/config.go index 62da7e778..c41e2d8c9 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -68,9 +68,11 @@ type TokenManager struct { // Config combines all available configuration parts. type Config struct { + *shared.Commons + File string Service Service - Log shared.Log + Log *shared.Log Debug Debug HTTP HTTP GRPC GRPC @@ -90,7 +92,6 @@ func New() *Config { // DefaultConfig provides sane bootstrapping defaults. func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Service: Service{ Name: "settings", DataPath: path.Join(defaults.BaseDataPath(), "settings"), @@ -132,14 +133,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/settings/pkg/config/mappings.go b/settings/pkg/config/mappings.go index c19dfcaad..0fd5a9f2d 100644 --- a/settings/pkg/config/mappings.go +++ b/settings/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. diff --git a/settings/pkg/store/filesystem/store.go b/settings/pkg/store/filesystem/store.go index 8eb3f0341..cf81638b9 100644 --- a/settings/pkg/store/filesystem/store.go +++ b/settings/pkg/store/filesystem/store.go @@ -24,17 +24,17 @@ type Store struct { // New creates a new store func New(cfg *config.Config) settings.Manager { s := Store{ - Logger: olog.NewLogger( - olog.Color(cfg.Log.Color), - olog.Pretty(cfg.Log.Pretty), - olog.Level(cfg.Log.Level), - olog.File(cfg.Log.File), - ), + //Logger: olog.NewLogger( + // olog.Color(cfg.Log.Color), + // olog.Pretty(cfg.Log.Pretty), + // olog.Level(cfg.Log.Level), + // olog.File(cfg.Log.File), + //), } if _, err := os.Stat(cfg.Service.DataPath); err != nil { s.Logger.Info().Msgf("creating container on %v", cfg.Service.DataPath) - err := os.MkdirAll(cfg.Service.DataPath, 0700) + err = os.MkdirAll(cfg.Service.DataPath, 0700) if err != nil { s.Logger.Err(err).Msgf("providing container on %v", cfg.Service.DataPath) diff --git a/storage/pkg/command/appprovider.go b/storage/pkg/command/appprovider.go index 59c0684ec..07abdc79b 100644 --- a/storage/pkg/command/appprovider.go +++ b/storage/pkg/command/appprovider.go @@ -132,7 +132,7 @@ type AppProviderSutureService struct { // NewAppProvider creates a new store.AppProviderSutureService func NewAppProvider(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return AppProviderSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authbasic.go b/storage/pkg/command/authbasic.go index cd9ac7977..35ec89737 100644 --- a/storage/pkg/command/authbasic.go +++ b/storage/pkg/command/authbasic.go @@ -151,7 +151,7 @@ type AuthBasicSutureService struct { // NewAuthBasicSutureService creates a new store.AuthBasicSutureService func NewAuthBasic(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return AuthBasicSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authbearer.go b/storage/pkg/command/authbearer.go index 4c8d87463..beaf9b37b 100644 --- a/storage/pkg/command/authbearer.go +++ b/storage/pkg/command/authbearer.go @@ -127,7 +127,7 @@ type AuthBearerSutureService struct { // NewAuthBearerSutureService creates a new gateway.AuthBearerSutureService func NewAuthBearer(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return AuthBearerSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authmachine.go b/storage/pkg/command/authmachine.go index 9a0244895..8b6ea05bb 100644 --- a/storage/pkg/command/authmachine.go +++ b/storage/pkg/command/authmachine.go @@ -123,7 +123,7 @@ type AuthMachineSutureService struct { // NewAuthMachineSutureService creates a new gateway.AuthMachineSutureService func NewAuthMachine(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return AuthMachineSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/frontend.go b/storage/pkg/command/frontend.go index 314d1e149..aefd4f572 100644 --- a/storage/pkg/command/frontend.go +++ b/storage/pkg/command/frontend.go @@ -337,7 +337,7 @@ type FrontendSutureService struct { // NewFrontend creates a new frontend.FrontendSutureService func NewFrontend(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return FrontendSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index f68408342..9b1ec5717 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -351,7 +351,7 @@ type GatewaySutureService struct { // NewGatewaySutureService creates a new gateway.GatewaySutureService func NewGateway(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return GatewaySutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/groups.go b/storage/pkg/command/groups.go index 4142c8e9a..318386082 100644 --- a/storage/pkg/command/groups.go +++ b/storage/pkg/command/groups.go @@ -165,7 +165,7 @@ type GroupSutureService struct { // NewGroupProviderSutureService creates a new storage.GroupProvider func NewGroupProvider(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return GroupSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/sharing.go b/storage/pkg/command/sharing.go index c23455eb4..6a71e5b22 100644 --- a/storage/pkg/command/sharing.go +++ b/storage/pkg/command/sharing.go @@ -191,7 +191,7 @@ type SharingSutureService struct { // NewSharingSutureService creates a new store.SharingSutureService func NewSharing(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return SharingSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagehome.go b/storage/pkg/command/storagehome.go index 1ab83572a..5d4e6d5a4 100644 --- a/storage/pkg/command/storagehome.go +++ b/storage/pkg/command/storagehome.go @@ -150,7 +150,7 @@ type StorageHomeSutureService struct { // NewStorageHomeSutureService creates a new storage.StorageHomeSutureService func NewStorageHome(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return StorageHomeSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index 665d4606a..a853c68fb 100644 --- a/storage/pkg/command/storagemetadata.go +++ b/storage/pkg/command/storagemetadata.go @@ -166,7 +166,7 @@ type MetadataSutureService struct { // NewSutureService creates a new storagemetadata.SutureService func NewStorageMetadata(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return MetadataSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagepubliclink.go b/storage/pkg/command/storagepubliclink.go index d5bb031c7..eb3803e50 100644 --- a/storage/pkg/command/storagepubliclink.go +++ b/storage/pkg/command/storagepubliclink.go @@ -124,7 +124,7 @@ type StoragePublicLinkSutureService struct { // NewStoragePublicLinkSutureService creates a new storage.StoragePublicLinkSutureService func NewStoragePublicLink(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return StoragePublicLinkSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storageusers.go b/storage/pkg/command/storageusers.go index 51b48508d..d86d49b53 100644 --- a/storage/pkg/command/storageusers.go +++ b/storage/pkg/command/storageusers.go @@ -150,7 +150,7 @@ type StorageUsersSutureService struct { // NewStorageUsersSutureService creates a new storage.StorageUsersSutureService func NewStorageUsers(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return StorageUsersSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/users.go b/storage/pkg/command/users.go index 60115b875..6bc2bdc60 100644 --- a/storage/pkg/command/users.go +++ b/storage/pkg/command/users.go @@ -186,7 +186,7 @@ type UserProviderSutureService struct { // NewUserProviderSutureService creates a new storage.UserProvider func NewUserProvider(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return UserProviderSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 7b34ec647..cda41e5d5 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -500,6 +500,8 @@ type Asset struct { // Config combines all available configuration parts. type Config struct { + *shared.Commons + File string Log *shared.Log Debug Debug