diff --git a/glauth/pkg/config/mappings.go b/glauth/pkg/config/mappings.go index 7d2a1393d2..c1af621315 100644 --- a/glauth/pkg/config/mappings.go +++ b/glauth/pkg/config/mappings.go @@ -2,11 +2,6 @@ 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. diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 606d768788..11cfdabb72 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -20,30 +20,25 @@ func Execute(cfg *config.Config) error { Version: version.String, Usage: "Serve Graph API for oCIS", Compiled: version.Compiled(), - Authors: []*cli.Author{ { Name: "ownCloud GmbH", Email: "support@owncloud.com", }, }, - Before: func(c *cli.Context) error { cfg.Server.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ Server(cfg), Health(cfg), }, } - cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ Name: "version,v", Usage: "Print the version", @@ -73,9 +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 - } + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) return nil } @@ -87,10 +81,7 @@ type SutureService struct { // NewSutureService creates a new graph.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Graph.Supervised = true - } - cfg.Graph.Log.File = cfg.Log.File + cfg.Graph.Log = cfg.Log return SutureService{ cfg: cfg.Graph, } diff --git a/graph/pkg/command/server.go b/graph/pkg/command/server.go index cf4b638127..36daa2daa7 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -24,10 +24,7 @@ func Server(cfg *config.Config) *cli.Command { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - return nil + return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index c59d69dcb0..3d35692c7e 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -6,6 +6,7 @@ import ( "reflect" gofig "github.com/gookit/config/v2" + "github.com/owncloud/ocis/ocis-pkg/shared" ) // Log defines the available logging configuration. @@ -65,7 +66,7 @@ type Spaces struct { // Config combines all available configuration parts. type Config struct { File string `mapstructure:"file"` - Log Log `mapstructure:"log"` + Log shared.Log `mapstructure:"log"` Debug Debug `mapstructure:"debug"` HTTP HTTP `mapstructure:"http"` Server Server `mapstructure:"server"` @@ -85,7 +86,7 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: Log{}, + Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9124", Token: "", diff --git a/graph/pkg/config/env.go b/graph/pkg/config/mappings.go similarity index 82% rename from graph/pkg/config/env.go rename to graph/pkg/config/mappings.go index 2f22b33d2b..d32b519aa7 100644 --- a/graph/pkg/config/env.go +++ b/graph/pkg/config/mappings.go @@ -1,13 +1,17 @@ package config -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. +import "github.com/owncloud/ocis/ocis-pkg/shared" + +// 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{"GRAPH_CONFIG_FILE"}, Destination: &cfg.File,