Skip to content

Commit

Permalink
FS-1101; bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeschuurmans committed Feb 15, 2024
1 parent d866144 commit b99f6d6
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions internal/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ type ConfigOIDC struct {

func LoadConfig(path string) (*Configuration, error) {
cfg := &Configuration{}
v := viper.New()
v.SetEnvPrefix(appName)
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
v.AutomaticEnv()

h, err := openConfig(path)
if err != nil {
return cfg, err
Expand All @@ -77,11 +72,6 @@ func LoadConfig(path string) (*Configuration, error) {
return cfg, err
}

err = loadEnvOverrides(cfg, v)
if err != nil {
return cfg, err
}

err = validateClientParams(cfg)
if err != nil {
return nil, err
Expand All @@ -91,14 +81,18 @@ func LoadConfig(path string) (*Configuration, error) {
}

func loadEnvOverrides(cfg *Configuration, v *viper.Viper) error {
cfg.FdbCfg.ClientSecret = v.GetString("fleetdb.oidc.client.secret")
if cfg.FdbCfg.ClientSecret == "" {
return errors.New("FLEET_SCHEDULER_FLEETDB_OIDC_CLIENT_SECRET was empty")
if !cfg.FdbCfg.DisableOAuth {
cfg.FdbCfg.ClientSecret = v.GetString("fleetdb.oidc.client.secret")
if cfg.FdbCfg.ClientSecret == "" {
return errors.New("FLEET_SCHEDULER_FLEETDB_OIDC_CLIENT_SECRET was empty")
}
}

cfg.CoCfg.ClientSecret = v.GetString("conditionorc.oidc.client.secret")
if cfg.FdbCfg.ClientSecret == "" {
return errors.New("FLEET_SCHEDULER_CONDITIONORC_OIDC_CLIENT_SECRET was empty")
if !cfg.CoCfg.DisableOAuth {
cfg.CoCfg.ClientSecret = v.GetString("conditionorc.oidc.client.secret")
if cfg.FdbCfg.ClientSecret == "" {
return errors.New("FLEET_SCHEDULER_CONDITIONORC_OIDC_CLIENT_SECRET was empty")
}
}

return nil
Expand Down Expand Up @@ -133,6 +127,15 @@ func validateClientParams(cfg *Configuration) error {
return err
}

v := viper.New()
v.SetEnvPrefix(appName)
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
v.AutomaticEnv()
err = loadEnvOverrides(cfg, v)
if err != nil {
return err
}

return nil
}

Expand Down

0 comments on commit b99f6d6

Please sign in to comment.