aws_sdk_cognitoidentity/operation/
get_id.rs

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