Skip to content

Commit 0226f3f

Browse files
author
Mouli Mukherjee
committed
Fix validate connection
1 parent cdf1ac5 commit 0226f3f

File tree

1 file changed

+47
-30
lines changed
  • src/storage-types/src/connections

1 file changed

+47
-30
lines changed

src/storage-types/src/connections/aws.rs

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -244,37 +244,54 @@ impl AwsConfig {
244244
id: GlobalId,
245245
connection_context: &ConnectionContext,
246246
) -> Result<(), anyhow::Error> {
247-
let external_id_prefix = connection_context
248-
.aws_external_id_prefix
249-
.as_ref()
250-
.ok_or_else(|| anyhow!("external ID should have been provided!"))?;
251-
let external_id = format!("{}_{}", external_id_prefix, id);
252247
let account_id = &connection_context.aws_principal;
253-
let aws_config = self
254-
.load(
255-
Some(external_id),
256-
account_id.clone(),
257-
connection_context.secrets_reader.as_ref(),
258-
)
259-
.await?;
260-
261-
let sts_client = aws_sdk_sts::Client::new(&aws_config);
262-
let response = sts_client.get_caller_identity().send().await?;
263-
println!("{:?}", response);
264-
265-
let aws_config_without_external_id = self
266-
.load(
267-
None,
268-
account_id.clone(),
269-
connection_context.secrets_reader.as_ref(),
270-
)
271-
.await?;
272-
273-
let sts_client = aws_sdk_sts::Client::new(&aws_config_without_external_id);
274-
if sts_client.get_caller_identity().send().await.is_ok() {
275-
Err(anyhow!("Validate succeeded without external_id!"))
276-
} else {
277-
Ok(())
248+
match &self.auth {
249+
AwsAuth::Credentials(_) => {
250+
let aws_config = self
251+
.load(
252+
None,
253+
account_id.clone(),
254+
connection_context.secrets_reader.as_ref(),
255+
)
256+
.await?;
257+
258+
let sts_client = aws_sdk_sts::Client::new(&aws_config);
259+
let _ = sts_client.get_caller_identity().send().await?;
260+
Ok(())
261+
}
262+
AwsAuth::AssumeRole(_) => {
263+
let external_id_prefix = connection_context
264+
.aws_external_id_prefix
265+
.as_ref()
266+
.ok_or_else(|| anyhow!("external ID should have been provided!"))?;
267+
let external_id = format!("{}_{}", external_id_prefix, id);
268+
269+
let aws_config = self
270+
.load(
271+
Some(external_id),
272+
account_id.clone(),
273+
connection_context.secrets_reader.as_ref(),
274+
)
275+
.await?;
276+
277+
let sts_client = aws_sdk_sts::Client::new(&aws_config);
278+
let _ = sts_client.get_caller_identity().send().await?;
279+
280+
let aws_config_without_external_id = self
281+
.load(
282+
None,
283+
account_id.clone(),
284+
connection_context.secrets_reader.as_ref(),
285+
)
286+
.await?;
287+
288+
let sts_client = aws_sdk_sts::Client::new(&aws_config_without_external_id);
289+
if sts_client.get_caller_identity().send().await.is_ok() {
290+
Err(anyhow!("Validate succeeded without external_id!"))
291+
} else {
292+
Ok(())
293+
}
294+
}
278295
}
279296
}
280297

0 commit comments

Comments
 (0)