Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/aws/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ pub enum AwsAuthentication {
#[configurable(metadata(docs::examples = "develop"))]
#[serde(default = "default_profile")]
profile: String,

/// The [AWS region][aws_region] to send STS requests to.
///
/// If not set, this defaults to the configured region
/// for the service itself.
///
/// [aws_region]: https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints
#[configurable(metadata(docs::examples = "us-west-2"))]
region: Option<String>,
},

/// Assume the given role ARN.
Expand Down Expand Up @@ -244,15 +253,23 @@ impl AwsAuthentication {
AwsAuthentication::File {
credentials_file,
profile,
region,
} => {
// The SDK uses the default profile out of the box, but doesn't provide an optional
// type in the builder. We can just hardcode it so that everything works.
let auth_region = region.clone().map(Region::new).unwrap_or(service_region);
let connector = super::connector(proxy, tls_options)?;
let provider_config = ProviderConfig::empty()
.with_region(Option::from(auth_region))
.with_http_client(connector);

let profile_files = ProfileFiles::builder()
.with_file(ProfileFileKind::Credentials, credentials_file)
.build();
let profile_provider = ProfileFileCredentialsProvider::builder()
.profile_files(profile_files)
.profile_name(profile)
.configure(&provider_config)
.build();
Ok(SharedCredentialsProvider::new(profile_provider))
}
Expand Down Expand Up @@ -616,6 +633,7 @@ mod tests {
r#"
auth.credentials_file = "/path/to/file"
auth.profile = "foo"
auth.region = "us-west-2"
"#,
)
.unwrap();
Expand All @@ -624,9 +642,11 @@ mod tests {
AwsAuthentication::File {
credentials_file,
profile,
region,
} => {
assert_eq!(&credentials_file, "/path/to/file");
assert_eq!(&profile, "foo");
assert_eq!(region.unwrap(), "us-west-2");
}
_ => panic!(),
}
Expand All @@ -642,6 +662,7 @@ mod tests {
AwsAuthentication::File {
credentials_file,
profile,
..
} => {
assert_eq!(&credentials_file, "/path/to/file");
assert_eq!(profile, "default".to_string());
Expand Down