Skip to content

Commit

Permalink
Override config file path using ONELOGIN_AUTH_CLI_CONFIG_FILE (#7)
Browse files Browse the repository at this point in the history
* feat: override a path to config file #5
  • Loading branch information
Mark authored Mar 20, 2023
1 parent 6c76da1 commit 8bcb7e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ roles:
defaultRegion: us-east-1
```
### Environment Variables (optional)
If you use external password managers, you can use environment variables to automate the login process.
The following environment variables are supported:
- `EMAIL` - email address of the user to login as
- `PASSWORD` - password of the user to login as
- `OTP` - One Time Password (if MFA is enabled)

If you prefere to specify the path to the config file, you can use the `ONELOGIN_AUTH_CLI_CONFIG_FILE` environment variable.

### Login

```
Expand Down
12 changes: 9 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"log"
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -65,9 +66,14 @@ func init() {
}

func LoadConfig(path string) (config Config, err error) {
viper.AddConfigPath(path)
viper.SetConfigName("config")
viper.SetConfigType("yaml")
userDefinedConfigFile := os.Getenv("ONELOGIN_AUTH_CLI_CONFIG_FILE")
if userDefinedConfigFile != "" {
viper.SetConfigFile(userDefinedConfigFile)
} else {
viper.AddConfigPath(path)
viper.SetConfigName("config")
viper.SetConfigType("yaml")
}

viper.AutomaticEnv()

Expand Down

0 comments on commit 8bcb7e5

Please sign in to comment.