Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ci): Fix merge conflict for AWS auth changes #12344

Merged
merged 2 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
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
27 changes: 11 additions & 16 deletions src/aws/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub enum AwsAuthentication {
impl AwsAuthentication {
pub async fn credentials_provider(
&self,
region: Option<Region>,
region: Region,
) -> crate::Result<SharedCredentialsProvider> {
match self {
Self::Static {
Expand All @@ -47,15 +47,11 @@ impl AwsAuthentication {
Err("Overriding the credentials file is not supported.".into())
}
AwsAuthentication::Role { assume_role } => {
let mut credentials = AssumeRoleProviderBuilder::new(assume_role);
let provider = AssumeRoleProviderBuilder::new(assume_role)
.region(region.clone())
.build(default_credentials_provider(region).await);

if let Some(ref region) = region {
credentials = credentials.region(region.clone())
}

Ok(SharedCredentialsProvider::new(
credentials.build(default_credentials_provider(region).await),
))
Ok(SharedCredentialsProvider::new(provider))
}
AwsAuthentication::Default {} => Ok(SharedCredentialsProvider::new(
default_credentials_provider(region).await,
Expand All @@ -72,14 +68,13 @@ impl AwsAuthentication {
}
}

async fn default_credentials_provider(region: Option<Region>) -> SharedCredentialsProvider {
let mut credentials = DefaultCredentialsChain::builder();

if let Some(region) = region {
credentials = credentials.region(region)
}
async fn default_credentials_provider(region: Region) -> SharedCredentialsProvider {
let chain = DefaultCredentialsChain::builder()
.region(region)
.build()
.await;

SharedCredentialsProvider::new(credentials.build().await)
SharedCredentialsProvider::new(chain)
}

#[cfg(test)]
Expand Down
12 changes: 9 additions & 3 deletions src/sinks/elasticsearch/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,16 @@ impl ElasticsearchCommon {
let http_auth = authorization.choose_one(&uri.auth)?;
let base_url = uri.uri.to_string().trim_end_matches('/').to_owned();

let region = config.aws.as_ref().map(|config| config.region());

let aws_auth = match &config.auth {
Some(ElasticsearchAuth::Basic { .. }) | None => None,
Some(ElasticsearchAuth::Aws(aws)) => {
Some(aws.credentials_provider(region.clone()).await?)
let region = config
.aws
.as_ref()
.map(|config| config.region())
.ok_or(ParseError::RegionRequired)?;

Some(aws.credentials_provider(region).await?)
}
};

Expand Down Expand Up @@ -116,6 +120,8 @@ impl ElasticsearchCommon {
metric_config.timezone.unwrap_or_default(),
);

let region = config.aws.as_ref().map(|config| config.region());

Ok(Self {
http_auth,
base_url,
Expand Down
2 changes: 2 additions & 0 deletions src/sinks/elasticsearch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,6 @@ pub enum ParseError {
IndexTemplate { source: TemplateParseError },
#[snafu(display("Batch action template parse error: {}", source))]
BatchActionTemplate { source: TemplateParseError },
#[snafu(display("aws.region required when AWS authentication is in use"))]
RegionRequired,
}
2 changes: 1 addition & 1 deletion src/sources/aws_sqs/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async fn get_sqs_client() -> aws_sdk_sqs::Client {
let config = aws_sdk_sqs::config::Builder::new()
.credentials_provider(
AwsAuthentication::test_auth()
.credentials_provider(Some(Region::new("custom")))
.credentials_provider(Region::new("custom"))
.await
.unwrap(),
)
Expand Down
1 change: 1 addition & 0 deletions tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ async fn parses_sink_full_es_aws() {
type = "elasticsearch"
inputs = ["in"]
endpoint = "https://es.us-east-1.amazonaws.com"
aws.region = "us-east-1"

[sinks.out.auth]
strategy = "aws"
Expand Down