summaryrefslogtreecommitdiffstats
path: root/src/modules/aws.rs
diff options
context:
space:
mode:
authorMike Sampson <mike@sambodata.com>2019-12-21 04:30:47 +1100
committerMatan Kushner <hello@matchai.me>2019-12-20 12:30:47 -0500
commit256a2be949288b6c0d9f5d02b09d78b245c992d1 (patch)
tree3989ca58395fe1a9a915aeec7bc6ec041cc676ef /src/modules/aws.rs
parentf3784f5aaa08281bd36c0891c6b29673c93ef929 (diff)
feat: Implement AWS region aliases (#646)
Diffstat (limited to 'src/modules/aws.rs')
-rw-r--r--src/modules/aws.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/modules/aws.rs b/src/modules/aws.rs
index ceb36c85c..c6fc8e92a 100644
--- a/src/modules/aws.rs
+++ b/src/modules/aws.rs
@@ -1,3 +1,4 @@
+use std::collections::HashMap;
use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader};
@@ -76,6 +77,13 @@ fn get_aws_region() -> Option<Region> {
}
}
+fn alias_region(region: &str, aliases: &HashMap<String, &str>) -> String {
+ match aliases.get(region) {
+ None => region.to_string(),
+ Some(alias) => alias.to_string(),
+ }
+}
+
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
const AWS_PREFIX: &str = "on ";
@@ -93,9 +101,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let aws_segment = match (&aws_profile, &aws_region) {
(None, None) => return None,
- (Some(p), Some(r)) => format!("{}({})", p, r),
+ (Some(p), Some(r)) => format!("{}({})", p, alias_region(r, &config.region_aliases)),
(Some(p), None) => p.to_string(),
- (None, Some(r)) => r.to_string(),
+ (None, Some(r)) => alias_region(r, &config.region_aliases),
};
module.create_segment("all", &config.region.with_value(&aws_segment));
}
@@ -105,7 +113,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
module.create_segment("profile", &config.profile.with_value(&aws_profile));
}
AwsItems::Region => {
- let aws_region = get_aws_region()?;
+ let aws_region = alias_region(&get_aws_region()?, &config.region_aliases);
module.create_segment("region", &config.region.with_value(&aws_region));
}