Skip to main content

fakecloud_kms/
state.rs

1use std::collections::HashMap;
2use std::sync::Arc;
3
4use parking_lot::RwLock;
5
6pub type SharedKmsState = Arc<RwLock<KmsState>>;
7
8pub struct KmsState {
9    pub account_id: String,
10    pub region: String,
11    pub keys: HashMap<String, KmsKey>,
12    pub aliases: HashMap<String, KmsAlias>,
13    pub grants: Vec<KmsGrant>,
14    pub custom_key_stores: HashMap<String, CustomKeyStore>,
15}
16
17impl KmsState {
18    pub fn new(account_id: &str, region: &str) -> Self {
19        Self {
20            account_id: account_id.to_string(),
21            region: region.to_string(),
22            keys: HashMap::new(),
23            aliases: HashMap::new(),
24            grants: Vec::new(),
25            custom_key_stores: HashMap::new(),
26        }
27    }
28
29    pub fn reset(&mut self) {
30        self.keys.clear();
31        self.aliases.clear();
32        self.grants.clear();
33        self.custom_key_stores.clear();
34    }
35}
36
37pub struct KmsKey {
38    pub key_id: String,
39    pub arn: String,
40    pub creation_date: f64,
41    pub description: String,
42    pub enabled: bool,
43    pub key_usage: String,
44    pub key_spec: String,
45    pub key_manager: String,
46    pub key_state: String,
47    pub deletion_date: Option<f64>,
48    pub tags: HashMap<String, String>,
49    pub policy: String,
50    pub key_rotation_enabled: bool,
51    pub origin: String,
52    pub multi_region: bool,
53    pub rotations: Vec<KeyRotation>,
54    pub signing_algorithms: Option<Vec<String>>,
55    pub encryption_algorithms: Option<Vec<String>>,
56    pub mac_algorithms: Option<Vec<String>>,
57    pub custom_key_store_id: Option<String>,
58    pub imported_key_material: bool,
59    pub primary_region: Option<String>,
60}
61
62pub struct KmsAlias {
63    pub alias_name: String,
64    pub alias_arn: String,
65    pub target_key_id: String,
66    pub creation_date: f64,
67}
68
69pub struct KmsGrant {
70    pub grant_id: String,
71    pub grant_token: String,
72    pub key_id: String,
73    pub grantee_principal: String,
74    pub retiring_principal: Option<String>,
75    pub operations: Vec<String>,
76    pub constraints: Option<serde_json::Value>,
77    pub name: Option<String>,
78    pub creation_date: f64,
79}
80
81pub struct KeyRotation {
82    pub key_id: String,
83    pub rotation_date: f64,
84    pub rotation_type: String,
85}
86
87pub struct CustomKeyStore {
88    pub custom_key_store_id: String,
89    pub custom_key_store_name: String,
90    pub custom_key_store_type: String,
91    pub cloud_hsm_cluster_id: Option<String>,
92    pub trust_anchor_certificate: Option<String>,
93    pub connection_state: String,
94    pub creation_date: f64,
95    pub xks_proxy_uri_endpoint: Option<String>,
96    pub xks_proxy_uri_path: Option<String>,
97    pub xks_proxy_vpc_endpoint_service_name: Option<String>,
98    pub xks_proxy_connectivity: Option<String>,
99}