Skip to content

Instantly share code, notes, and snippets.

@offbyone
Created November 13, 2022 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save offbyone/2c48706be64ae4fd82f84b06d6467b65 to your computer and use it in GitHub Desktop.
Save offbyone/2c48706be64ae4fd82f84b06d6467b65 to your computer and use it in GitHub Desktop.
fn get_profile_or_default(aws_profile: Option<Profile>) -> Profile {
match aws_profile {
Some(p) => p.clone(),
None => "default".to_string() as Profile,
}
}
fn has_credential_process_or_sso(
context: &Context,
aws_profile: &Option<Profile>,
aws_config: &AwsConfigFile,
aws_creds: &AwsCredsFile,
) -> Option<bool> {
let config = get_config(context, aws_config)?;
let credentials = get_creds(context, aws_creds)?;
let empty_section = ini::Properties::new();
let credential_profile = Some(get_profile_or_default(*aws_profile));
let config_section =
get_profile_config(config, &credential_profile).or_else(|| Some(&empty_section))?;
let credential_section = credentials
.section(credential_profile)
.or_else(|| Some(&empty_section))?;
Some(
config_section.contains_key("credential_process")
|| config_section.contains_key("sso_start_url")
|| credential_section.contains_key("credential_process")
|| credential_section.contains_key("sso_start_url"),
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment