1#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
4#[non_exhaustive]
5pub struct Publish;
6impl Publish {
7 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 use ::tracing::Instrument;
50 ::aws_smithy_runtime::client::orchestrator::invoke_with_stop_point("IoT Data Plane", "Publish", input, runtime_plugins, stop_point)
51 .instrument(::tracing::debug_span!(
54 "IoT Data Plane.Publish",
55 "rpc.service" = "IoT Data Plane",
56 "rpc.method" = "Publish",
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 Publish {
84 fn config(&self) -> ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer> {
85 let mut cfg = ::aws_smithy_types::config_bag::Layer::new("Publish");
86
87 cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedRequestSerializer::new(
88 PublishRequestSerializer,
89 ));
90 cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer::new(
91 PublishResponseDeserializer,
92 ));
93
94 cfg.store_put(::aws_smithy_runtime_api::client::auth::AuthSchemeOptionResolverParams::new(
95 crate::config::auth::Params::builder()
96 .operation_name("Publish")
97 .build()
98 .expect("required fields set"),
99 ));
100
101 cfg.store_put(::aws_smithy_runtime_api::client::orchestrator::Metadata::new("Publish", "IoT Data Plane"));
102 let mut signing_options = ::aws_runtime::auth::SigningOptions::default();
103 signing_options.double_uri_encode = true;
104 signing_options.content_sha256_header = false;
105 signing_options.normalize_uri_path = true;
106 signing_options.payload_override = None;
107
108 cfg.store_put(::aws_runtime::auth::SigV4OperationSigningConfig {
109 signing_options,
110 ..::std::default::Default::default()
111 });
112
113 ::std::option::Option::Some(cfg.freeze())
114 }
115
116 fn runtime_components(
117 &self,
118 _: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
119 ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
120 #[allow(unused_mut)]
121 let mut rcb = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("Publish")
122 .with_interceptor(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::permanent(
123 PublishTelemetryInputCaptureInterceptor,
124 ))
125 .with_interceptor(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::permanent(
126 ::aws_smithy_runtime::client::stalled_stream_protection::StalledStreamProtectionInterceptor::default(),
127 ))
128 .with_interceptor(::aws_smithy_runtime_api::client::interceptors::SharedInterceptor::permanent(
129 PublishEndpointParamsInterceptor,
130 ))
131 .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::TransientErrorClassifier::<
132 crate::operation::publish::PublishError,
133 >::new())
134 .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::ModeledAsRetryableClassifier::<
135 crate::operation::publish::PublishError,
136 >::new())
137 .with_retry_classifier(::aws_runtime::retries::classifiers::AwsErrorCodeClassifier::<
138 crate::operation::publish::PublishError,
139 >::new())
140 .with_retry_classifier(::aws_runtime::service_clock_skew::ServiceClockSkewClassifier::<
141 crate::operation::publish::PublishError,
142 >::new());
143
144 ::std::borrow::Cow::Owned(rcb)
145 }
146}
147
148#[derive(Debug)]
149struct PublishTelemetryInputCaptureInterceptor;
150
151#[::aws_smithy_runtime_api::client::interceptors::dyn_dispatch_hint]
152impl ::aws_smithy_runtime_api::client::interceptors::Intercept for PublishTelemetryInputCaptureInterceptor {
153 fn name(&self) -> &'static str {
154 "PublishTelemetryInputCaptureInterceptor"
155 }
156
157 fn read_before_execution(
158 &self,
159 context: &::aws_smithy_runtime_api::client::interceptors::context::BeforeSerializationInterceptorContextRef<
160 '_,
161 ::aws_smithy_runtime_api::client::interceptors::context::Input,
162 ::aws_smithy_runtime_api::client::interceptors::context::Output,
163 ::aws_smithy_runtime_api::client::interceptors::context::Error,
164 >,
165 cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
166 ) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
167 let ::std::option::Option::Some(requested) = cfg
169 .load::<::aws_smithy_types::telemetry::RequestedTelemetryAttributes>()
170 .filter(|r| !r.is_empty())
171 else {
172 return ::std::result::Result::Ok(());
173 };
174
175 let ::std::option::Option::Some(input) = context.input().downcast_ref::<PublishInput>() else {
176 return ::std::result::Result::Ok(());
178 };
179
180 let mut captured = ::aws_smithy_types::telemetry::CapturedTelemetryAttributes::default();
181 if requested.should_capture("topic") {
182 if let ::std::option::Option::Some(value) = input.topic.as_deref() {
183 captured.insert("topic", value);
184 }
185 }
186 if requested.should_capture("userProperties") {
187 if let ::std::option::Option::Some(value) = input.user_properties.as_deref() {
188 captured.insert("userProperties", value);
189 }
190 }
191 if requested.should_capture("contentType") {
192 if let ::std::option::Option::Some(value) = input.content_type.as_deref() {
193 captured.insert("contentType", value);
194 }
195 }
196 if requested.should_capture("responseTopic") {
197 if let ::std::option::Option::Some(value) = input.response_topic.as_deref() {
198 captured.insert("responseTopic", value);
199 }
200 }
201 if requested.should_capture("correlationData") {
202 if let ::std::option::Option::Some(value) = input.correlation_data.as_deref() {
203 captured.insert("correlationData", value);
204 }
205 }
206
207 cfg.interceptor_state().store_put(captured);
208 ::std::result::Result::Ok(())
209 }
210}
211#[derive(Debug)]
212struct PublishResponseDeserializer;
213impl ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse for PublishResponseDeserializer {
214 fn deserialize_nonstreaming_with_config(
215 &self,
216 response: &::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
217 _cfg: &::aws_smithy_types::config_bag::ConfigBag,
218 ) -> ::aws_smithy_runtime_api::client::interceptors::context::OutputOrError {
219 let (success, status) = (response.status().is_success(), response.status().as_u16());
220 let headers = response.headers();
221 let body = response.body().bytes().expect("body loaded");
222 #[allow(unused_mut)]
223 let mut force_error = false;
224 ::tracing::debug!(request_id = ?::aws_types::request_id::RequestId::request_id(response));
225 let parse_result = if !success && status != 200 || force_error {
226 crate::protocol_serde::shape_publish::de_publish_http_error(status, headers, body)
227 } else {
228 crate::protocol_serde::shape_publish::de_publish_http_response(status, headers, body)
229 };
230 crate::protocol_serde::type_erase_result(parse_result)
231 }
232}
233#[derive(Debug)]
234struct PublishRequestSerializer;
235impl ::aws_smithy_runtime_api::client::ser_de::SerializeRequest for PublishRequestSerializer {
236 #[allow(unused_mut, clippy::let_and_return, clippy::needless_borrow, clippy::useless_conversion)]
237 fn serialize_input(
238 &self,
239 input: ::aws_smithy_runtime_api::client::interceptors::context::Input,
240 _cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
241 ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, ::aws_smithy_runtime_api::box_error::BoxError> {
242 let input = input.downcast::<crate::operation::publish::PublishInput>().expect("correct type");
243 let _header_serialization_settings = _cfg
244 .load::<crate::serialization_settings::HeaderSerializationSettings>()
245 .cloned()
246 .unwrap_or_default();
247 let mut request_builder = {
248 #[allow(clippy::uninlined_format_args)]
249 fn uri_base(
250 _input: &crate::operation::publish::PublishInput,
251 output: &mut ::std::string::String,
252 ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
253 use ::std::fmt::Write as _;
254 let input_1 = &_input.topic;
255 let input_1 = input_1
256 .as_ref()
257 .ok_or_else(|| ::aws_smithy_types::error::operation::BuildError::missing_field("topic", "cannot be empty or unset"))?;
258 let topic = ::aws_smithy_http::label::fmt_string(input_1, ::aws_smithy_http::label::EncodingStrategy::Default);
259 if topic.is_empty() {
260 return ::std::result::Result::Err(::aws_smithy_types::error::operation::BuildError::missing_field(
261 "topic",
262 "cannot be empty or unset",
263 ));
264 }
265 ::std::write!(output, "/topics/{topic}", topic = topic).expect("formatting should succeed");
266 ::std::result::Result::Ok(())
267 }
268 fn uri_query(
269 _input: &crate::operation::publish::PublishInput,
270 mut output: &mut ::std::string::String,
271 ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
272 let mut query = ::aws_smithy_http::query::Writer::new(output);
273 if let ::std::option::Option::Some(inner_2) = &_input.qos {
274 {
275 query.push_kv("qos", ::aws_smithy_types::primitive::Encoder::from(*inner_2).encode());
276 }
277 }
278 if let ::std::option::Option::Some(inner_3) = &_input.retain {
279 {
280 query.push_kv("retain", ::aws_smithy_types::primitive::Encoder::from(*inner_3).encode());
281 }
282 }
283 if let ::std::option::Option::Some(inner_4) = &_input.content_type {
284 {
285 query.push_kv("contentType", &::aws_smithy_http::query::fmt_string(inner_4));
286 }
287 }
288 if let ::std::option::Option::Some(inner_5) = &_input.response_topic {
289 {
290 query.push_kv("responseTopic", &::aws_smithy_http::query::fmt_string(inner_5));
291 }
292 }
293 if let ::std::option::Option::Some(inner_6) = &_input.message_expiry {
294 {
295 query.push_kv("messageExpiry", ::aws_smithy_types::primitive::Encoder::from(*inner_6).encode());
296 }
297 }
298 ::std::result::Result::Ok(())
299 }
300 #[allow(clippy::unnecessary_wraps)]
301 fn update_http_builder(
302 input: &crate::operation::publish::PublishInput,
303 builder: ::http_1x::request::Builder,
304 ) -> ::std::result::Result<::http_1x::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
305 let mut uri = ::std::string::String::new();
306 uri_base(input, &mut uri)?;
307 uri_query(input, &mut uri)?;
308 let builder = crate::protocol_serde::shape_publish::ser_publish_headers(input, builder)?;
309 ::std::result::Result::Ok(builder.method("POST").uri(uri))
310 }
311 let mut builder = update_http_builder(&input, ::http_1x::request::Builder::new())?;
312 builder = _header_serialization_settings.set_default_header(builder, ::http_1x::header::CONTENT_TYPE, "application/octet-stream");
313 builder
314 };
315 let body = ::aws_smithy_types::body::SdkBody::from(crate::protocol_serde::shape_publish_input::ser_payload_http_payload(input.payload)?);
316 if let Some(content_length) = body.content_length() {
317 let content_length = content_length.to_string();
318 request_builder = _header_serialization_settings.set_default_header(request_builder, ::http_1x::header::CONTENT_LENGTH, &content_length);
319 }
320 ::std::result::Result::Ok(request_builder.body(body).expect("valid request").try_into().unwrap())
321 }
322}
323#[derive(Debug)]
324struct PublishEndpointParamsInterceptor;
325
326#[::aws_smithy_runtime_api::client::interceptors::dyn_dispatch_hint]
327impl ::aws_smithy_runtime_api::client::interceptors::Intercept for PublishEndpointParamsInterceptor {
328 fn name(&self) -> &'static str {
329 "PublishEndpointParamsInterceptor"
330 }
331
332 fn read_before_execution(
333 &self,
334 context: &::aws_smithy_runtime_api::client::interceptors::context::BeforeSerializationInterceptorContextRef<
335 '_,
336 ::aws_smithy_runtime_api::client::interceptors::context::Input,
337 ::aws_smithy_runtime_api::client::interceptors::context::Output,
338 ::aws_smithy_runtime_api::client::interceptors::context::Error,
339 >,
340 cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
341 ) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
342 let _input = context
343 .input()
344 .downcast_ref::<PublishInput>()
345 .ok_or("failed to downcast to PublishInput")?;
346
347 let params = crate::config::endpoint::Params::builder()
348 .set_region(cfg.load::<::aws_types::region::Region>().map(|r| r.as_ref().to_owned()))
349 .set_use_dual_stack(cfg.load::<::aws_types::endpoint_config::UseDualStack>().map(|ty| ty.0))
350 .set_use_fips(cfg.load::<::aws_types::endpoint_config::UseFips>().map(|ty| ty.0))
351 .set_endpoint(cfg.load::<::aws_types::endpoint_config::EndpointUrl>().map(|ty| ty.0.clone()))
352 .build()
353 .map_err(|err| {
354 ::aws_smithy_runtime_api::client::interceptors::error::ContextAttachedError::new("endpoint params could not be built", err)
355 })?;
356 cfg.interceptor_state()
357 .store_put(::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams::new(params));
358 ::std::result::Result::Ok(())
359 }
360}
361
362#[non_exhaustive]
367#[derive(::std::fmt::Debug)]
368pub enum PublishError {
369 InternalFailureException(crate::types::error::InternalFailureException),
371 InvalidRequestException(crate::types::error::InvalidRequestException),
373 MethodNotAllowedException(crate::types::error::MethodNotAllowedException),
375 ThrottlingException(crate::types::error::ThrottlingException),
377 UnauthorizedException(crate::types::error::UnauthorizedException),
379 #[deprecated(note = "Matching `Unhandled` directly is not forwards compatible. Instead, match using a \
381 variable wildcard pattern and check `.code()`:
382 \
383 `err if err.code() == Some(\"SpecificExceptionCode\") => { /* handle the error */ }`
384 \
385 See [`ProvideErrorMetadata`](#impl-ProvideErrorMetadata-for-PublishError) for what information is available for the error.")]
386 Unhandled(crate::error::sealed_unhandled::Unhandled),
387}
388impl PublishError {
389 pub fn unhandled(
391 err: impl ::std::convert::Into<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>>,
392 ) -> Self {
393 Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
394 source: err.into(),
395 meta: ::std::default::Default::default(),
396 })
397 }
398
399 pub fn generic(err: ::aws_smithy_types::error::ErrorMetadata) -> Self {
401 Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
402 source: err.clone().into(),
403 meta: err,
404 })
405 }
406 pub fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
411 match self {
412 Self::InternalFailureException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
413 Self::InvalidRequestException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
414 Self::MethodNotAllowedException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
415 Self::ThrottlingException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
416 Self::UnauthorizedException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
417 Self::Unhandled(e) => &e.meta,
418 }
419 }
420 pub fn is_internal_failure_exception(&self) -> bool {
422 matches!(self, Self::InternalFailureException(_))
423 }
424 pub fn is_invalid_request_exception(&self) -> bool {
426 matches!(self, Self::InvalidRequestException(_))
427 }
428 pub fn is_method_not_allowed_exception(&self) -> bool {
430 matches!(self, Self::MethodNotAllowedException(_))
431 }
432 pub fn is_throttling_exception(&self) -> bool {
434 matches!(self, Self::ThrottlingException(_))
435 }
436 pub fn is_unauthorized_exception(&self) -> bool {
438 matches!(self, Self::UnauthorizedException(_))
439 }
440}
441impl ::std::error::Error for PublishError {
442 fn source(&self) -> ::std::option::Option<&(dyn ::std::error::Error + 'static)> {
443 match self {
444 Self::InternalFailureException(_inner) => ::std::option::Option::Some(_inner),
445 Self::InvalidRequestException(_inner) => ::std::option::Option::Some(_inner),
446 Self::MethodNotAllowedException(_inner) => ::std::option::Option::Some(_inner),
447 Self::ThrottlingException(_inner) => ::std::option::Option::Some(_inner),
448 Self::UnauthorizedException(_inner) => ::std::option::Option::Some(_inner),
449 Self::Unhandled(_inner) => ::std::option::Option::Some(&*_inner.source),
450 }
451 }
452}
453impl ::std::fmt::Display for PublishError {
454 fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
455 match self {
456 Self::InternalFailureException(_inner) => _inner.fmt(f),
457 Self::InvalidRequestException(_inner) => _inner.fmt(f),
458 Self::MethodNotAllowedException(_inner) => _inner.fmt(f),
459 Self::ThrottlingException(_inner) => _inner.fmt(f),
460 Self::UnauthorizedException(_inner) => _inner.fmt(f),
461 Self::Unhandled(_inner) => {
462 if let ::std::option::Option::Some(code) = ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self) {
463 write!(f, "unhandled error ({code})")
464 } else {
465 f.write_str("unhandled error")
466 }
467 }
468 }
469 }
470}
471impl ::aws_smithy_types::retry::ProvideErrorKind for PublishError {
472 fn code(&self) -> ::std::option::Option<&str> {
473 ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self)
474 }
475 fn retryable_error_kind(&self) -> ::std::option::Option<::aws_smithy_types::retry::ErrorKind> {
476 ::std::option::Option::None
477 }
478}
479impl ::aws_smithy_types::error::metadata::ProvideErrorMetadata for PublishError {
480 fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
481 match self {
482 Self::InternalFailureException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
483 Self::InvalidRequestException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
484 Self::MethodNotAllowedException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
485 Self::ThrottlingException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
486 Self::UnauthorizedException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
487 Self::Unhandled(_inner) => &_inner.meta,
488 }
489 }
490}
491impl ::aws_smithy_runtime_api::client::result::CreateUnhandledError for PublishError {
492 fn create_unhandled_error(
493 source: ::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>,
494 meta: ::std::option::Option<::aws_smithy_types::error::ErrorMetadata>,
495 ) -> Self {
496 Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
497 source,
498 meta: meta.unwrap_or_default(),
499 })
500 }
501}
502impl ::aws_types::request_id::RequestId for crate::operation::publish::PublishError {
503 fn request_id(&self) -> Option<&str> {
504 self.meta().request_id()
505 }
506}
507
508pub use crate::operation::publish::_publish_input::PublishInput;
509
510pub use crate::operation::publish::_publish_output::PublishOutput;
511
512mod _publish_input;
513
514mod _publish_output;
515
516pub mod builders;