Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to read .okta.yaml config file from working directory #382

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .generator/templates/configuration.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions okta/okta.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion openapi/generator/templates/okta.go.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -94,7 +95,7 @@ func (c *Client) SetConfig(conf ...ConfigSetter) (err error) {
return
}
c.config = config
return
return
}

// GetRequestExecutor returns underlying request executor
Expand Down Expand Up @@ -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)
Expand Down