aws_sdk_iotdataplane/operation/
publish.rs

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