Skip to content

Commit

Permalink
Change env var naming for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
atainter committed Jul 29, 2024
1 parent df00ad7 commit 502ff12
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ workos [cmd] [args]
### Environment Variables
WorkOS CLI support environment variables for initialization and environment management.

| Environment Variable | Description | Supported Values |
|-----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
| WORKOS_ACTIVE_ENVIRONMENT | Sets the selected environment in your .workos.json file. Use `env` to override environment configs with other environment variable overrides. | |
| WORKOS_ENVIRONMENTS_ENV_NAME | Sets the name of the environment | |
| WORKOS_ENVIRONMENTS_ENV_ENDPOINT | Sets the base endpoint for the environment | |
| WORKOS_ENVIRONMENTS_ENV_API_KEY | Sets the API key for the environment | |
| WORKOS_ENVIRONMENTS_ENV_TYPE | Sets the env type for the environment | Production / Sandbox |
| Environment Variable | Description | Supported Values |
|---------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
| WORKOS_ACTIVE_ENVIRONMENT | Sets the selected environment in your .workos.json file. Use `headless` to override environment configs with other environment variable overrides. | |
| WORKOS_ENVIRONMENTS_HEADLESS_NAME | Sets the name of the environment | |
| WORKOS_ENVIRONMENTS_HEADLESS_ENDPOINT | Sets the base endpoint for the environment | |
| WORKOS_ENVIRONMENTS_HEADLESS_API_KEY | Sets the API key for the environment | |
| WORKOS_ENVIRONMENTS_HEADLESS_TYPE | Sets the env type for the environment | Production / Sandbox |

#### Examples

Expand All @@ -86,9 +86,9 @@ export WORKOS_ACTIVE_ENVIRONMENT=local
##### Headless Mode

```shell
export WORKOS_ACTIVE_ENVIRONMENT=env
export WORKOS_ENVIRONMENTS_ENV_NAME=local
export WORKOS_ENVIRONMENTS_ENV_ENDPOINT=http://localhost:8001
export WORKOS_ENVIRONMENTS_ENV_API_KEY=<YOUR_KEY>
export WORKOS_ENVIRONMENTS_ENV_TYPE=Sandbox
export WORKOS_ACTIVE_ENVIRONMENT=headless
export WORKOS_ENVIRONMENTS_HEADLESS_NAME=local
export WORKOS_ENVIRONMENTS_HEADLESS_ENDPOINT=http://localhost:8001
export WORKOS_ENVIRONMENTS_HEADLESS_API_KEY=<YOUR_KEY>
export WORKOS_ENVIRONMENTS_HEADLESS_TYPE=Sandbox
```
12 changes: 6 additions & 6 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

const (
EnvVarPrefix = "WORKOS"
EnvVarHeadlessMode = "env"
EnvVarHeadlessMode = "headless"
FilePrefix = ".workos"
FileExtension = "json"
FileName = FilePrefix + "." + FileExtension
Expand Down Expand Up @@ -58,7 +58,7 @@ func createEmptyConfigFile(dir string) {

// Loads config values from environment variables if active environment is set to headless mode
// Supports overriding nested json keys with environment variables
// e.g. environments.env.endpoint -> WORKOS_ENVIRONMENTS_ENV_ENDPOINT
// e.g. environments.headless.endpoint -> WORKOS_ENVIRONMENTS_HEADLESS_ENDPOINT
func loadEnvVarOverrides() {
viper.SetEnvPrefix(EnvVarPrefix)
// replace '.' in env var names with '_' to support overriding nested json keys
Expand All @@ -71,10 +71,10 @@ func loadEnvVarOverrides() {

// Binds environment variables to nested json keys which allows unmarshalling into struct
if activeEnvironment == EnvVarHeadlessMode {
_ = viper.BindEnv("environments.env.endpoint")
_ = viper.BindEnv("environments.env.type")
_ = viper.BindEnv("environments.env.name")
_ = viper.BindEnv("environments.env.api_key")
_ = viper.BindEnv("environments.headless.endpoint")
_ = viper.BindEnv("environments.headless.type")
_ = viper.BindEnv("environments.headless.name")
_ = viper.BindEnv("environments.headless.api_key")
}
}

Expand Down

0 comments on commit 502ff12

Please sign in to comment.