1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use super::*;

#[derive(Debug, Serialize)]
#[serde(rename_all = "PascalCase")]
struct CallerIdentity {
    user_id: String,
    account: String,
    arn: String,
}

impl Show for CallerIdentity {
    fn _fmt(&self) -> Box<dyn fmt::Display + '_> {
        todo!()
    }

    fn json(&self) -> String {
        json::to_string_pretty(self).unwrap_or_default()
    }
}

impl Show for aws_sdk_sts::operation::get_caller_identity::GetCallerIdentityOutput {
    fn _fmt(&self) -> Box<dyn fmt::Display + '_> {
        Box::new(fmtools::fmt!(
            { prefixed_item("ACCOUNT", self.account()) } " "
            { prefixed_item("USER_ID", self.user_id()) } " "
            { prefixed_item("ARN", self.arn()) }
        ))
    }

    fn json(&self) -> String {
        CallerIdentity::from(self).json()
    }
}

impl fmt::Display for CallerIdentity {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        format_args!("{} {} {}", self.account, self.user_id, self.arn).fmt(f)
    }
}

impl From<&aws_sdk_sts::operation::get_caller_identity::GetCallerIdentityOutput>
    for CallerIdentity
{
    fn from(output: &aws_sdk_sts::operation::get_caller_identity::GetCallerIdentityOutput) -> Self {
        let user_id = output.user_id().unwrap_or_default().to_string();
        let account = output.account().unwrap_or_default().to_string();
        let arn = output.arn().unwrap_or_default().to_string();
        Self {
            user_id,
            account,
            arn,
        }
    }
}