Skip to content

Commit

Permalink
Use http client when building assume role for AccessKey.
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Wakely <[email protected]>
  • Loading branch information
StephenWakely committed Apr 11, 2024
1 parent 665ab39 commit 8ce5d4d
Showing 1 changed file with 41 additions and 20 deletions.
61 changes: 41 additions & 20 deletions src/aws/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,33 @@ impl AwsAuthentication {
}
}

/// Create the AssumeRoleProviderBuilder, ensuring we create the HTTP client with
/// the correct proxy and TLS options.
fn assume_role_provider_builder(
proxy: &ProxyConfig,
tls_options: &Option<TlsConfig>,
region: &Region,
assume_role: &str,
external_id: Option<&str>,
) -> crate::Result<AssumeRoleProviderBuilder> {
let connector = super::connector(proxy, tls_options)?;
let config = SdkConfig::builder()
.http_client(connector)
.region(region.clone())
.time_source(SystemTimeSource::new())
.build();

let mut builder = AssumeRoleProviderBuilder::new(assume_role)
.region(region.clone())
.configure(&config);

if let Some(external_id) = external_id {
builder = builder.external_id(external_id)
}

Ok(builder)
}

/// Returns the provider for the credentials based on the authentication mechanism chosen.
pub async fn credentials_provider(
&self,
Expand All @@ -228,12 +255,13 @@ impl AwsAuthentication {
));
if let Some(assume_role) = assume_role {
let auth_region = region.clone().map(Region::new).unwrap_or(service_region);
let mut builder =
AssumeRoleProviderBuilder::new(assume_role).region(auth_region);

if let Some(external_id) = external_id {
builder = builder.external_id(external_id)
}
let builder = Self::assume_role_provider_builder(
proxy,
tls_options,
&auth_region,
assume_role,
external_id.as_deref(),
)?;

let provider = builder.build_from_provider(provider).await;

Expand Down Expand Up @@ -264,20 +292,13 @@ impl AwsAuthentication {
..
} => {
let auth_region = region.clone().map(Region::new).unwrap_or(service_region);
let connector = super::connector(proxy, tls_options)?;
let config = SdkConfig::builder()
.http_client(connector)
.region(auth_region.clone())
.time_source(SystemTimeSource::new())
.build();

let mut builder = AssumeRoleProviderBuilder::new(assume_role)
.region(auth_region.clone())
.configure(&config);

if let Some(external_id) = external_id {
builder = builder.external_id(external_id)
}
let builder = Self::assume_role_provider_builder(
proxy,
tls_options,
&auth_region,
assume_role,
external_id.as_deref(),
)?;

let provider = builder
.build_from_provider(
Expand Down

0 comments on commit 8ce5d4d

Please sign in to comment.