aws_sdk_kms/protocol_serde/
shape_schedule_key_deletion.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2#[allow(clippy::unnecessary_wraps)]
3pub fn de_schedule_key_deletion_http_error(
4    _response_status: u16,
5    _response_headers: &::aws_smithy_runtime_api::http::Headers,
6    _response_body: &[u8],
7) -> std::result::Result<
8    crate::operation::schedule_key_deletion::ScheduleKeyDeletionOutput,
9    crate::operation::schedule_key_deletion::ScheduleKeyDeletionError,
10> {
11    #[allow(unused_mut)]
12    let mut generic_builder = crate::protocol_serde::parse_http_error_metadata(_response_status, _response_headers, _response_body)
13        .map_err(crate::operation::schedule_key_deletion::ScheduleKeyDeletionError::unhandled)?;
14    generic_builder = ::aws_types::request_id::apply_request_id(generic_builder, _response_headers);
15    let generic = generic_builder.build();
16    let error_code = match generic.code() {
17        Some(code) => code,
18        None => return Err(crate::operation::schedule_key_deletion::ScheduleKeyDeletionError::unhandled(generic)),
19    };
20
21    let _error_message = generic.message().map(|msg| msg.to_owned());
22    Err(match error_code {
23        "DependencyTimeoutException" => crate::operation::schedule_key_deletion::ScheduleKeyDeletionError::DependencyTimeoutException({
24            #[allow(unused_mut)]
25            let mut tmp = {
26                #[allow(unused_mut)]
27                let mut output = crate::types::error::builders::DependencyTimeoutExceptionBuilder::default();
28                output = crate::protocol_serde::shape_dependency_timeout_exception::de_dependency_timeout_exception_json_err(_response_body, output)
29                    .map_err(crate::operation::schedule_key_deletion::ScheduleKeyDeletionError::unhandled)?;
30                let output = output.meta(generic);
31                output.build()
32            };
33            if tmp.message.is_none() {
34                tmp.message = _error_message;
35            }
36            tmp
37        }),
38        "InvalidArnException" => crate::operation::schedule_key_deletion::ScheduleKeyDeletionError::InvalidArnException({
39            #[allow(unused_mut)]
40            let mut tmp = {
41                #[allow(unused_mut)]
42                let mut output = crate::types::error::builders::InvalidArnExceptionBuilder::default();
43                output = crate::protocol_serde::shape_invalid_arn_exception::de_invalid_arn_exception_json_err(_response_body, output)
44                    .map_err(crate::operation::schedule_key_deletion::ScheduleKeyDeletionError::unhandled)?;
45                let output = output.meta(generic);
46                output.build()
47            };
48            if tmp.message.is_none() {
49                tmp.message = _error_message;
50            }
51            tmp
52        }),
53        "KMSInternalException" => crate::operation::schedule_key_deletion::ScheduleKeyDeletionError::KmsInternalException({
54            #[allow(unused_mut)]
55            let mut tmp = {
56                #[allow(unused_mut)]
57                let mut output = crate::types::error::builders::KmsInternalExceptionBuilder::default();
58                output = crate::protocol_serde::shape_kms_internal_exception::de_kms_internal_exception_json_err(_response_body, output)
59                    .map_err(crate::operation::schedule_key_deletion::ScheduleKeyDeletionError::unhandled)?;
60                let output = output.meta(generic);
61                output.build()
62            };
63            if tmp.message.is_none() {
64                tmp.message = _error_message;
65            }
66            tmp
67        }),
68        "KMSInvalidStateException" => crate::operation::schedule_key_deletion::ScheduleKeyDeletionError::KmsInvalidStateException({
69            #[allow(unused_mut)]
70            let mut tmp = {
71                #[allow(unused_mut)]
72                let mut output = crate::types::error::builders::KmsInvalidStateExceptionBuilder::default();
73                output = crate::protocol_serde::shape_kms_invalid_state_exception::de_kms_invalid_state_exception_json_err(_response_body, output)
74                    .map_err(crate::operation::schedule_key_deletion::ScheduleKeyDeletionError::unhandled)?;
75                let output = output.meta(generic);
76                output.build()
77            };
78            if tmp.message.is_none() {
79                tmp.message = _error_message;
80            }
81            tmp
82        }),
83        "NotFoundException" => crate::operation::schedule_key_deletion::ScheduleKeyDeletionError::NotFoundException({
84            #[allow(unused_mut)]
85            let mut tmp = {
86                #[allow(unused_mut)]
87                let mut output = crate::types::error::builders::NotFoundExceptionBuilder::default();
88                output = crate::protocol_serde::shape_not_found_exception::de_not_found_exception_json_err(_response_body, output)
89                    .map_err(crate::operation::schedule_key_deletion::ScheduleKeyDeletionError::unhandled)?;
90                let output = output.meta(generic);
91                output.build()
92            };
93            if tmp.message.is_none() {
94                tmp.message = _error_message;
95            }
96            tmp
97        }),
98        _ => crate::operation::schedule_key_deletion::ScheduleKeyDeletionError::generic(generic),
99    })
100}
101
102#[allow(clippy::unnecessary_wraps)]
103pub fn de_schedule_key_deletion_http_response(
104    _response_status: u16,
105    _response_headers: &::aws_smithy_runtime_api::http::Headers,
106    _response_body: &[u8],
107) -> std::result::Result<
108    crate::operation::schedule_key_deletion::ScheduleKeyDeletionOutput,
109    crate::operation::schedule_key_deletion::ScheduleKeyDeletionError,
110> {
111    Ok({
112        #[allow(unused_mut)]
113        let mut output = crate::operation::schedule_key_deletion::builders::ScheduleKeyDeletionOutputBuilder::default();
114        output = crate::protocol_serde::shape_schedule_key_deletion::de_schedule_key_deletion(_response_body, output)
115            .map_err(crate::operation::schedule_key_deletion::ScheduleKeyDeletionError::unhandled)?;
116        output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
117        output.build()
118    })
119}
120
121pub fn ser_schedule_key_deletion_input(
122    input: &crate::operation::schedule_key_deletion::ScheduleKeyDeletionInput,
123) -> Result<::aws_smithy_types::body::SdkBody, ::aws_smithy_types::error::operation::SerializationError> {
124    let mut out = String::new();
125    let mut object = ::aws_smithy_json::serialize::JsonObjectWriter::new(&mut out);
126    crate::protocol_serde::shape_schedule_key_deletion_input::ser_schedule_key_deletion_input_input(&mut object, input)?;
127    object.finish();
128    Ok(::aws_smithy_types::body::SdkBody::from(out))
129}
130
131pub(crate) fn de_schedule_key_deletion(
132    value: &[u8],
133    mut builder: crate::operation::schedule_key_deletion::builders::ScheduleKeyDeletionOutputBuilder,
134) -> Result<
135    crate::operation::schedule_key_deletion::builders::ScheduleKeyDeletionOutputBuilder,
136    ::aws_smithy_json::deserialize::error::DeserializeError,
137> {
138    let mut tokens_owned = ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(value)).peekable();
139    let tokens = &mut tokens_owned;
140    ::aws_smithy_json::deserialize::token::expect_start_object(tokens.next())?;
141    loop {
142        match tokens.next().transpose()? {
143            Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
144            Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
145                "KeyId" => {
146                    builder = builder.set_key_id(
147                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
148                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
149                            .transpose()?,
150                    );
151                }
152                "DeletionDate" => {
153                    builder = builder.set_deletion_date(::aws_smithy_json::deserialize::token::expect_timestamp_or_null(
154                        tokens.next(),
155                        ::aws_smithy_types::date_time::Format::EpochSeconds,
156                    )?);
157                }
158                "KeyState" => {
159                    builder = builder.set_key_state(
160                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
161                            .map(|s| s.to_unescaped().map(|u| crate::types::KeyState::from(u.as_ref())))
162                            .transpose()?,
163                    );
164                }
165                "PendingWindowInDays" => {
166                    builder = builder.set_pending_window_in_days(
167                        ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
168                            .map(i32::try_from)
169                            .transpose()?,
170                    );
171                }
172                _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
173            },
174            other => {
175                return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
176                    "expected object key or end object, found: {:?}",
177                    other
178                )))
179            }
180        }
181    }
182    if tokens.next().is_some() {
183        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
184            "found more JSON tokens after completing parsing",
185        ));
186    }
187    Ok(builder)
188}