use crate::opt::GlobalOpts;
use aws_types::region::Region;
pub mod par;
pub mod sec;
pub async fn load_shared_config(opts: &GlobalOpts) -> aws_types::SdkConfig {
let region = Region::new(opts.region.clone());
let mut loader = aws_config::from_env().region(region);
if let Some(profile) = opts.profile.as_deref() {
loader = loader.profile_name(profile);
}
loader.load().await
}
pub fn env_context(opts: &GlobalOpts) -> String {
let mut parts = vec![format!("🌍 {}", opts.region)];
if let Some(profile) = &opts.profile {
parts.push(format!("👤 {profile}"));
}
if let Ok(endpoint) = std::env::var("AWS_ENDPOINT_URL") {
parts.push(format!("🔌 {endpoint}"));
}
parts.join(" ")
}
pub fn show_env(opts: &GlobalOpts) {
let rows: Vec<(&str, String)> = {
let mut v = vec![("Region ", format!("🌍 {}", opts.region))];
if let Some(profile) = &opts.profile {
v.push(("Profile", format!("👤 {profile}")));
}
if let Ok(endpoint) = std::env::var("AWS_ENDPOINT_URL") {
v.push(("Endpoint", format!("🔌 {endpoint}")));
}
v
};
let value_width = rows
.iter()
.map(|(_, v)| v.chars().count())
.max()
.unwrap_or(0);
let label_width = rows
.iter()
.map(|(l, _)| l.chars().count())
.max()
.unwrap_or(0);
let inner_width = 2 + label_width + 2 + 1 + 2 + value_width + 2;
let border = "─".repeat(inner_width);
println!("┌{border}┐");
println!("│{:^inner_width$}│", " AWS Environment ");
println!("├{border}┤");
for (label, value) in &rows {
let line = format!(" {label:<label_width$} : {value} ");
let pad = inner_width.saturating_sub(line.chars().count());
println!("│{line}{:pad$}│", "");
}
println!("└{border}┘");
}