mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-28 06:49:49 -05:00
switch graph to struct tag based env config
This commit is contained in:
+24
-15
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/thejerf/suture/v4"
|
||||
"github.com/wkloucek/envdecode"
|
||||
|
||||
"github.com/owncloud/ocis/graph/pkg/config"
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
@@ -62,26 +62,35 @@ func NewLogger(cfg *config.Config) log.Logger {
|
||||
|
||||
// ParseConfig loads graph configuration from known paths.
|
||||
func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
||||
conf, err := ociscfg.BindSourcesToStructs("graph", cfg)
|
||||
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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.
|
||||
envCfg := config.Config{}
|
||||
if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" {
|
||||
return err
|
||||
}
|
||||
|
||||
conf.LoadOSEnv(config.GetEnv(cfg), false)
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SutureService allows for the graph command to be embedded and supervised by a suture supervisor tree.
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/oklog/run"
|
||||
"github.com/owncloud/ocis/graph/pkg/config"
|
||||
"github.com/owncloud/ocis/graph/pkg/logging"
|
||||
"github.com/owncloud/ocis/graph/pkg/metrics"
|
||||
"github.com/owncloud/ocis/graph/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/graph/pkg/server/http"
|
||||
@@ -30,9 +31,9 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
|
||||
if err := tracing.Configure(cfg); err != nil {
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
err := tracing.Configure(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user