aws_sdk_transcribestreaming/config/
auth.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Auth scheme resolver trait specific to Amazon Transcribe Streaming 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                    preference: ::std::option::Option<::aws_smithy_runtime_api::client::auth::AuthSchemePreference>,
47                }
48
49                // TODO(https://github.com/smithy-lang/smithy-rs/issues/4177): Remove `allow(...)` once the issue is addressed.
50                // When generating code for tests (e.g., `codegen-client-test`), this manual implementation
51                // of the `Default` trait may appear as if it could be derived automatically.
52                // However, that is not the case in production.
53                #[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: ::std::collections::HashMap::new(),
63                            preference: ::std::option::Option::None,
64                        }
65                    }
66                }
67
68                impl crate::config::auth::ResolveAuthScheme for DefaultAuthSchemeResolver {
69                    fn resolve_auth_scheme<'a>(
70                        &'a self,
71                        params: &'a crate::config::auth::Params,
72                        _cfg: &'a ::aws_smithy_types::config_bag::ConfigBag,
73                        _runtime_components: &'a ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponents,
74                    ) -> ::aws_smithy_runtime_api::client::auth::AuthSchemeOptionsFuture<'a> {
75                        let operation_name = params.operation_name();
76
77                        let modeled_auth_options = match self.operation_overrides.get(operation_name) {
78                            Some(overrides) => overrides,
79                            None => &self.service_defaults,
80                        };
81
82                        let _fut = ::aws_smithy_runtime_api::client::auth::AuthSchemeOptionsFuture::ready(Ok(modeled_auth_options.clone()));
83
84                        
85
86                        match &self.preference {
87                            ::std::option::Option::Some(preference) => {
88                                _fut.map_ok({
89                                    // maps auth scheme ID to the index in the preference list
90                                    let preference_map: ::std::collections::HashMap<_, _> = preference
91                                        .clone()
92                                        .into_iter()
93                                        .enumerate()
94                                        .map(|(i, s)| (s, i))
95                                        .collect();
96                                    move |auth_scheme_options| {
97                                        let (mut preferred, non_preferred): (::std::vec::Vec<_>, ::std::vec::Vec<_>) = auth_scheme_options
98                                            .into_iter()
99                                            .partition(|auth_scheme_option| {
100                                                preference_map.contains_key(auth_scheme_option.scheme_id())
101                                            });
102
103                                        preferred.sort_by_key(|opt| {
104                                            preference_map
105                                                .get(opt.scheme_id())
106                                                .expect("guaranteed by `partition`")
107                                        });
108                                        preferred.extend(non_preferred);
109                                        preferred
110                                    }
111                                })
112                            },
113                            ::std::option::Option::None => _fut,
114                        }
115                    }
116                }
117
118                impl DefaultAuthSchemeResolver {
119                    /// Set auth scheme preference to the default auth scheme resolver
120                    pub fn with_auth_scheme_preference(mut self, preference: impl ::std::convert::Into<::aws_smithy_runtime_api::client::auth::AuthSchemePreference>) -> Self {
121                        self.preference = ::std::option::Option::Some(preference.into());
122                        self
123                    }
124                }
125
126/// Configuration parameters for resolving the correct auth scheme
127#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::fmt::Debug)]
128pub struct Params {
129    operation_name: ::std::borrow::Cow<'static, str>
130}
131impl Params {
132    /// Create a builder for [`Params`]
133                    pub fn builder() -> crate::config::auth::ParamsBuilder {
134                        crate::config::auth::ParamsBuilder::default()
135                    }
136    
137                    /// Return the operation name for [`Params`]
138                    pub fn operation_name(&self) -> &str {
139                        self.operation_name.as_ref()
140                    }
141}
142
143#[derive(::std::clone::Clone, ::std::cmp::PartialEq, ::std::default::Default, ::std::fmt::Debug)]
144/// Builder for [`Params`]
145pub struct ParamsBuilder {
146    operation_name: ::std::option::Option<::std::borrow::Cow<'static, str>>,
147}
148impl ParamsBuilder {
149    /// Set the operation name for the builder
150                    pub fn operation_name(self, operation_name: impl Into<::std::borrow::Cow<'static, str>>) -> Self {
151                        self.set_operation_name(::std::option::Option::Some(operation_name.into()))
152                    }
153    
154                    /// Set the operation name for the builder
155                    pub fn set_operation_name(mut self, operation_name: ::std::option::Option<::std::borrow::Cow<'static, str>>) -> Self {
156                        self.operation_name = operation_name;
157                        self
158                    }
159    /// Consume this builder, create [`Params`]."
160    /// 
161    /// Return [`BuildError`] if any of the required fields are unset.
162    /// 
163    pub fn build(self) -> ::std::result::Result<crate::config::auth::Params, crate::config::auth::BuildError> {
164        ::std::result::Result::Ok(crate::config::auth::Params {
165                                operation_name: self.operation_name
166                                    .ok_or_else(||BuildError::missing("operation_name"))?
167                            })
168    }
169}
170
171/// An error that occurred while constructing `config::auth::Params`
172                #[derive(Debug)]
173                pub struct BuildError {
174                    field: ::std::borrow::Cow<'static, str>
175                }
176
177                impl BuildError {
178                    fn missing(field: &'static str) -> Self {
179                        Self { field: field.into() }
180                    }
181                }
182
183                impl std::fmt::Display for BuildError {
184                    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
185                        write!(f, "a required field was missing: `{}`", self.field)
186                    }
187                }
188
189                impl std::error::Error for BuildError { }
190