aws_sdk_cognitoidentityprovider/operation/
get_user.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Orchestration and serialization glue logic for `GetUser`.
3#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
4#[non_exhaustive]
5pub struct GetUser;
6impl GetUser {
7    /// Creates a new `GetUser`
8    pub fn new() -> Self {
9        Self
10    }
11    pub(crate) async fn orchestrate(
12        runtime_plugins: &::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
13        input: crate::operation::get_user::GetUserInput,
14    ) -> ::std::result::Result<
15        crate::operation::get_user::GetUserOutput,
16        ::aws_smithy_runtime_api::client::result::SdkError<
17            crate::operation::get_user::GetUserError,
18            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
19        >,
20    > {
21        let map_err =
22            |err: ::aws_smithy_runtime_api::client::result::SdkError<
23                ::aws_smithy_runtime_api::client::interceptors::context::Error,
24                ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
25            >| { err.map_service_error(|err| err.downcast::<crate::operation::get_user::GetUserError>().expect("correct error type")) };
26        let context = Self::orchestrate_with_stop_point(runtime_plugins, input, ::aws_smithy_runtime::client::orchestrator::StopPoint::None)
27            .await
28            .map_err(map_err)?;
29        let output = context.finalize().map_err(map_err)?;
30        ::std::result::Result::Ok(
31            output
32                .downcast::<crate::operation::get_user::GetUserOutput>()
33                .expect("correct output type"),
34        )
35    }
36
37    pub(crate) async fn orchestrate_with_stop_point(
38        runtime_plugins: &::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
39        input: crate::operation::get_user::GetUserInput,
40        stop_point: ::aws_smithy_runtime::client::orchestrator::StopPoint,
41    ) -> ::std::result::Result<
42        ::aws_smithy_runtime_api::client::interceptors::context::InterceptorContext,
43        ::aws_smithy_runtime_api::client::result::SdkError<
44            ::aws_smithy_runtime_api::client::interceptors::context::Error,
45            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
46        >,
47    > {
48        let input = ::aws_smithy_runtime_api::client::interceptors::context::Input::erase(input);
49        use ::tracing::Instrument;
50        ::aws_smithy_runtime::client::orchestrator::invoke_with_stop_point("Cognito Identity Provider", "GetUser", input, runtime_plugins, stop_point)
51            // Create a parent span for the entire operation. Includes a random, internal-only,
52            // seven-digit ID for the operation orchestration so that it can be correlated in the logs.
53            .instrument(::tracing::debug_span!(
54                "Cognito Identity Provider.GetUser",
55                "rpc.service" = "Cognito Identity Provider",
56                "rpc.method" = "GetUser",
57                "sdk_invocation_id" = ::fastrand::u32(1_000_000..10_000_000),
58                "rpc.system" = "aws-api",
59            ))
60            .await
61    }
62
63    pub(crate) fn operation_runtime_plugins(
64        client_runtime_plugins: ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
65        client_config: &crate::config::Config,
66        config_override: ::std::option::Option<crate::config::Builder>,
67    ) -> ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins {
68        let mut runtime_plugins = client_runtime_plugins.with_operation_plugin(Self::new());
69
70        if let ::std::option::Option::Some(config_override) = config_override {
71            for plugin in config_override.runtime_plugins.iter().cloned() {
72                runtime_plugins = runtime_plugins.with_operation_plugin(plugin);
73            }
74            runtime_plugins = runtime_plugins.with_operation_plugin(crate::config::ConfigOverrideRuntimePlugin::new(
75                config_override,
76                client_config.config.clone(),
77                &client_config.runtime_components,
78            ));
79        }
80        runtime_plugins
81    }
82}
83impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for GetUser {
84    fn config(&self) -> ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer> {
85        let mut cfg = ::aws_smithy_types::config_bag::Layer::new("GetUser");
86
87        cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedRequestSerializer::new(
88            GetUserRequestSerializer,
89        ));
90        cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer::new(
91            GetUserResponseDeserializer,
92        ));
93
94        cfg.store_put(::aws_smithy_runtime_api::client::auth::AuthSchemeOptionResolverParams::new(
95            crate::config::auth::Params::builder()
96                .operation_name("GetUser")
97                .build()
98                .expect("required fields set"),
99        ));
100
101        cfg.store_put(::aws_smithy_runtime_api::client::orchestrator::SensitiveOutput);
102        cfg.store_put(::aws_smithy_runtime_api::client::orchestrator::Metadata::new(
103            "GetUser",
104            "Cognito Identity Provider",
105        ));
106
107        ::std::option::Option::Some(cfg.freeze())
108    }
109
110    fn runtime_components(
111        &self,
112        _: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
113    ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
114        #[allow(unused_mut)]
115        let mut rcb = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("GetUser")
116            .with_interceptor(::aws_smithy_runtime::client::stalled_stream_protection::StalledStreamProtectionInterceptor::default())
117            .with_interceptor(GetUserEndpointParamsInterceptor)
118            .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::TransientErrorClassifier::<
119                crate::operation::get_user::GetUserError,
120            >::new())
121            .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::ModeledAsRetryableClassifier::<
122                crate::operation::get_user::GetUserError,
123            >::new())
124            .with_retry_classifier(::aws_runtime::retries::classifiers::AwsErrorCodeClassifier::<
125                crate::operation::get_user::GetUserError,
126            >::new());
127
128        ::std::borrow::Cow::Owned(rcb)
129    }
130}
131
132#[derive(Debug)]
133struct GetUserResponseDeserializer;
134impl ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse for GetUserResponseDeserializer {
135    fn deserialize_nonstreaming(
136        &self,
137        response: &::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
138    ) -> ::aws_smithy_runtime_api::client::interceptors::context::OutputOrError {
139        let (success, status) = (response.status().is_success(), response.status().as_u16());
140        let headers = response.headers();
141        let body = response.body().bytes().expect("body loaded");
142        #[allow(unused_mut)]
143        let mut force_error = false;
144        ::tracing::debug!(request_id = ?::aws_types::request_id::RequestId::request_id(response));
145        let parse_result = if !success && status != 200 || force_error {
146            crate::protocol_serde::shape_get_user::de_get_user_http_error(status, headers, body)
147        } else {
148            crate::protocol_serde::shape_get_user::de_get_user_http_response(status, headers, body)
149        };
150        crate::protocol_serde::type_erase_result(parse_result)
151    }
152}
153#[derive(Debug)]
154struct GetUserRequestSerializer;
155impl ::aws_smithy_runtime_api::client::ser_de::SerializeRequest for GetUserRequestSerializer {
156    #[allow(unused_mut, clippy::let_and_return, clippy::needless_borrow, clippy::useless_conversion)]
157    fn serialize_input(
158        &self,
159        input: ::aws_smithy_runtime_api::client::interceptors::context::Input,
160        _cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
161    ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, ::aws_smithy_runtime_api::box_error::BoxError> {
162        let input = input.downcast::<crate::operation::get_user::GetUserInput>().expect("correct type");
163        let _header_serialization_settings = _cfg
164            .load::<crate::serialization_settings::HeaderSerializationSettings>()
165            .cloned()
166            .unwrap_or_default();
167        let mut request_builder = {
168            #[allow(clippy::uninlined_format_args)]
169            fn uri_base(
170                _input: &crate::operation::get_user::GetUserInput,
171                output: &mut ::std::string::String,
172            ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
173                use ::std::fmt::Write as _;
174                ::std::write!(output, "/").expect("formatting should succeed");
175                ::std::result::Result::Ok(())
176            }
177            #[allow(clippy::unnecessary_wraps)]
178            fn update_http_builder(
179                input: &crate::operation::get_user::GetUserInput,
180                builder: ::http::request::Builder,
181            ) -> ::std::result::Result<::http::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
182                let mut uri = ::std::string::String::new();
183                uri_base(input, &mut uri)?;
184                ::std::result::Result::Ok(builder.method("POST").uri(uri))
185            }
186            let mut builder = update_http_builder(&input, ::http::request::Builder::new())?;
187            builder = _header_serialization_settings.set_default_header(builder, ::http::header::CONTENT_TYPE, "application/x-amz-json-1.1");
188            builder = _header_serialization_settings.set_default_header(
189                builder,
190                ::http::header::HeaderName::from_static("x-amz-target"),
191                "AWSCognitoIdentityProviderService.GetUser",
192            );
193            builder
194        };
195        let body = ::aws_smithy_types::body::SdkBody::from(crate::protocol_serde::shape_get_user::ser_get_user_input(&input)?);
196        if let Some(content_length) = body.content_length() {
197            let content_length = content_length.to_string();
198            request_builder = _header_serialization_settings.set_default_header(request_builder, ::http::header::CONTENT_LENGTH, &content_length);
199        }
200        ::std::result::Result::Ok(request_builder.body(body).expect("valid request").try_into().unwrap())
201    }
202}
203#[derive(Debug)]
204struct GetUserEndpointParamsInterceptor;
205
206impl ::aws_smithy_runtime_api::client::interceptors::Intercept for GetUserEndpointParamsInterceptor {
207    fn name(&self) -> &'static str {
208        "GetUserEndpointParamsInterceptor"
209    }
210
211    fn read_before_execution(
212        &self,
213        context: &::aws_smithy_runtime_api::client::interceptors::context::BeforeSerializationInterceptorContextRef<
214            '_,
215            ::aws_smithy_runtime_api::client::interceptors::context::Input,
216            ::aws_smithy_runtime_api::client::interceptors::context::Output,
217            ::aws_smithy_runtime_api::client::interceptors::context::Error,
218        >,
219        cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
220    ) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
221        let _input = context
222            .input()
223            .downcast_ref::<GetUserInput>()
224            .ok_or("failed to downcast to GetUserInput")?;
225
226        let params = crate::config::endpoint::Params::builder()
227            .set_region(cfg.load::<::aws_types::region::Region>().map(|r| r.as_ref().to_owned()))
228            .set_use_dual_stack(cfg.load::<::aws_types::endpoint_config::UseDualStack>().map(|ty| ty.0))
229            .set_use_fips(cfg.load::<::aws_types::endpoint_config::UseFips>().map(|ty| ty.0))
230            .set_endpoint(cfg.load::<::aws_types::endpoint_config::EndpointUrl>().map(|ty| ty.0.clone()))
231            .build()
232            .map_err(|err| {
233                ::aws_smithy_runtime_api::client::interceptors::error::ContextAttachedError::new("endpoint params could not be built", err)
234            })?;
235        cfg.interceptor_state()
236            .store_put(::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams::new(params));
237        ::std::result::Result::Ok(())
238    }
239}
240
241// The get_* functions below are generated from JMESPath expressions in the
242// operationContextParams trait. They target the operation's input shape.
243
244/// Error type for the `GetUserError` operation.
245#[non_exhaustive]
246#[derive(::std::fmt::Debug)]
247pub enum GetUserError {
248    /// <p>This exception is thrown when WAF doesn't allow your request based on a web ACL that's associated with your user pool.</p>
249    ForbiddenException(crate::types::error::ForbiddenException),
250    /// <p>This exception is thrown when Amazon Cognito encounters an internal error.</p>
251    InternalErrorException(crate::types::error::InternalErrorException),
252    /// <p>This exception is thrown when the Amazon Cognito service encounters an invalid parameter.</p>
253    InvalidParameterException(crate::types::error::InvalidParameterException),
254    /// <p>This exception is thrown when a user isn't authorized.</p>
255    NotAuthorizedException(crate::types::error::NotAuthorizedException),
256    /// <p>This exception is thrown when a password reset is required.</p>
257    PasswordResetRequiredException(crate::types::error::PasswordResetRequiredException),
258    /// <p>This exception is thrown when the Amazon Cognito service can't find the requested resource.</p>
259    ResourceNotFoundException(crate::types::error::ResourceNotFoundException),
260    /// <p>This exception is thrown when the user has made too many requests for a given operation.</p>
261    TooManyRequestsException(crate::types::error::TooManyRequestsException),
262    /// <p>This exception is thrown when a user isn't confirmed successfully.</p>
263    UserNotConfirmedException(crate::types::error::UserNotConfirmedException),
264    /// <p>This exception is thrown when a user isn't found.</p>
265    UserNotFoundException(crate::types::error::UserNotFoundException),
266    /// An unexpected error occurred (e.g., invalid JSON returned by the service or an unknown error code).
267    #[deprecated(note = "Matching `Unhandled` directly is not forwards compatible. Instead, match using a \
268    variable wildcard pattern and check `.code()`:
269     \
270    &nbsp;&nbsp;&nbsp;`err if err.code() == Some(\"SpecificExceptionCode\") => { /* handle the error */ }`
271     \
272    See [`ProvideErrorMetadata`](#impl-ProvideErrorMetadata-for-GetUserError) for what information is available for the error.")]
273    Unhandled(crate::error::sealed_unhandled::Unhandled),
274}
275impl GetUserError {
276    /// Creates the `GetUserError::Unhandled` variant from any error type.
277    pub fn unhandled(
278        err: impl ::std::convert::Into<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>>,
279    ) -> Self {
280        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
281            source: err.into(),
282            meta: ::std::default::Default::default(),
283        })
284    }
285
286    /// Creates the `GetUserError::Unhandled` variant from an [`ErrorMetadata`](::aws_smithy_types::error::ErrorMetadata).
287    pub fn generic(err: ::aws_smithy_types::error::ErrorMetadata) -> Self {
288        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
289            source: err.clone().into(),
290            meta: err,
291        })
292    }
293    ///
294    /// Returns error metadata, which includes the error code, message,
295    /// request ID, and potentially additional information.
296    ///
297    pub fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
298        match self {
299            Self::ForbiddenException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
300            Self::InternalErrorException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
301            Self::InvalidParameterException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
302            Self::NotAuthorizedException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
303            Self::PasswordResetRequiredException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
304            Self::ResourceNotFoundException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
305            Self::TooManyRequestsException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
306            Self::UserNotConfirmedException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
307            Self::UserNotFoundException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
308            Self::Unhandled(e) => &e.meta,
309        }
310    }
311    /// Returns `true` if the error kind is `GetUserError::ForbiddenException`.
312    pub fn is_forbidden_exception(&self) -> bool {
313        matches!(self, Self::ForbiddenException(_))
314    }
315    /// Returns `true` if the error kind is `GetUserError::InternalErrorException`.
316    pub fn is_internal_error_exception(&self) -> bool {
317        matches!(self, Self::InternalErrorException(_))
318    }
319    /// Returns `true` if the error kind is `GetUserError::InvalidParameterException`.
320    pub fn is_invalid_parameter_exception(&self) -> bool {
321        matches!(self, Self::InvalidParameterException(_))
322    }
323    /// Returns `true` if the error kind is `GetUserError::NotAuthorizedException`.
324    pub fn is_not_authorized_exception(&self) -> bool {
325        matches!(self, Self::NotAuthorizedException(_))
326    }
327    /// Returns `true` if the error kind is `GetUserError::PasswordResetRequiredException`.
328    pub fn is_password_reset_required_exception(&self) -> bool {
329        matches!(self, Self::PasswordResetRequiredException(_))
330    }
331    /// Returns `true` if the error kind is `GetUserError::ResourceNotFoundException`.
332    pub fn is_resource_not_found_exception(&self) -> bool {
333        matches!(self, Self::ResourceNotFoundException(_))
334    }
335    /// Returns `true` if the error kind is `GetUserError::TooManyRequestsException`.
336    pub fn is_too_many_requests_exception(&self) -> bool {
337        matches!(self, Self::TooManyRequestsException(_))
338    }
339    /// Returns `true` if the error kind is `GetUserError::UserNotConfirmedException`.
340    pub fn is_user_not_confirmed_exception(&self) -> bool {
341        matches!(self, Self::UserNotConfirmedException(_))
342    }
343    /// Returns `true` if the error kind is `GetUserError::UserNotFoundException`.
344    pub fn is_user_not_found_exception(&self) -> bool {
345        matches!(self, Self::UserNotFoundException(_))
346    }
347}
348impl ::std::error::Error for GetUserError {
349    fn source(&self) -> ::std::option::Option<&(dyn ::std::error::Error + 'static)> {
350        match self {
351            Self::ForbiddenException(_inner) => ::std::option::Option::Some(_inner),
352            Self::InternalErrorException(_inner) => ::std::option::Option::Some(_inner),
353            Self::InvalidParameterException(_inner) => ::std::option::Option::Some(_inner),
354            Self::NotAuthorizedException(_inner) => ::std::option::Option::Some(_inner),
355            Self::PasswordResetRequiredException(_inner) => ::std::option::Option::Some(_inner),
356            Self::ResourceNotFoundException(_inner) => ::std::option::Option::Some(_inner),
357            Self::TooManyRequestsException(_inner) => ::std::option::Option::Some(_inner),
358            Self::UserNotConfirmedException(_inner) => ::std::option::Option::Some(_inner),
359            Self::UserNotFoundException(_inner) => ::std::option::Option::Some(_inner),
360            Self::Unhandled(_inner) => ::std::option::Option::Some(&*_inner.source),
361        }
362    }
363}
364impl ::std::fmt::Display for GetUserError {
365    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
366        match self {
367            Self::ForbiddenException(_inner) => _inner.fmt(f),
368            Self::InternalErrorException(_inner) => _inner.fmt(f),
369            Self::InvalidParameterException(_inner) => _inner.fmt(f),
370            Self::NotAuthorizedException(_inner) => _inner.fmt(f),
371            Self::PasswordResetRequiredException(_inner) => _inner.fmt(f),
372            Self::ResourceNotFoundException(_inner) => _inner.fmt(f),
373            Self::TooManyRequestsException(_inner) => _inner.fmt(f),
374            Self::UserNotConfirmedException(_inner) => _inner.fmt(f),
375            Self::UserNotFoundException(_inner) => _inner.fmt(f),
376            Self::Unhandled(_inner) => {
377                if let ::std::option::Option::Some(code) = ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self) {
378                    write!(f, "unhandled error ({code})")
379                } else {
380                    f.write_str("unhandled error")
381                }
382            }
383        }
384    }
385}
386impl ::aws_smithy_types::retry::ProvideErrorKind for GetUserError {
387    fn code(&self) -> ::std::option::Option<&str> {
388        ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self)
389    }
390    fn retryable_error_kind(&self) -> ::std::option::Option<::aws_smithy_types::retry::ErrorKind> {
391        ::std::option::Option::None
392    }
393}
394impl ::aws_smithy_types::error::metadata::ProvideErrorMetadata for GetUserError {
395    fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
396        match self {
397            Self::ForbiddenException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
398            Self::InternalErrorException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
399            Self::InvalidParameterException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
400            Self::NotAuthorizedException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
401            Self::PasswordResetRequiredException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
402            Self::ResourceNotFoundException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
403            Self::TooManyRequestsException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
404            Self::UserNotConfirmedException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
405            Self::UserNotFoundException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
406            Self::Unhandled(_inner) => &_inner.meta,
407        }
408    }
409}
410impl ::aws_smithy_runtime_api::client::result::CreateUnhandledError for GetUserError {
411    fn create_unhandled_error(
412        source: ::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>,
413        meta: ::std::option::Option<::aws_smithy_types::error::ErrorMetadata>,
414    ) -> Self {
415        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
416            source,
417            meta: meta.unwrap_or_default(),
418        })
419    }
420}
421impl ::aws_types::request_id::RequestId for crate::operation::get_user::GetUserError {
422    fn request_id(&self) -> Option<&str> {
423        self.meta().request_id()
424    }
425}
426
427pub use crate::operation::get_user::_get_user_output::GetUserOutput;
428
429pub use crate::operation::get_user::_get_user_input::GetUserInput;
430
431mod _get_user_input;
432
433mod _get_user_output;
434
435/// Builders
436pub mod builders;