diff --git a/.generator/templates/configuration.mustache b/.generator/templates/configuration.mustache index 5b9c656e1..1a3afdf67 100644 --- a/.generator/templates/configuration.mustache +++ b/.generator/templates/configuration.mustache @@ -250,6 +250,7 @@ func NewConfiguration(conf ...ConfigSetter) *Configuration { cfg.Okta.Client.AuthorizationMode = "SSWS" cfg = readConfigFromSystem(*cfg) + cfg = readConfigFromWorkingDirectory(*cfg) cfg = readConfigFromApplication(*cfg) cfg = readConfigFromEnvironment(*cfg) @@ -308,6 +309,14 @@ func readConfigFromSystem(c Configuration) *Configuration { return conf } +func readConfigFromWorkingDirectory(c config) *config { + conf, err := readConfigFromFile(".okta.yaml", c) + if err != nil { + return &c + } + return conf +} + // read config from the project's root directory func readConfigFromApplication(c Configuration) *Configuration { _, b, _, _ := runtime.Caller(0) diff --git a/README.md b/README.md index 098a65a07..2a25d612a 100644 --- a/README.md +++ b/README.md @@ -770,6 +770,7 @@ This library looks for configuration in the following sources: 0. An `okta.yaml` file in a `.okta` folder in the current user's home directory (`~/.okta/okta.yaml` or `%userprofile\.okta\okta.yaml`) +0. A `.okta.yaml` file in the current working directory 0. A `.okta.yaml` file in the application or project's root directory 0. Environment variables 0. Configuration explicitly passed to the constructor (see the example in diff --git a/okta/okta.go b/okta/okta.go index f1d40a9aa..31e21d989 100644 --- a/okta/okta.go +++ b/okta/okta.go @@ -77,6 +77,7 @@ func NewClient(ctx context.Context, conf ...ConfigSetter) (context.Context, *Cli setConfigDefaults(config) config = readConfigFromSystem(*config) + config = readConfigFromWorkingDirectory(*config) config = readConfigFromApplication(*config) config = readConfigFromEnvironment(*config) @@ -220,6 +221,14 @@ func readConfigFromSystem(c config) *config { return conf } +func readConfigFromWorkingDirectory(c config) *config { + conf, err := readConfigFromFile(".okta.yaml", c) + if err != nil { + return &c + } + return conf +} + // read config from the project's root directory func readConfigFromApplication(c config) *config { _, b, _, _ := runtime.Caller(0) diff --git a/openapi/generator/templates/okta.go.hbs b/openapi/generator/templates/okta.go.hbs index 3eed1ea6a..5427b2f5f 100644 --- a/openapi/generator/templates/okta.go.hbs +++ b/openapi/generator/templates/okta.go.hbs @@ -36,6 +36,7 @@ func NewClient(ctx context.Context, conf ...ConfigSetter) (context.Context, *Cli setConfigDefaults(config) config = readConfigFromSystem(*config) + config = readConfigFromWorkingDirectory(*config) config = readConfigFromApplication(*config) config = readConfigFromEnvironment(*config) @@ -94,7 +95,7 @@ func (c *Client) SetConfig(conf ...ConfigSetter) (err error) { return } c.config = config - return + return } // GetRequestExecutor returns underlying request executor @@ -154,6 +155,14 @@ func readConfigFromSystem(c config) *config { return conf } +func readConfigFromWorkingDirectory(c config) *config { + conf, err := readConfigFromFile(".okta.yaml", c) + if err != nil { + return &c + } + return conf +} + // read config from the project's root directory func readConfigFromApplication(c config) *config { _, b, _, _ := runtime.Caller(0)