-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch all other services to struct tag based env config
- Loading branch information
Showing
115 changed files
with
1,022 additions
and
1,988 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ func Execute(cfg *config.Config) error { | |
Email: "[email protected]", | ||
}, | ||
}, | ||
|
||
Before: func(c *cli.Context) error { | ||
cfg.Service.Version = version.String | ||
return ParseConfig(c, cfg) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,10 +26,12 @@ func Execute(cfg *config.Config) error { | |
Email: "[email protected]", | ||
}, | ||
}, | ||
|
||
Before: func(c *cli.Context) error { | ||
cfg.Service.Version = version.String | ||
return nil | ||
return ParseConfig(c, cfg) | ||
}, | ||
|
||
Commands: []*cli.Command{ | ||
Server(cfg), | ||
Health(cfg), | ||
|
@@ -89,7 +91,7 @@ type SutureService struct { | |
|
||
// NewSutureService creates a new glauth.SutureService | ||
func NewSutureService(cfg *ociscfg.Config) suture.Service { | ||
cfg.GLAuth.Commons = cfg.Commons | ||
//cfg.GLAuth.Commons = cfg.Commons | ||
return SutureService{ | ||
cfg: cfg.GLAuth, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,13 @@ import ( | |
"context" | ||
"os" | ||
|
||
"github.com/imdario/mergo" | ||
"github.com/owncloud/ocis/graph-explorer/pkg/config" | ||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config" | ||
"github.com/owncloud/ocis/ocis-pkg/log" | ||
"github.com/owncloud/ocis/ocis-pkg/version" | ||
"github.com/thejerf/suture/v4" | ||
"github.com/urfave/cli/v2" | ||
"github.com/wkloucek/envdecode" | ||
) | ||
|
||
// Execute is the entry point for the graph-explorer command. | ||
|
@@ -25,10 +26,12 @@ func Execute(cfg *config.Config) error { | |
Email: "[email protected]", | ||
}, | ||
}, | ||
|
||
Before: func(c *cli.Context) error { | ||
cfg.Service.Version = version.String | ||
return ParseConfig(c, cfg) | ||
}, | ||
|
||
Commands: []*cli.Command{ | ||
Server(cfg), | ||
Health(cfg), | ||
|
@@ -46,27 +49,37 @@ func Execute(cfg *config.Config) error { | |
return app.Run(os.Args) | ||
} | ||
|
||
// NewLogger initializes a service-specific logger instance. | ||
func NewLogger(cfg *config.Config) log.Logger { | ||
return log.NewLogger( | ||
log.Name("graph-explorer"), | ||
log.Level(cfg.Log.Level), | ||
log.Pretty(cfg.Log.Pretty), | ||
log.Color(cfg.Log.Color), | ||
log.File(cfg.Log.File), | ||
) | ||
} | ||
|
||
// ParseConfig loads graph configuration from known paths. | ||
func ParseConfig(c *cli.Context, cfg *config.Config) error { | ||
conf, err := ociscfg.BindSourcesToStructs("graph-explorer", cfg) | ||
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
conf.LoadOSEnv(config.GetEnv(), false) | ||
bindings := config.StructMappings(cfg) | ||
return ociscfg.BindEnv(conf, bindings) | ||
// 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. | ||
envCfg := config.Config{} | ||
if err := envdecode.Decode(&envCfg); err != nil && err.Error() != "none of the target fields were set from environment variables" { | ||
return err | ||
} | ||
|
||
// 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-explorer command to be embedded and supervised by a suture supervisor tree. | ||
|
@@ -76,7 +89,7 @@ type SutureService struct { | |
|
||
// NewSutureService creates a new graph-explorer.SutureService | ||
func NewSutureService(cfg *ociscfg.Config) suture.Service { | ||
cfg.GraphExplorer.Log = cfg.Log | ||
//cfg.GraphExplorer.Log = cfg.Log | ||
return SutureService{ | ||
cfg: cfg.GraphExplorer, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.