pub fn aws_config(
    options: &mut BTreeMap<String, Value>,
    region: Option<String>,
) -> Result<AwsConfig, anyhow::Error> {
    let mut extract = |key| match options.remove(key) {
        Some(Value::String(key)) => {
            if !key.is_empty() {
                Ok(Some(key))
            } else {
                Ok(None)
            }
        }
        Some(_) => bail!("{} must be a string", key),
        _ => Ok(None),
    };

    let credentials = match extract("profile")? {
        Some(profile_name) => {
            for name in &["access_key_id", "secret_access_key", "token"] {
                let extracted = extract(name);
                if matches!(extracted, Ok(Some(_)) | Err(_)) {
                    bail!(
                        "AWS profile cannot be set in combination with '{0}', \
                         configure '{0}' inside the profile file",
                        name
                    );
                }
            }
            AwsCredentials::Profile { profile_name }
        }
        None => {
            let access_key_id = extract("access_key_id")?;
            let secret_access_key = extract("secret_access_key")?;
            let session_token = extract("token")?;
            let credentials = match (access_key_id, secret_access_key, session_token) {
                (None, None, None) => AwsCredentials::Default,
                (Some(access_key_id), Some(secret_access_key), session_token) => {
                    AwsCredentials::Static {
                        access_key_id,
                        secret_access_key,
                        session_token,
                    }
                }
                (Some(_), None, _) => {
                    bail!("secret_access_key must be specified if access_key_id is specified")
                }
                (None, Some(_), _) => {
                    bail!("secret_access_key cannot be specified without access_key_id")
                }
                (None, None, Some(_)) => bail!("token cannot be specified without access_key_id"),
            };

            credentials
        }
    };

    let region = match region {
        Some(region) => Some(region),
        None => extract("region")?,
    };
    let endpoint = match extract("endpoint")? {
        None => None,
        Some(endpoint) => Some(SerdeUri(endpoint.parse().context("parsing AWS endpoint")?)),
    };
    let arn = extract("role_arn")?;
    Ok(AwsConfig {
        credentials,
        region,
        endpoint,
        role: arn.map(|arn| AwsAssumeRole { arn }),
    })
}
/// Normalizes option values that contain AWS connection parameters.
Normalizes option values that contain AWS connection parameters.
Normalizes option values that contain AWS connection parameters .
pub fn aws_config(
    options: &mut BTreeMap<String, Value>,
    region: Option<String>,
) -> Result<AwsConfig, anyhow::Error> {
    let mut extract = |key| match options.remove(key) {
        Some(Value::String(key)) => {
            if !key.is_empty() {
                Ok(Some(key))
            } else {
                Ok(None)
            }
        }
        Some(_) => bail!("{} must be a string", key),
        _ => Ok(None),
    };
    let credentials = match extract("profile")? {
        Some(profile_name) => {
            for name in &["access_key_id", "secret_access_key", "token"] {
                let extracted = extract(name);
                if matches!(extracted, Ok(Some(_)) | Err(_)) {
                    bail!(
                        "AWS profile cannot be set in combination with '{0}', \
                         configure '{0}' inside the profile file",
                        name
                    );
                }
            }
            AwsCredentials::Profile { profile_name }
        }
        None => {
            let access_key_id = extract("access_key_id")?;
            let secret_access_key = extract("secret_access_key")?;
            let session_token = extract("token")?;
            let credentials = match (access_key_id, secret_access_key, session_token) {
                (None, None, None) => AwsCredentials::Default,
                (Some(access_key_id), Some(secret_access_key), session_token) => {
                    AwsCredentials::Static {
                        access_key_id,
                        secret_access_key,
                        session_token,
                    }
                }
                (Some(_), None, _) => {
                    bail!("secret_access_key must be specified if access_key_id is specified")
                }
                (None, Some(_), _) => {
                    bail!("secret_access_key cannot be specified without access_key_id")
                }
                (None, None, Some(_)) => bail!("token cannot be specified without access_key_id"),
            };
            credentials
        }
    };
    let region = match region {
        Some(region) => Some(region),
        None => extract("region")?,
    };
    let endpoint = match extract("endpoint")? {
        None => None,
        Some(endpoint) => Some(SerdeUri(endpoint.parse().context("parsing AWS endpoint")?)),
    };
    let arn = extract("role_arn")?;
    Ok(AwsConfig {
        credentials,
        region,
        endpoint,
        role: arn.map(|arn| AwsAssumeRole { arn }),
    })
}
pub fn aws_config ( options : & mut BTreeMap < String , Value > , region : Option < String > , ) -> Result < AwsConfig , anyhow :: Error > { let mut extract = | key | match options . remove ( key ) { Some ( Value :: String ( key ) ) => { if ! key . is_empty ( ) { Ok ( Some ( key ) ) } else { Ok ( None ) } } Some ( _ ) => bail ! ( " " key ) , _ => Ok ( None ) , } ; let credentials = match extract ( " " ) ? { Some ( profile_name ) => { for name in & [ " " , " " , " " ] { let extracted = extract ( name ) ; if matches ! ( extracted Ok ( Some ( ) ) Err ( ) ) { bail ! ( " \
 " name ) ; } } AwsCredentials :: Profile { profile_name } } None => { let access_key_id = extract ( " " ) ? ; let secret_access_key = extract ( " " ) ? ; let session_token = extract ( " " ) ? ; let credentials = match ( access_key_id , secret_access_key , session_token ) { ( None , None , None ) => AwsCredentials :: Default , ( Some ( access_key_id ) , Some ( secret_access_key ) , session_token ) => { AwsCredentials :: Static { access_key_id , secret_access_key , session_token , } } ( Some ( _ ) , None , _ ) => { bail ! ( " " ) } ( None , Some ( _ ) , _ ) => { bail ! ( " " ) } ( None , None , Some ( _ ) ) => bail ! ( " " ) , } ; credentials } } ; let region = match region { Some ( region ) => Some ( region ) , None => extract ( " " ) ? , } ; let endpoint = match extract ( " " ) ? { None => None , Some ( endpoint ) => Some ( SerdeUri ( endpoint . parse ( ) . context ( " " ) ? ) ) , } ; let arn = extract ( " " ) ? ; Ok ( AwsConfig { credentials , region , endpoint , role : arn . map ( | arn | AwsAssumeRole { arn } ) , } ) }
Normalizes option values that contain AWS connection parameters.
Normalizes option values that contain AWS connection parameters .
options
&mut BTreeMap<String, Value>
region
Option<String>
options
&mut BTreeMap<String, Value>
region
Option<String>