aws_sdk_paymentcryptography/operation/
get_key.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Orchestration and serialization glue logic for `GetKey`.
3#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
4#[non_exhaustive]
5pub struct GetKey;
6impl GetKey {
7    /// Creates a new `GetKey`
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_key::GetKeyInput,
14    ) -> ::std::result::Result<
15        crate::operation::get_key::GetKeyOutput,
16        ::aws_smithy_runtime_api::client::result::SdkError<
17            crate::operation::get_key::GetKeyError,
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_key::GetKeyError>().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(output.downcast::<crate::operation::get_key::GetKeyOutput>().expect("correct output type"))
31    }
32
33    pub(crate) async fn orchestrate_with_stop_point(
34        runtime_plugins: &::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
35        input: crate::operation::get_key::GetKeyInput,
36        stop_point: ::aws_smithy_runtime::client::orchestrator::StopPoint,
37    ) -> ::std::result::Result<
38        ::aws_smithy_runtime_api::client::interceptors::context::InterceptorContext,
39        ::aws_smithy_runtime_api::client::result::SdkError<
40            ::aws_smithy_runtime_api::client::interceptors::context::Error,
41            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
42        >,
43    > {
44        let input = ::aws_smithy_runtime_api::client::interceptors::context::Input::erase(input);
45        ::aws_smithy_runtime::client::orchestrator::invoke_with_stop_point("paymentcryptography", "GetKey", input, runtime_plugins, stop_point).await
46    }
47
48    pub(crate) fn operation_runtime_plugins(
49        client_runtime_plugins: ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
50        client_config: &crate::config::Config,
51        config_override: ::std::option::Option<crate::config::Builder>,
52    ) -> ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins {
53        let mut runtime_plugins = client_runtime_plugins.with_operation_plugin(Self::new());
54        runtime_plugins = runtime_plugins.with_client_plugin(crate::auth_plugin::DefaultAuthOptionsPlugin::new(vec![
55            ::aws_runtime::auth::sigv4::SCHEME_ID,
56        ]));
57        if let ::std::option::Option::Some(config_override) = config_override {
58            for plugin in config_override.runtime_plugins.iter().cloned() {
59                runtime_plugins = runtime_plugins.with_operation_plugin(plugin);
60            }
61            runtime_plugins = runtime_plugins.with_operation_plugin(crate::config::ConfigOverrideRuntimePlugin::new(
62                config_override,
63                client_config.config.clone(),
64                &client_config.runtime_components,
65            ));
66        }
67        runtime_plugins
68    }
69}
70impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for GetKey {
71    fn config(&self) -> ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer> {
72        let mut cfg = ::aws_smithy_types::config_bag::Layer::new("GetKey");
73
74        cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedRequestSerializer::new(
75            GetKeyRequestSerializer,
76        ));
77        cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer::new(
78            GetKeyResponseDeserializer,
79        ));
80
81        cfg.store_put(::aws_smithy_runtime_api::client::auth::AuthSchemeOptionResolverParams::new(
82            ::aws_smithy_runtime_api::client::auth::static_resolver::StaticAuthSchemeOptionResolverParams::new(),
83        ));
84
85        cfg.store_put(::aws_smithy_runtime_api::client::orchestrator::Metadata::new(
86            "GetKey",
87            "paymentcryptography",
88        ));
89        let mut signing_options = ::aws_runtime::auth::SigningOptions::default();
90        signing_options.double_uri_encode = true;
91        signing_options.content_sha256_header = false;
92        signing_options.normalize_uri_path = true;
93        signing_options.payload_override = None;
94
95        cfg.store_put(::aws_runtime::auth::SigV4OperationSigningConfig {
96            signing_options,
97            ..::std::default::Default::default()
98        });
99
100        ::std::option::Option::Some(cfg.freeze())
101    }
102
103    fn runtime_components(
104        &self,
105        _: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
106    ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
107        #[allow(unused_mut)]
108        let mut rcb = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("GetKey")
109            .with_interceptor(::aws_smithy_runtime::client::stalled_stream_protection::StalledStreamProtectionInterceptor::default())
110            .with_interceptor(GetKeyEndpointParamsInterceptor)
111            .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::TransientErrorClassifier::<
112                crate::operation::get_key::GetKeyError,
113            >::new())
114            .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::ModeledAsRetryableClassifier::<
115                crate::operation::get_key::GetKeyError,
116            >::new())
117            .with_retry_classifier(::aws_runtime::retries::classifiers::AwsErrorCodeClassifier::<
118                crate::operation::get_key::GetKeyError,
119            >::new());
120
121        ::std::borrow::Cow::Owned(rcb)
122    }
123}
124
125#[derive(Debug)]
126struct GetKeyResponseDeserializer;
127impl ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse for GetKeyResponseDeserializer {
128    fn deserialize_nonstreaming(
129        &self,
130        response: &::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
131    ) -> ::aws_smithy_runtime_api::client::interceptors::context::OutputOrError {
132        let (success, status) = (response.status().is_success(), response.status().as_u16());
133        let headers = response.headers();
134        let body = response.body().bytes().expect("body loaded");
135        #[allow(unused_mut)]
136        let mut force_error = false;
137        ::tracing::debug!(request_id = ?::aws_types::request_id::RequestId::request_id(response));
138        let parse_result = if !success && status != 200 || force_error {
139            crate::protocol_serde::shape_get_key::de_get_key_http_error(status, headers, body)
140        } else {
141            crate::protocol_serde::shape_get_key::de_get_key_http_response(status, headers, body)
142        };
143        crate::protocol_serde::type_erase_result(parse_result)
144    }
145}
146#[derive(Debug)]
147struct GetKeyRequestSerializer;
148impl ::aws_smithy_runtime_api::client::ser_de::SerializeRequest for GetKeyRequestSerializer {
149    #[allow(unused_mut, clippy::let_and_return, clippy::needless_borrow, clippy::useless_conversion)]
150    fn serialize_input(
151        &self,
152        input: ::aws_smithy_runtime_api::client::interceptors::context::Input,
153        _cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
154    ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, ::aws_smithy_runtime_api::box_error::BoxError> {
155        let input = input.downcast::<crate::operation::get_key::GetKeyInput>().expect("correct type");
156        let _header_serialization_settings = _cfg
157            .load::<crate::serialization_settings::HeaderSerializationSettings>()
158            .cloned()
159            .unwrap_or_default();
160        let mut request_builder = {
161            fn uri_base(
162                _input: &crate::operation::get_key::GetKeyInput,
163                output: &mut ::std::string::String,
164            ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
165                use ::std::fmt::Write as _;
166                ::std::write!(output, "/").expect("formatting should succeed");
167                ::std::result::Result::Ok(())
168            }
169            #[allow(clippy::unnecessary_wraps)]
170            fn update_http_builder(
171                input: &crate::operation::get_key::GetKeyInput,
172                builder: ::http::request::Builder,
173            ) -> ::std::result::Result<::http::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
174                let mut uri = ::std::string::String::new();
175                uri_base(input, &mut uri)?;
176                ::std::result::Result::Ok(builder.method("POST").uri(uri))
177            }
178            let mut builder = update_http_builder(&input, ::http::request::Builder::new())?;
179            builder = _header_serialization_settings.set_default_header(builder, ::http::header::CONTENT_TYPE, "application/x-amz-json-1.0");
180            builder = _header_serialization_settings.set_default_header(
181                builder,
182                ::http::header::HeaderName::from_static("x-amz-target"),
183                "PaymentCryptographyControlPlane.GetKey",
184            );
185            builder
186        };
187        let body = ::aws_smithy_types::body::SdkBody::from(crate::protocol_serde::shape_get_key::ser_get_key_input(&input)?);
188        if let Some(content_length) = body.content_length() {
189            let content_length = content_length.to_string();
190            request_builder = _header_serialization_settings.set_default_header(request_builder, ::http::header::CONTENT_LENGTH, &content_length);
191        }
192        ::std::result::Result::Ok(request_builder.body(body).expect("valid request").try_into().unwrap())
193    }
194}
195#[derive(Debug)]
196struct GetKeyEndpointParamsInterceptor;
197
198impl ::aws_smithy_runtime_api::client::interceptors::Intercept for GetKeyEndpointParamsInterceptor {
199    fn name(&self) -> &'static str {
200        "GetKeyEndpointParamsInterceptor"
201    }
202
203    fn read_before_execution(
204        &self,
205        context: &::aws_smithy_runtime_api::client::interceptors::context::BeforeSerializationInterceptorContextRef<
206            '_,
207            ::aws_smithy_runtime_api::client::interceptors::context::Input,
208            ::aws_smithy_runtime_api::client::interceptors::context::Output,
209            ::aws_smithy_runtime_api::client::interceptors::context::Error,
210        >,
211        cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
212    ) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
213        let _input = context.input().downcast_ref::<GetKeyInput>().ok_or("failed to downcast to GetKeyInput")?;
214
215        let params = crate::config::endpoint::Params::builder()
216            .set_region(cfg.load::<::aws_types::region::Region>().map(|r| r.as_ref().to_owned()))
217            .set_use_dual_stack(cfg.load::<::aws_types::endpoint_config::UseDualStack>().map(|ty| ty.0))
218            .set_use_fips(cfg.load::<::aws_types::endpoint_config::UseFips>().map(|ty| ty.0))
219            .set_endpoint(cfg.load::<::aws_types::endpoint_config::EndpointUrl>().map(|ty| ty.0.clone()))
220            .build()
221            .map_err(|err| {
222                ::aws_smithy_runtime_api::client::interceptors::error::ContextAttachedError::new("endpoint params could not be built", err)
223            })?;
224        cfg.interceptor_state()
225            .store_put(::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams::new(params));
226        ::std::result::Result::Ok(())
227    }
228}
229
230// The get_* functions below are generated from JMESPath expressions in the
231// operationContextParams trait. They target the operation's input shape.
232
233/// Error type for the `GetKeyError` operation.
234#[non_exhaustive]
235#[derive(::std::fmt::Debug)]
236pub enum GetKeyError {
237    /// <p>You do not have sufficient access to perform this action.</p>
238    AccessDeniedException(crate::types::error::AccessDeniedException),
239    /// <p>The request processing has failed because of an unknown error, exception, or failure.</p>
240    InternalServerException(crate::types::error::InternalServerException),
241    /// <p>The request was denied due to an invalid resource error.</p>
242    ResourceNotFoundException(crate::types::error::ResourceNotFoundException),
243    /// <p>The service cannot complete the request.</p>
244    ServiceUnavailableException(crate::types::error::ServiceUnavailableException),
245    /// <p>The request was denied due to request throttling.</p>
246    ThrottlingException(crate::types::error::ThrottlingException),
247    /// <p>The request was denied due to an invalid request error.</p>
248    ValidationException(crate::types::error::ValidationException),
249    /// An unexpected error occurred (e.g., invalid JSON returned by the service or an unknown error code).
250    #[deprecated(note = "Matching `Unhandled` directly is not forwards compatible. Instead, match using a \
251    variable wildcard pattern and check `.code()`:
252     \
253    &nbsp;&nbsp;&nbsp;`err if err.code() == Some(\"SpecificExceptionCode\") => { /* handle the error */ }`
254     \
255    See [`ProvideErrorMetadata`](#impl-ProvideErrorMetadata-for-GetKeyError) for what information is available for the error.")]
256    Unhandled(crate::error::sealed_unhandled::Unhandled),
257}
258impl GetKeyError {
259    /// Creates the `GetKeyError::Unhandled` variant from any error type.
260    pub fn unhandled(
261        err: impl ::std::convert::Into<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>>,
262    ) -> Self {
263        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
264            source: err.into(),
265            meta: ::std::default::Default::default(),
266        })
267    }
268
269    /// Creates the `GetKeyError::Unhandled` variant from an [`ErrorMetadata`](::aws_smithy_types::error::ErrorMetadata).
270    pub fn generic(err: ::aws_smithy_types::error::ErrorMetadata) -> Self {
271        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
272            source: err.clone().into(),
273            meta: err,
274        })
275    }
276    ///
277    /// Returns error metadata, which includes the error code, message,
278    /// request ID, and potentially additional information.
279    ///
280    pub fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
281        match self {
282            Self::AccessDeniedException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
283            Self::InternalServerException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
284            Self::ResourceNotFoundException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
285            Self::ServiceUnavailableException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
286            Self::ThrottlingException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
287            Self::ValidationException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
288            Self::Unhandled(e) => &e.meta,
289        }
290    }
291    /// Returns `true` if the error kind is `GetKeyError::AccessDeniedException`.
292    pub fn is_access_denied_exception(&self) -> bool {
293        matches!(self, Self::AccessDeniedException(_))
294    }
295    /// Returns `true` if the error kind is `GetKeyError::InternalServerException`.
296    pub fn is_internal_server_exception(&self) -> bool {
297        matches!(self, Self::InternalServerException(_))
298    }
299    /// Returns `true` if the error kind is `GetKeyError::ResourceNotFoundException`.
300    pub fn is_resource_not_found_exception(&self) -> bool {
301        matches!(self, Self::ResourceNotFoundException(_))
302    }
303    /// Returns `true` if the error kind is `GetKeyError::ServiceUnavailableException`.
304    pub fn is_service_unavailable_exception(&self) -> bool {
305        matches!(self, Self::ServiceUnavailableException(_))
306    }
307    /// Returns `true` if the error kind is `GetKeyError::ThrottlingException`.
308    pub fn is_throttling_exception(&self) -> bool {
309        matches!(self, Self::ThrottlingException(_))
310    }
311    /// Returns `true` if the error kind is `GetKeyError::ValidationException`.
312    pub fn is_validation_exception(&self) -> bool {
313        matches!(self, Self::ValidationException(_))
314    }
315}
316impl ::std::error::Error for GetKeyError {
317    fn source(&self) -> ::std::option::Option<&(dyn ::std::error::Error + 'static)> {
318        match self {
319            Self::AccessDeniedException(_inner) => ::std::option::Option::Some(_inner),
320            Self::InternalServerException(_inner) => ::std::option::Option::Some(_inner),
321            Self::ResourceNotFoundException(_inner) => ::std::option::Option::Some(_inner),
322            Self::ServiceUnavailableException(_inner) => ::std::option::Option::Some(_inner),
323            Self::ThrottlingException(_inner) => ::std::option::Option::Some(_inner),
324            Self::ValidationException(_inner) => ::std::option::Option::Some(_inner),
325            Self::Unhandled(_inner) => ::std::option::Option::Some(&*_inner.source),
326        }
327    }
328}
329impl ::std::fmt::Display for GetKeyError {
330    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
331        match self {
332            Self::AccessDeniedException(_inner) => _inner.fmt(f),
333            Self::InternalServerException(_inner) => _inner.fmt(f),
334            Self::ResourceNotFoundException(_inner) => _inner.fmt(f),
335            Self::ServiceUnavailableException(_inner) => _inner.fmt(f),
336            Self::ThrottlingException(_inner) => _inner.fmt(f),
337            Self::ValidationException(_inner) => _inner.fmt(f),
338            Self::Unhandled(_inner) => {
339                if let ::std::option::Option::Some(code) = ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self) {
340                    write!(f, "unhandled error ({code})")
341                } else {
342                    f.write_str("unhandled error")
343                }
344            }
345        }
346    }
347}
348impl ::aws_smithy_types::retry::ProvideErrorKind for GetKeyError {
349    fn code(&self) -> ::std::option::Option<&str> {
350        ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self)
351    }
352    fn retryable_error_kind(&self) -> ::std::option::Option<::aws_smithy_types::retry::ErrorKind> {
353        ::std::option::Option::None
354    }
355}
356impl ::aws_smithy_types::error::metadata::ProvideErrorMetadata for GetKeyError {
357    fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
358        match self {
359            Self::AccessDeniedException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
360            Self::InternalServerException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
361            Self::ResourceNotFoundException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
362            Self::ServiceUnavailableException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
363            Self::ThrottlingException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
364            Self::ValidationException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
365            Self::Unhandled(_inner) => &_inner.meta,
366        }
367    }
368}
369impl ::aws_smithy_runtime_api::client::result::CreateUnhandledError for GetKeyError {
370    fn create_unhandled_error(
371        source: ::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>,
372        meta: ::std::option::Option<::aws_smithy_types::error::ErrorMetadata>,
373    ) -> Self {
374        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
375            source,
376            meta: meta.unwrap_or_default(),
377        })
378    }
379}
380impl ::aws_types::request_id::RequestId for crate::operation::get_key::GetKeyError {
381    fn request_id(&self) -> Option<&str> {
382        self.meta().request_id()
383    }
384}
385
386pub use crate::operation::get_key::_get_key_output::GetKeyOutput;
387
388pub use crate::operation::get_key::_get_key_input::GetKeyInput;
389
390mod _get_key_input;
391
392mod _get_key_output;
393
394/// Builders
395pub mod builders;