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

Promote AWS_REGION from .env if it exists for proper AWS API behavior. #85

Merged
merged 1 commit into from
Mar 15, 2023
Merged
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ Also see the CLI's online help `$ okta-aws-cli --help`
| Emit deprecated AWS variable `aws_security_token` with duplicated value from `aws_session_token` | `LEGACY_AWS_VARIABLES=true` | `--legacy-aws-variables` | `true` if flag is present |
| Verbosely print all API calls/responses to the screen | `DEBUG_API_CALLS=true` | `--debug-api-calls` | `true` if flag is present |

NOTE: If
[`AWS_REGION`](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html)
is set in the `.env` file it will be promoted into the okta-aws-cli runtime if
it isn't also already set as an ENV VAR. This will allow operators making use of
an `.env` file have to have proper AWS API behavior in spefific regions, for
instance in US govcloud and other non-North America regions.

### Allowed Web SSO Client

This is the "Allowed Web SSO Client" value from the "Sign On" settings of an
Expand Down
10 changes: 10 additions & 0 deletions cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -185,6 +186,15 @@ to collect a proper IAM role for the AWS CLI operator.`,
viper.SetConfigType("dotenv")

_ = viper.ReadInConfig()

// After viper reads in the dotenv file check if AWS_REGION is set
// there. The value will be keyed by lower case name. If it is, set
// AWS_REGION as an ENV VAR if it hasn't already been.
awsRegionEnvVar := "AWS_REGION"
vipAwsRegion := viper.GetString(strings.ToLower(awsRegionEnvVar))
if vipAwsRegion != "" && os.Getenv(awsRegionEnvVar) == "" {
_ = os.Setenv(awsRegionEnvVar, vipAwsRegion)
}
}
viper.AutomaticEnv()

Expand Down