Skip to main content

aws_sdk_sts/config/
auth.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Auth scheme resolver trait specific to AWS Security Token Service
3pub trait ResolveAuthScheme: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug {
4    /// Resolve a priority list of auth scheme options with the given parameters
5    fn resolve_auth_scheme<'a>(
6        &'a self,
7        params: &'a crate::config::auth::Params,
8        cfg: &'a ::aws_smithy_types::config_bag::ConfigBag,
9        runtime_components: &'a ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponents,
10    ) -> ::aws_smithy_runtime_api::client::auth::AuthSchemeOptionsFuture<'a>;
11
12    /// Convert this service-specific resolver into a `SharedAuthSchemeOptionResolver`
13    fn into_shared_resolver(self) -> ::aws_smithy_runtime_api::client::auth::SharedAuthSchemeOptionResolver
14    where
15        Self: ::std::marker::Sized + 'static,
16    {
17        ::aws_smithy_runtime_api::client::auth::SharedAuthSchemeOptionResolver::new(DowncastParams(self))
18    }
19}
20
21#[derive(Debug)]
22struct DowncastParams<T>(T);
23impl<T> ::aws_smithy_runtime_api::client::auth::ResolveAuthSchemeOptions for DowncastParams<T>
24where
25    T: ResolveAuthScheme,
26{
27    fn resolve_auth_scheme_options_v2<'a>(
28        &'a self,
29        params: &'a ::aws_smithy_runtime_api::client::auth::AuthSchemeOptionResolverParams,
30        cfg: &'a ::aws_smithy_types::config_bag::ConfigBag,
31        runtime_components: &'a ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponents,
32    ) -> ::aws_smithy_runtime_api::client::auth::AuthSchemeOptionsFuture<'a> {
33        match params.get::<crate::config::auth::Params>() {
34            ::std::option::Option::Some(concrete_params) => self.0.resolve_auth_scheme(concrete_params, cfg, runtime_components),
35            ::std::option::Option::None => ::aws_smithy_runtime_api::client::auth::AuthSchemeOptionsFuture::ready(::std::result::Result::Err(
36                "params of expected type was not present".into(),
37            )),
38        }
39    }
40}
41
42/// The default auth scheme resolver
43#[derive(Debug)]
44#[allow(dead_code)]
45pub struct DefaultAuthSchemeResolver {
46    service_defaults: Vec<::aws_smithy_runtime_api::client::auth::AuthSchemeOption>,
47    operation_overrides: ::std::collections::HashMap<&'static str, Vec<::aws_smithy_runtime_api::client::auth::AuthSchemeOption>>,
48}
49
50// TODO(https://github.com/smithy-lang/smithy-rs/issues/4177): Remove `allow(...)` once the issue is addressed.
51// When generating code for tests (e.g., `codegen-client-test`), this manual implementation
52// of the `Default` trait may appear as if it could be derived automatically.
53// However, that is not the case in production.
54#[allow(clippy::derivable_impls)]
55impl Default for DefaultAuthSchemeResolver {
56    fn default() -> Self {
57        Self {
58            service_defaults: vec![
59                ::aws_smithy_runtime_api::client::auth::AuthSchemeOption::builder()
60                    .scheme_id(::aws_runtime::auth::sigv4::SCHEME_ID)
61                    .build()
62                    .expect("required fields set"),
63                #[cfg(feature = "sigv4a")]
64                {
65                    ::aws_smithy_runtime_api::client::auth::AuthSchemeOption::builder()
66                        .scheme_id(::aws_runtime::auth::sigv4a::SCHEME_ID)
67                        .build()
68                        .expect("required fields set")
69                },
70            ],
71            operation_overrides: [
72                (
73                    "AssumeRoleWithSAML",
74                    vec![::aws_smithy_runtime_api::client::auth::AuthSchemeOption::from(
75                        ::aws_smithy_runtime::client::auth::no_auth::NO_AUTH_SCHEME_ID,
76                    )],
77                ),
78                (
79                    "AssumeRoleWithWebIdentity",
80                    vec![::aws_smithy_runtime_api::client::auth::AuthSchemeOption::from(
81                        ::aws_smithy_runtime::client::auth::no_auth::NO_AUTH_SCHEME_ID,
82                    )],
83                ),
84            ]
85            .into(),
86        }
87    }
88}
89
90impl crate::config::auth::ResolveAuthScheme for DefaultAuthSchemeResolver {
91    fn resolve_auth_scheme<'a>(
92        &'a self,
93        params: &'a crate::config::auth::Params,
94        _cfg: &'a ::aws_smithy_types::config_bag::ConfigBag,
95        _runtime_components: &'a ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponents,
96    ) -> ::aws_smithy_runtime_api::client::auth::AuthSchemeOptionsFuture<'a> {
97        let operation_name = params.operation_name();
98
99        let modeled_auth_options = match self.operation_overrides.get(operation_name) {
100            Some(overrides) => overrides,
101            None => &self.service_defaults,
102        };
103
104        let _fut = ::aws_smithy_runtime_api::client::auth::AuthSchemeOptionsFuture::ready(Ok(modeled_auth_options.clone()));
105
106        _fut
107    }
108}
109
110/// Configuration parameters for resolving the correct auth scheme
111#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
112pub struct Params {
113    operation_name: ::std::borrow::Cow<'static, str>,
114}
115impl Params {
116    /// Create a builder for [`Params`]
117    pub fn builder() -> crate::config::auth::ParamsBuilder {
118        crate::config::auth::ParamsBuilder::default()
119    }
120
121    /// Return the operation name for [`Params`]
122    pub fn operation_name(&self) -> &str {
123        self.operation_name.as_ref()
124    }
125}
126
127#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
128/// Builder for [`Params`]
129pub struct ParamsBuilder {
130    operation_name: ::std::option::Option<::std::borrow::Cow<'static, str>>,
131}
132impl ParamsBuilder {
133    /// Set the operation name for the builder
134    pub fn operation_name(self, operation_name: impl Into<::std::borrow::Cow<'static, str>>) -> Self {
135        self.set_operation_name(::std::option::Option::Some(operation_name.into()))
136    }
137
138    /// Set the operation name for the builder
139    pub fn set_operation_name(mut self, operation_name: ::std::option::Option<::std::borrow::Cow<'static, str>>) -> Self {
140        self.operation_name = operation_name;
141        self
142    }
143    /// Consume this builder, create [`Params`]."
144    ///
145    /// Return [`BuildError`] if any of the required fields are unset.
146    ///
147    pub fn build(self) -> ::std::result::Result<crate::config::auth::Params, crate::config::auth::BuildError> {
148        ::std::result::Result::Ok(crate::config::auth::Params {
149            operation_name: self.operation_name.ok_or_else(|| BuildError::missing("operation_name"))?,
150        })
151    }
152}
153
154/// An error that occurred while constructing `config::auth::Params`
155#[derive(Debug)]
156pub struct BuildError {
157    field: ::std::borrow::Cow<'static, str>,
158}
159
160impl BuildError {
161    fn missing(field: &'static str) -> Self {
162        Self { field: field.into() }
163    }
164}
165
166impl std::fmt::Display for BuildError {
167    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
168        write!(f, "a required field was missing: `{}`", self.field)
169    }
170}
171
172impl std::error::Error for BuildError {}