diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 55b5070d67..6c8baa610c 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -19,21 +19,16 @@ func Execute(cfg *config.Config) error { Version: version.String, Usage: "Serve GLAuth API for oCIS", Compiled: version.Compiled(), - Authors: []*cli.Author{ { Name: "ownCloud GmbH", Email: "support@owncloud.com", }, }, - - //Flags: flagset.RootWithConfig(cfg), - Before: func(c *cli.Context) error { cfg.Version = version.String return nil }, - Commands: []*cli.Command{ Server(cfg), Health(cfg), @@ -73,12 +68,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - - if err = cfg.UnmapEnv(conf); err != nil { - return err - } - - return nil + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } // SutureService allows for the glauth command to be embedded and supervised by a suture supervisor tree. @@ -88,11 +79,7 @@ type SutureService struct { // NewSutureService creates a new glauth.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - inheritLogging(cfg) - if cfg.Mode == 0 { - cfg.GLAuth.Supervised = true - } - cfg.GLAuth.Log.File = cfg.Log.File + cfg.GLAuth.Log = cfg.Log return SutureService{ cfg: cfg.GLAuth, } @@ -106,13 +93,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.GLAuth.Log.File = cfg.Log.File - cfg.GLAuth.Log.Color = cfg.Log.Color - cfg.GLAuth.Log.Pretty = cfg.Log.Pretty - cfg.GLAuth.Log.Level = cfg.Log.Level -} diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index 6380aa8c64..89339a5fe4 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -6,18 +6,12 @@ import ( "path" "reflect" + "github.com/owncloud/ocis/ocis-pkg/shared" + gofig "github.com/gookit/config/v2" "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) -// 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"` -} - // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` @@ -70,17 +64,17 @@ type Backend struct { // Config combines all available configuration parts. type Config struct { - File string `mapstructure:"file"` - Log Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Tracing Tracing `mapstructure:"tracing"` - Ldap Ldap `mapstructure:"ldap"` - Ldaps Ldaps `mapstructure:"ldaps"` - Backend Backend `mapstructure:"backend"` - Fallback Backend `mapstructure:"fallback"` - Version string `mapstructure:"version"` - RoleBundleUUID string `mapstructure:"role_bundle_uuid"` + File string `mapstructure:"file"` + Log shared.Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + Ldap Ldap `mapstructure:"ldap"` + Ldaps Ldaps `mapstructure:"ldaps"` + Backend Backend `mapstructure:"backend"` + Fallback Backend `mapstructure:"fallback"` + Version string `mapstructure:"version"` + RoleBundleUUID string `mapstructure:"role_bundle_uuid"` Context context.Context Supervised bool @@ -93,7 +87,7 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: Log{}, + Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9129", }, diff --git a/glauth/pkg/config/env.go b/glauth/pkg/config/mappings.go similarity index 88% rename from glauth/pkg/config/env.go rename to glauth/pkg/config/mappings.go index ef48fdc5f4..7d2a1393d2 100644 --- a/glauth/pkg/config/env.go +++ b/glauth/pkg/config/mappings.go @@ -1,13 +1,22 @@ package config +import "github.com/owncloud/ocis/ocis-pkg/shared" + type mapping struct { EnvVars []string // name of the EnvVars var. Destination interface{} // memory address of the original config value to modify. } +// 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. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + // structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []mapping { - return []mapping{ +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ { EnvVars: []string{"GLAUTH_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index cc1f91fe1e..7544f9a91c 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -19,19 +19,16 @@ func Execute(cfg *config.Config) error { Version: version.String, Usage: "proxy for oCIS", Compiled: version.Compiled(), - Authors: []*cli.Author{ { Name: "ownCloud GmbH", Email: "support@owncloud.com", }, }, - Before: func(c *cli.Context) error { cfg.Service.Version = version.String return nil }, - Commands: []*cli.Command{ Server(cfg), Health(cfg),