aws_sdk_sts/protocol_serde/
shape_get_delegated_access_token.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2#[allow(clippy::unnecessary_wraps)]
3pub fn de_get_delegated_access_token_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::get_delegated_access_token::GetDelegatedAccessTokenOutput,
9    crate::operation::get_delegated_access_token::GetDelegatedAccessTokenError,
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::get_delegated_access_token::GetDelegatedAccessTokenError::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 => {
19            return Err(crate::operation::get_delegated_access_token::GetDelegatedAccessTokenError::unhandled(
20                generic,
21            ))
22        }
23    };
24
25    let _error_message = generic.message().map(|msg| msg.to_owned());
26    Err(match error_code {
27        "ExpiredTradeInTokenException" => crate::operation::get_delegated_access_token::GetDelegatedAccessTokenError::ExpiredTradeInTokenException({
28            #[allow(unused_mut)]
29            let mut tmp = {
30                #[allow(unused_mut)]
31                let mut output = crate::types::error::builders::ExpiredTradeInTokenExceptionBuilder::default();
32                output = crate::protocol_serde::shape_expired_trade_in_token_exception::de_expired_trade_in_token_exception_xml_err(
33                    _response_body,
34                    output,
35                )
36                .map_err(crate::operation::get_delegated_access_token::GetDelegatedAccessTokenError::unhandled)?;
37                let output = output.meta(generic);
38                output.build()
39            };
40            if tmp.message.is_none() {
41                tmp.message = _error_message;
42            }
43            tmp
44        }),
45        "RegionDisabledException" => crate::operation::get_delegated_access_token::GetDelegatedAccessTokenError::RegionDisabledException({
46            #[allow(unused_mut)]
47            let mut tmp = {
48                #[allow(unused_mut)]
49                let mut output = crate::types::error::builders::RegionDisabledExceptionBuilder::default();
50                output = crate::protocol_serde::shape_region_disabled_exception::de_region_disabled_exception_xml_err(_response_body, output)
51                    .map_err(crate::operation::get_delegated_access_token::GetDelegatedAccessTokenError::unhandled)?;
52                let output = output.meta(generic);
53                output.build()
54            };
55            if tmp.message.is_none() {
56                tmp.message = _error_message;
57            }
58            tmp
59        }),
60        _ => crate::operation::get_delegated_access_token::GetDelegatedAccessTokenError::generic(generic),
61    })
62}
63
64#[allow(clippy::unnecessary_wraps)]
65pub fn de_get_delegated_access_token_http_response(
66    _response_status: u16,
67    _response_headers: &::aws_smithy_runtime_api::http::Headers,
68    _response_body: &[u8],
69) -> std::result::Result<
70    crate::operation::get_delegated_access_token::GetDelegatedAccessTokenOutput,
71    crate::operation::get_delegated_access_token::GetDelegatedAccessTokenError,
72> {
73    Ok({
74        #[allow(unused_mut)]
75        let mut output = crate::operation::get_delegated_access_token::builders::GetDelegatedAccessTokenOutputBuilder::default();
76        output = crate::protocol_serde::shape_get_delegated_access_token::de_get_delegated_access_token(_response_body, output)
77            .map_err(crate::operation::get_delegated_access_token::GetDelegatedAccessTokenError::unhandled)?;
78        output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
79        output.build()
80    })
81}
82
83#[allow(unused_mut)]
84pub fn de_get_delegated_access_token(
85    inp: &[u8],
86    mut builder: crate::operation::get_delegated_access_token::builders::GetDelegatedAccessTokenOutputBuilder,
87) -> std::result::Result<
88    crate::operation::get_delegated_access_token::builders::GetDelegatedAccessTokenOutputBuilder,
89    ::aws_smithy_xml::decode::XmlDecodeError,
90> {
91    let mut doc = ::aws_smithy_xml::decode::Document::try_from(inp)?;
92
93    #[allow(unused_mut)]
94    let mut decoder = doc.root_element()?;
95    #[allow(unused_variables)]
96    let start_el = decoder.start_el();
97    if !(start_el.matches("GetDelegatedAccessTokenResponse")) {
98        return Err(::aws_smithy_xml::decode::XmlDecodeError::custom(format!(
99            "invalid root, expected GetDelegatedAccessTokenResponse got {start_el:?}"
100        )));
101    }
102    if let Some(mut result_tag) = decoder.next_tag() {
103        let start_el = result_tag.start_el();
104        if !(start_el.matches("GetDelegatedAccessTokenResult")) {
105            return Err(::aws_smithy_xml::decode::XmlDecodeError::custom(format!(
106                "invalid result, expected GetDelegatedAccessTokenResult got {start_el:?}"
107            )));
108        }
109        while let Some(mut tag) = result_tag.next_tag() {
110            match tag.start_el() {
111            s if s.matches("Credentials") /* Credentials com.amazonaws.sts.synthetic#GetDelegatedAccessTokenOutput$Credentials */ =>  {
112                let var_1 =
113                    Some(
114                        crate::protocol_serde::shape_credentials::de_credentials(&mut tag)
115                        ?
116                    )
117                ;
118                builder = builder.set_credentials(var_1);
119            }
120            ,
121            s if s.matches("PackedPolicySize") /* PackedPolicySize com.amazonaws.sts.synthetic#GetDelegatedAccessTokenOutput$PackedPolicySize */ =>  {
122                let var_2 =
123                    Some(
124                         {
125                            <i32 as ::aws_smithy_types::primitive::Parse>::parse_smithy_primitive(
126                                ::aws_smithy_xml::decode::try_data(&mut tag)?.as_ref()
127                            )
128                            .map_err(|_|::aws_smithy_xml::decode::XmlDecodeError::custom("expected (integer: `com.amazonaws.sts#nonNegativeIntegerType`)"))
129                        }
130                        ?
131                    )
132                ;
133                builder = builder.set_packed_policy_size(var_2);
134            }
135            ,
136            s if s.matches("AssumedPrincipal") /* AssumedPrincipal com.amazonaws.sts.synthetic#GetDelegatedAccessTokenOutput$AssumedPrincipal */ =>  {
137                let var_3 =
138                    Some(
139                        Result::<::std::string::String, ::aws_smithy_xml::decode::XmlDecodeError>::Ok(
140                            ::aws_smithy_xml::decode::try_data(&mut tag)?.as_ref()
141                            .into()
142                        )
143                        ?
144                    )
145                ;
146                builder = builder.set_assumed_principal(var_3);
147            }
148            ,
149            _ => {}
150        }
151        }
152    } else {
153        return Err(::aws_smithy_xml::decode::XmlDecodeError::custom(
154            "expected GetDelegatedAccessTokenResult tag",
155        ));
156    };
157    Ok(builder)
158}