raws_sts/
lib.rs

1use aws_sdk_sts as sts;
2use clap::{Args, Subcommand};
3
4use config::Config;
5use error::RawsError;
6
7mod assume;
8mod get;
9
10type StsResult<T = Box<dyn show::Show>> = Result<T, sts::Error>;
11
12/// Security Token Service (STS) operations
13#[derive(Debug, Subcommand)]
14pub enum Sts {
15    AssumeRole(assume::AssumeRole),
16    AssumeRoleWithSaml(assume::AssumeRoleWithSaml),
17    AssumeRoleWithWebIdentity(assume::AssumeRoleWithWebIdentity),
18    GetAccessKeyInfo(get::GetAccessKeyInfo),
19    GetCallerIdentity(get::GetCallerIdentity),
20    GetFederationToken(get::GetFederationToken),
21    GetSessionToken(get::GetSessionToken),
22}
23
24impl Sts {
25    async fn execute(self, config: &Config) -> StsResult {
26        match self {
27            Self::AssumeRole(assume_role) => assume_role.execute(config).await,
28            Self::AssumeRoleWithSaml(assume_role_with_saml) => {
29                assume_role_with_saml.execute(config).await
30            }
31            Self::AssumeRoleWithWebIdentity(assume_role_with_web_identity) => {
32                assume_role_with_web_identity.execute(config).await
33            }
34            Self::GetAccessKeyInfo(get_access_key_info) => {
35                get_access_key_info.execute(config).await
36            }
37            Self::GetCallerIdentity(get_caller_identity) => {
38                get_caller_identity.execute(config).await
39            }
40            Self::GetFederationToken(get_federation_token) => {
41                get_federation_token.execute(config).await
42            }
43            Self::GetSessionToken(get_session_token) => get_session_token.execute(config).await,
44        }
45    }
46
47    pub async fn dispatch(self, config: Config) -> Result<(), RawsError<sts::Error>> {
48        self.execute(&config)
49            .await
50            .map(|output| config.show(output))?;
51        Ok(())
52    }
53}