From 9c2150422debb259821598fe07844afa55167b07 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 15:59:13 +0100 Subject: [PATCH] addded webdav to the new inheritance strategy --- ocis/pkg/command/webdav.go | 11 +++-------- webdav/pkg/command/root.go | 18 ++++++++++++++---- webdav/pkg/command/server.go | 20 -------------------- webdav/pkg/config/config.go | 30 ++++++++++-------------------- webdav/pkg/config/mappings.go | 11 +++++++++++ 5 files changed, 38 insertions(+), 52 deletions(-) diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index ae9e50fda..0502642bb 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.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/webdav/pkg/command" "github.com/urfave/cli/v2" @@ -13,7 +12,6 @@ import ( // WebDAVCommand is the entrypoint for the webdav command. func WebDAVCommand(cfg *config.Config) *cli.Command { - var globalLog shared.Log return &cli.Command{ Name: "webdav", @@ -27,16 +25,13 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { return err } - globalLog = cfg.Log + if cfg.Commons != nil { + cfg.WebDAV.Commons = cfg.Commons + } return nil }, Action: func(c *cli.Context) error { - // if webdav logging is empty in ocis.yaml - if (cfg.WebDAV.Log == shared.Log{}) && (globalLog != shared.Log{}) { - // we can safely inherit the global logging values. - cfg.WebDAV.Log = globalLog - } origCmd := command.Server(cfg.WebDAV) return handleOriginalAction(c, origCmd) }, diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index ea5464000..f221de832 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -70,8 +70,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) @@ -84,9 +96,7 @@ type SutureService struct { // NewSutureService creates a new webdav.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.WebDAV.Log == shared.Log{}) { - cfg.WebDAV.Log = cfg.Log - } + cfg.Proxy.Commons = cfg.Commons return SutureService{ cfg: cfg.WebDAV, } diff --git a/webdav/pkg/command/server.go b/webdav/pkg/command/server.go index 8e28925e7..16be22e97 100644 --- a/webdav/pkg/command/server.go +++ b/webdav/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/webdav/pkg/config" @@ -24,9 +20,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, "/") } @@ -35,19 +28,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/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index 801de7213..e8319c8b6 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -47,14 +47,16 @@ type Tracing 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"` - Service Service `mapstructure:"service"` - OcisPublicURL string `mapstructure:"ocis_public_url"` - WebdavNamespace string `mapstructure:"webdav_namespace"` + *shared.Commons + + File string `mapstructure:"file"` + Log *shared.Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + Service Service `mapstructure:"service"` + OcisPublicURL string `mapstructure:"ocis_public_url"` + WebdavNamespace string `mapstructure:"webdav_namespace"` Context context.Context Supervised bool @@ -67,7 +69,6 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Debug: Debug{ Addr: "", Token: "", @@ -99,14 +100,3 @@ func DefaultConfig() *Config { WebdavNamespace: "/home", } } - -// 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/webdav/pkg/config/mappings.go b/webdav/pkg/config/mappings.go index e2637e478..7fa86211e 100644 --- a/webdav/pkg/config/mappings.go +++ b/webdav/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.