normalize idp

This commit is contained in:
A.Unger
2021-11-08 12:17:23 +01:00
parent 22601de351
commit a515a97c8f
10 changed files with 58 additions and 224 deletions
+3 -20
View File
@@ -71,11 +71,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
}
return nil
bindings := config.StructMappings(cfg)
return ociscfg.BindEnv(conf, bindings)
}
// SutureService allows for the idp command to be embedded and supervised by a suture supervisor tree.
@@ -85,11 +82,7 @@ type SutureService struct {
// NewSutureService creates a new idp.SutureService
func NewSutureService(cfg *ociscfg.Config) suture.Service {
inheritLogging(cfg)
if cfg.Mode == 0 {
cfg.IDP.Supervised = true
}
cfg.IDP.Log.File = cfg.Log.File
cfg.IDP.Log = cfg.Log
return SutureService{
cfg: cfg.IDP,
}
@@ -103,13 +96,3 @@ func (s SutureService) Serve(ctx context.Context) error {
return nil
}
// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging
// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults,
// being overwritten when the extension parses its config file / env variables.
func inheritLogging(cfg *ociscfg.Config) {
cfg.IDP.Log.File = cfg.Log.File
cfg.IDP.Log.Color = cfg.Log.Color
cfg.IDP.Log.Pretty = cfg.Log.Pretty
cfg.IDP.Log.Level = cfg.Log.Level
}
+12 -17
View File
@@ -24,24 +24,19 @@ func Server(cfg *config.Config) *cli.Command {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
// StringSliceFlag doesn't support Destination
// UPDATE Destination on string flags supported. Wait for https://github.com/urfave/cli/pull/1078 to get to micro/cli
if len(ctx.StringSlice("trusted-proxy")) > 0 {
cfg.IDP.TrustedProxy = ctx.StringSlice("trusted-proxy")
}
//if len(ctx.StringSlice("trusted-proxy")) > 0 {
// cfg.IDP.TrustedProxy = ctx.StringSlice("trusted-proxy")
//}
//
//if len(ctx.StringSlice("allow-scope")) > 0 {
// cfg.IDP.AllowScope = ctx.StringSlice("allow-scope")
//}
//
//if len(ctx.StringSlice("signing-private-key")) > 0 {
// cfg.IDP.SigningPrivateKeyFiles = ctx.StringSlice("signing-private-key")
//}
if len(ctx.StringSlice("allow-scope")) > 0 {
cfg.IDP.AllowScope = ctx.StringSlice("allow-scope")
}
if len(ctx.StringSlice("signing-private-key")) > 0 {
cfg.IDP.SigningPrivateKeyFiles = ctx.StringSlice("signing-private-key")
}
if err := ParseConfig(ctx, cfg); err != nil {
return err
}
return nil
return ParseConfig(ctx, cfg)
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)