aws_sdk_sts/config/
auth.rs1pub trait ResolveAuthScheme: ::std::marker::Send + ::std::marker::Sync + ::std::fmt::Debug {
4 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 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#[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 preference: ::std::option::Option<::aws_smithy_runtime_api::client::auth::AuthSchemePreference>,
47 }
48
49 #[allow(clippy::derivable_impls)]
54 impl Default for DefaultAuthSchemeResolver {
55 fn default() -> Self {
56 Self {
57 service_defaults: vec![::aws_smithy_runtime_api::client::auth::AuthSchemeOption::builder()
58 .scheme_id(::aws_runtime::auth::sigv4::SCHEME_ID)
59
60 .build()
61 .expect("required fields set")],
62 operation_overrides: [
63 ("AssumeRoleWithSAML", vec![::aws_smithy_runtime_api::client::auth::AuthSchemeOption::builder()
64 .scheme_id(::aws_runtime::auth::sigv4::SCHEME_ID)
65
66 .build()
67 .expect("required fields set")
68 , ::aws_smithy_runtime_api::client::auth::AuthSchemeOption::from(::aws_smithy_runtime::client::auth::no_auth::NO_AUTH_SCHEME_ID)])
69 ,
70 ("AssumeRoleWithWebIdentity", vec![::aws_smithy_runtime_api::client::auth::AuthSchemeOption::builder()
71 .scheme_id(::aws_runtime::auth::sigv4::SCHEME_ID)
72
73 .build()
74 .expect("required fields set")
75 , ::aws_smithy_runtime_api::client::auth::AuthSchemeOption::from(::aws_smithy_runtime::client::auth::no_auth::NO_AUTH_SCHEME_ID)])
76 ,
77]
78.into(),
79 preference: ::std::option::Option::None,
80 }
81 }
82 }
83
84 impl crate::config::auth::ResolveAuthScheme for DefaultAuthSchemeResolver {
85 fn resolve_auth_scheme<'a>(
86 &'a self,
87 params: &'a crate::config::auth::Params,
88 _cfg: &'a ::aws_smithy_types::config_bag::ConfigBag,
89 _runtime_components: &'a ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponents,
90 ) -> ::aws_smithy_runtime_api::client::auth::AuthSchemeOptionsFuture<'a> {
91 let operation_name = params.operation_name();
92
93 let modeled_auth_options = match self.operation_overrides.get(operation_name) {
94 Some(overrides) => overrides,
95 None => &self.service_defaults,
96 };
97
98 let _fut = ::aws_smithy_runtime_api::client::auth::AuthSchemeOptionsFuture::ready(Ok(modeled_auth_options.clone()));
99
100
101
102 match &self.preference {
103 ::std::option::Option::Some(preference) => {
104 _fut.map_ok({
105 let preference_map: ::std::collections::HashMap<_, _> = preference
107 .clone()
108 .into_iter()
109 .enumerate()
110 .map(|(i, s)| (s, i))
111 .collect();
112 move |auth_scheme_options| {
113 let (mut preferred, non_preferred): (::std::vec::Vec<_>, ::std::vec::Vec<_>) = auth_scheme_options
114 .into_iter()
115 .partition(|auth_scheme_option| {
116 preference_map.contains_key(auth_scheme_option.scheme_id())
117 });
118
119 preferred.sort_by_key(|opt| {
120 preference_map
121 .get(opt.scheme_id())
122 .expect("guaranteed by `partition`")
123 });
124 preferred.extend(non_preferred);
125 preferred
126 }
127 })
128 },
129 ::std::option::Option::None => _fut,
130 }
131 }
132 }
133
134 impl DefaultAuthSchemeResolver {
135 pub fn with_auth_scheme_preference(mut self, preference: impl ::std::convert::Into<::aws_smithy_runtime_api::client::auth::AuthSchemePreference>) -> Self {
137 self.preference = ::std::option::Option::Some(preference.into());
138 self
139 }
140 }
141
142#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
144pub struct Params {
145 operation_name: ::std::borrow::Cow<'static, str>
146}
147impl Params {
148 pub fn builder() -> crate::config::auth::ParamsBuilder {
150 crate::config::auth::ParamsBuilder::default()
151 }
152
153 pub fn operation_name(&self) -> &str {
155 self.operation_name.as_ref()
156 }
157}
158
159#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
160pub struct ParamsBuilder {
162 operation_name: ::std::option::Option<::std::borrow::Cow<'static, str>>,
163}
164impl ParamsBuilder {
165 pub fn operation_name(self, operation_name: impl Into<::std::borrow::Cow<'static, str>>) -> Self {
167 self.set_operation_name(::std::option::Option::Some(operation_name.into()))
168 }
169
170 pub fn set_operation_name(mut self, operation_name: ::std::option::Option<::std::borrow::Cow<'static, str>>) -> Self {
172 self.operation_name = operation_name;
173 self
174 }
175 pub fn build(self) -> ::std::result::Result<crate::config::auth::Params, crate::config::auth::BuildError> {
180 ::std::result::Result::Ok(crate::config::auth::Params {
181 operation_name: self.operation_name
182 .ok_or_else(||BuildError::missing("operation_name"))?
183 })
184 }
185}
186
187#[derive(Debug)]
189 pub struct BuildError {
190 field: ::std::borrow::Cow<'static, str>
191 }
192
193 impl BuildError {
194 fn missing(field: &'static str) -> Self {
195 Self { field: field.into() }
196 }
197 }
198
199 impl std::fmt::Display for BuildError {
200 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
201 write!(f, "a required field was missing: `{}`", self.field)
202 }
203 }
204
205 impl std::error::Error for BuildError { }
206