From f118357a18472960fb12673b59e8ec1f21f31e85 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 13:18:53 +0100 Subject: [PATCH] graph --- graph/pkg/command/root.go | 19 +++++++++++++++---- graph/pkg/command/server.go | 20 -------------------- graph/pkg/config/config.go | 16 +++------------- graph/pkg/config/mappings.go | 11 +++++++++++ 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 4e07ad4b8..20d07c88e 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -66,7 +66,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) } @@ -78,9 +91,7 @@ type SutureService struct { // NewSutureService creates a new graph.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.Graph.Log == shared.Log{}) { - cfg.Graph.Log = cfg.Log - } + cfg.Graph.Commons = cfg.Commons return SutureService{ cfg: cfg.Graph, } diff --git a/graph/pkg/command/server.go b/graph/pkg/command/server.go index b8a90ecbd..1c4341bcc 100644 --- a/graph/pkg/command/server.go +++ b/graph/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/graph/pkg/config" "github.com/owncloud/ocis/graph/pkg/metrics" @@ -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/graph/pkg/config/config.go b/graph/pkg/config/config.go index c29fcfb2e..57e2b0b80 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -54,8 +54,10 @@ type Spaces struct { // Config combines all available configuration parts. type Config struct { + *shared.Commons + File string `mapstructure:"file"` - Log shared.Log `mapstructure:"log"` + Log *shared.Log `mapstructure:"log"` Debug Debug `mapstructure:"debug"` HTTP HTTP `mapstructure:"http"` Server Server `mapstructure:"server"` @@ -75,7 +77,6 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9124", Token: "", @@ -104,14 +105,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/graph/pkg/config/mappings.go b/graph/pkg/config/mappings.go index a8239f37e..2c74cc9f1 100644 --- a/graph/pkg/config/mappings.go +++ b/graph/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.