-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend): Add STSAdapter for validating AWS credentials
This commit introduces the module `STSAdapter` that checks the validity of AWS credentials by performing a `get_caller_identity` operation via AWS's Secure Token Service (STS). A successful operation indicates that the credentials are valid. Refs: #14
- Loading branch information
Showing
16 changed files
with
342 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod aws; | ||
pub mod report; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use aws_config::BehaviorVersion; | ||
|
||
pub fn localstack_endpoint() -> Option<String> { | ||
match std::env::var("LOCALSTACK_ENDPOINT") { | ||
Ok(value) => Some(value), | ||
Err(_) => None, | ||
} | ||
} | ||
|
||
pub fn shared_config_loader(profile_name: &str) -> aws_config::ConfigLoader { | ||
aws_config::defaults(BehaviorVersion::latest()).credentials_provider( | ||
aws_config::profile::ProfileFileCredentialsProvider::builder() | ||
.profile_name(profile_name) | ||
.build(), | ||
) | ||
} | ||
|
||
pub fn sts_client(config: &aws_config::SdkConfig) -> aws_sdk_sts::Client { | ||
// Copy config from aws_config::SdkConfig to aws_sdk_sts::Config | ||
let sts_config_builder = aws_sdk_sts::config::Builder::from(config); | ||
|
||
aws_sdk_sts::Client::from_conf(sts_config_builder.build()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod application; | ||
pub mod core; | ||
pub mod infrastructure; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod error; | ||
pub mod spi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::fmt::{Display, Formatter}; | ||
|
||
use error_stack::Context; | ||
|
||
#[derive(Debug, Eq, PartialEq, Clone, serde::Serialize)] | ||
pub enum CredentialsError { | ||
InvalidCredentialsError, | ||
UnexpectedError(String), | ||
} | ||
|
||
impl Display for CredentialsError { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
CredentialsError::InvalidCredentialsError => write!(f, "invalid credentials error"), | ||
CredentialsError::UnexpectedError(skd_error) => { | ||
write!(f, "unexpected error: {}", skd_error) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl Context for CredentialsError {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use async_trait::async_trait; | ||
use error_stack::Result; | ||
#[cfg(test)] | ||
use mockall::automock; | ||
|
||
use crate::credentials::core::error::CredentialsError; | ||
|
||
#[cfg_attr(test, automock)] | ||
#[async_trait] | ||
pub trait CredentialsDataSPI: Send + Sync { | ||
async fn validate_credentials(&self, profile_name: &str) -> Result<(), CredentialsError>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod aws; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod sts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod sts_adapter; |
Oops, something went wrong.