switch ocs to struct tag based env config
This commit is contained in:
+23
-16
@@ -4,14 +4,14 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/ocis-pkg/version"
|
||||
"github.com/owncloud/ocis/ocs/pkg/config"
|
||||
"github.com/thejerf/suture/v4"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/wkloucek/envdecode"
|
||||
)
|
||||
|
||||
// Execute is the entry point for the ocis-ocs command.
|
||||
@@ -67,28 +67,35 @@ func NewLogger(cfg *config.Config) log.Logger {
|
||||
|
||||
// ParseConfig loads idp configuration from known paths.
|
||||
func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
||||
conf, err := ociscfg.BindSourcesToStructs("ocs", cfg)
|
||||
_, err := ociscfg.BindSourcesToStructs("ocs", cfg)
|
||||
if err != nil {
|
||||
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{}
|
||||
}
|
||||
//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(cfg), false)
|
||||
envCfg := config.Config{}
|
||||
if err := envdecode.Decode(&envCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bindings := config.StructMappings(cfg)
|
||||
return ociscfg.BindEnv(conf, bindings)
|
||||
// merge environment variable config on top of the current config
|
||||
if err := mergo.Merge(cfg, envCfg, mergo.WithOverride); err != nil && err.Error() != "none of the target fields were set from environment variables" {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SutureService allows for the ocs command to be embedded and supervised by a suture supervisor tree.
|
||||
|
||||
Reference in New Issue
Block a user