Struct aws_manager::kms::Key
source · Expand description
Represents the KMS CMK.
Fields§
§id: String§arn: StringImplementations§
source§impl Key
impl Key
sourcepub fn new(id: &str, arn: &str) -> Self
pub fn new(id: &str, arn: &str) -> Self
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))
}