fix(aws): Make AWS_REGION orverrides AWS_DEFAULT_REGION (#3619) (#3733)

* fix(aws): Make AWS_REGION orverrides AWS_DEFAULT_REGION (#3619)

* fix(aws): Align the coding style of region and profile env var (#3619)
This commit is contained in:
kuno 2022-03-15 05:49:23 +08:00 committed by GitHub
parent 848bf693a4
commit 59622bc41b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,12 +64,13 @@ fn get_aws_region_from_config(context: &Context, aws_profile: Option<&str>) -> O
fn get_aws_profile_and_region(context: &Context) -> (Option<Profile>, Option<Region>) { fn get_aws_profile_and_region(context: &Context) -> (Option<Profile>, Option<Region>) {
let profile_env_vars = vec!["AWSU_PROFILE", "AWS_VAULT", "AWSUME_PROFILE", "AWS_PROFILE"]; let profile_env_vars = vec!["AWSU_PROFILE", "AWS_VAULT", "AWSUME_PROFILE", "AWS_PROFILE"];
let region_env_vars = vec!["AWS_REGION", "AWS_DEFAULT_REGION"];
let profile = profile_env_vars let profile = profile_env_vars
.iter() .iter()
.find_map(|env_var| context.get_env(env_var)); .find_map(|env_var| context.get_env(env_var));
let region = context let region = region_env_vars
.get_env("AWS_DEFAULT_REGION") .iter()
.or_else(|| context.get_env("AWS_REGION")); .find_map(|env_var| context.get_env(env_var));
match (profile, region) { match (profile, region) {
(Some(p), Some(r)) => (Some(p), Some(r)), (Some(p), Some(r)) => (Some(p), Some(r)),
(None, Some(r)) => (None, Some(r)), (None, Some(r)) => (None, Some(r)),
@ -285,7 +286,7 @@ mod tests {
.collect(); .collect();
let expected = Some(format!( let expected = Some(format!(
"on {}", "on {}",
Color::Yellow.bold().paint("☁️ (ap-northeast-1) ") Color::Yellow.bold().paint("☁️ (ap-northeast-2) ")
)); ));
assert_eq!(expected, actual); assert_eq!(expected, actual);