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 region = match region {
        Some(region) => region,
        None => extract("region")?.ok_or_else(|| anyhow!("region is required"))?,
    };

    let endpoint = extract("endpoint")?;

    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) => None,
        (Some(access_key_id), Some(secret_access_key), session_token) => Some(AwsCredentials {
            access_key_id,
            secret_access_key,
            session_token,
        }),
        (Some(_), None, _) => {
            bail!("secret_acccess_key must be specified if access_key_id is specified")
        }
        (None, Some(_), _) => bail!("secret_acccess_key cannot be specified without access_key_id"),
        (None, None, Some(_)) => bail!("token cannot be specified without access_key_id"),
    };

    Ok(AwsConfig {
        credentials,
        region,
        endpoint,
    })
}
/// 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 region = match region {
        Some(region) => region,
        None => extract("region")?.ok_or_else(|| anyhow!("region is required"))?,
    };
    let endpoint = extract("endpoint")?;
    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) => None,
        (Some(access_key_id), Some(secret_access_key), session_token) => Some(AwsCredentials {
            access_key_id,
            secret_access_key,
            session_token,
        }),
        (Some(_), None, _) => {
            bail!("secret_acccess_key must be specified if access_key_id is specified")
        }
        (None, Some(_), _) => bail!("secret_acccess_key cannot be specified without access_key_id"),
        (None, None, Some(_)) => bail!("token cannot be specified without access_key_id"),
    };
    Ok(AwsConfig {
        credentials,
        region,
        endpoint,
    })
}
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 region = match region { Some ( region ) => region , None => extract ( " " ) ? . ok_or_else ( | | anyhow ! ( " " ) ) ? , } ; let endpoint = extract ( " " ) ? ; 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 ) => None , ( Some ( access_key_id ) , Some ( secret_access_key ) , session_token ) => Some ( AwsCredentials { access_key_id , secret_access_key , session_token , } ) , ( Some ( _ ) , None , _ ) => { bail ! ( " " ) } ( None , Some ( _ ) , _ ) => bail ! ( " " ) , ( None , None , Some ( _ ) ) => bail ! ( " " ) , } ; Ok ( AwsConfig { credentials , region , endpoint , } ) }
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>