From 6391d94516c02eb66c21ec8e3075d59cd442c251 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 13:14:19 +0100 Subject: [PATCH] glauth --- glauth/pkg/command/root.go | 20 ++++++++++++++----- glauth/pkg/command/server.go | 20 ------------------- glauth/pkg/config/config.go | 36 +++++++++++++---------------------- glauth/pkg/config/mappings.go | 11 +++++++++++ ocis/pkg/command/glauth.go | 14 +++++--------- proxy/pkg/command/root.go | 1 - 6 files changed, 44 insertions(+), 58 deletions(-) diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 4d68ded216..e6017cfef5 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -52,7 +52,7 @@ func Execute(cfg *config.Config) error { // NewLogger initializes a service-specific logger instance. func NewLogger(cfg *config.Config) log.Logger { - return oclog.LoggerFromConfig("glauth", cfg.Log) + return oclog.LoggerFromConfig("glauth", *cfg.Log) } // ParseConfig loads glauth configuration from known paths. @@ -62,8 +62,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } + // 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{} + } + // load all env variables relevant to the config in the current context. - conf.LoadOSEnv(config.GetEnv(), false) + conf.LoadOSEnv(config.GetEnv(cfg), false) bindings := config.StructMappings(cfg) return ociscfg.BindEnv(conf, bindings) } @@ -75,9 +87,7 @@ type SutureService struct { // NewSutureService creates a new glauth.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.GLAuth.Log == shared.Log{}) { - cfg.GLAuth.Log = cfg.Log - } + cfg.GLAuth.Commons = cfg.Commons return SutureService{ cfg: cfg.GLAuth, } diff --git a/glauth/pkg/command/server.go b/glauth/pkg/command/server.go index 380eba4199..d3e903503f 100644 --- a/glauth/pkg/command/server.go +++ b/glauth/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" - glauthcfg "github.com/glauth/glauth/v2/pkg/config" "github.com/oklog/run" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" @@ -28,9 +24,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, "/") } @@ -39,19 +32,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/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index 00843b8845..3268e13274 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -61,17 +61,19 @@ type Backend struct { // Config combines all available configuration parts. type Config struct { - 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"` + *shared.Commons + + 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 @@ -84,7 +86,6 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9129", }, @@ -126,14 +127,3 @@ func DefaultConfig() *Config { RoleBundleUUID: "71881883-1768-46bd-a24d-a356a2afdf7f", // BundleUUIDRoleAdmin } } - -// 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/glauth/pkg/config/mappings.go b/glauth/pkg/config/mappings.go index b7fc75748d..4867fc9ea2 100644 --- a/glauth/pkg/config/mappings.go +++ b/glauth/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/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index dcbfda8bdb..c6baacfdeb 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -3,15 +3,12 @@ package command import ( "github.com/owncloud/ocis/glauth/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "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", @@ -20,15 +17,14 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { if err := ParseConfig(ctx, cfg); err != nil { return err } - globalLog = cfg.Log + + if cfg.Commons != nil { + cfg.GLAuth.Commons = cfg.Commons + } + return nil }, Action: func(c *cli.Context) error { - // 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) }, diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index caad7d3477..13ea25e99d 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -88,7 +88,6 @@ type SutureService struct { // NewSutureService creates a new proxy.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - // inherit common configuration from ocis config parsing. cfg.Proxy.Commons = cfg.Commons return SutureService{ cfg: cfg.Proxy,