Struct aws_manager::kms::Key

source ·
pub struct Key {
    pub id: String,
    pub arn: String,
}
Expand description

Represents the KMS CMK.

Fields§

§id: String§arn: String

Implementations§

Examples found in repository?
src/kms/mod.rs (line 120)
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
    pub async fn create_key(
        &self,
        name: &str,
        key_spec: KeySpec,
        key_usage: KeyUsageType,
    ) -> Result<Key> {
        log::info!(
            "creating KMS CMK {}, key spec {:?}, key usage {:?}",
            name,
            key_spec,
            key_usage
        );
        let resp = self
            .cli
            .create_key()
            .description(name)
            // ref. https://docs.aws.amazon.com/kms/latest/developerguide/asymmetric-key-specs.html#key-spec-ecc
            // ref. https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateKey.html#API_CreateKey_RequestSyntax
            .key_spec(key_spec)
            // ref. https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateKey.html#KMS-CreateKey-request-KeyUsage
            .key_usage(key_usage)
            .tags(Tag::builder().tag_key("Name").tag_value(name).build())
            .tags(
                Tag::builder()
                    .tag_key("KIND")
                    .tag_value("aws-manager")
                    .build(),
            )
            .send()
            .await
            .map_err(|e| API {
                message: format!("failed create_key {:?}", e),
                is_retryable: is_error_retryable(&e) || is_error_retryable_create_key(&e),
            })?;

        let meta = match resp.key_metadata() {
            Some(v) => v,
            None => {
                return Err(Other {
                    message: String::from("unexpected empty key metadata"),
                    is_retryable: false,
                });
            }
        };

        let key_id = meta.key_id().unwrap_or("");
        let key_arn = meta.arn().unwrap_or("");
        log::info!(
            "successfully KMS CMK -- key Id '{}' and Arn '{}'",
            key_id,
            key_arn
        );

        Ok(Key::new(key_id, key_arn))
    }

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more