aws_sdk_kms/protocol_serde/
shape_list_grants.rs

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