From 226a821f958a8e71bc6a2104fc858157e554ca91 Mon Sep 17 00:00:00 2001 From: ConnorWidtfeldt Date: Wed, 31 May 2023 11:20:19 -0600 Subject: [PATCH 1/2] try to read config file from working directory --- .generator/templates/configuration.mustache | 9 +++++++++ okta/okta.go | 9 +++++++++ openapi/generator/templates/okta.go.hbs | 11 ++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) 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/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) From eebf53ca5c01fe38cacaca6f8a353a06c14bc463 Mon Sep 17 00:00:00 2001 From: ConnorWidtfeldt Date: Wed, 31 May 2023 11:44:39 -0600 Subject: [PATCH 2/2] update readme to mention reading .okta.yaml from working directory --- README.md | 1 + 1 file changed, 1 insertion(+) 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