aws_sdk_codestarnotifications/operation/
subscribe.rs

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