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