2019-09-26 02:55:47 +00:00
|
|
|
use std::env;
|
|
|
|
|
|
|
|
use super::{Context, Module};
|
|
|
|
|
2019-10-04 12:42:33 +00:00
|
|
|
use crate::config::RootModuleConfig;
|
|
|
|
use crate::configs::aws::AwsConfig;
|
|
|
|
|
2019-09-26 02:55:47 +00:00
|
|
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|
|
|
const AWS_PREFIX: &str = "on ";
|
|
|
|
|
|
|
|
let aws_profile = env::var("AWS_PROFILE").ok()?;
|
|
|
|
if aws_profile.is_empty() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut module = context.new_module("aws");
|
2019-10-04 12:42:33 +00:00
|
|
|
let config: AwsConfig = AwsConfig::try_load(module.config);
|
2019-09-26 02:55:47 +00:00
|
|
|
|
2019-10-04 12:42:33 +00:00
|
|
|
module.set_style(config.style);
|
2019-09-26 02:55:47 +00:00
|
|
|
|
|
|
|
module.get_prefix().set_value(AWS_PREFIX);
|
|
|
|
|
2019-10-04 12:42:33 +00:00
|
|
|
module.create_segment("symbol", &config.symbol);
|
|
|
|
module.create_segment("profile", &config.profile.with_value(&aws_profile));
|
2019-09-26 02:55:47 +00:00
|
|
|
|
|
|
|
Some(module)
|
|
|
|
}
|