cloud_storage/sync/
hmac_key.rs

1use crate::hmac_key::{HmacKey, HmacMeta, HmacState};
2
3/// Operations on [`HmacKey`](HmacKey)s.
4#[derive(Debug)]
5pub struct HmacKeyClient<'a>(pub(super) &'a super::Client);
6
7impl<'a> HmacKeyClient<'a> {
8    /// Creates a new HMAC key for the specified service account.
9    ///
10    /// The authenticated user must have `storage.hmacKeys.create` permission for the project in
11    /// which the key will be created.
12    ///
13    /// For general information about HMAC keys in Cloud Storage, see
14    /// [HMAC Keys](https://cloud.google.com/storage/docs/authentication/hmackeys).
15    /// ### Example
16    /// ```
17    /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
18    /// use cloud_storage::sync::Client;
19    /// use cloud_storage::hmac_key::HmacKey;
20    ///
21    /// let client = Client::new()?;
22    /// let hmac_key = client.hmac_key().create()?;
23    /// # use cloud_storage::hmac_key::HmacState;
24    /// # client.hmac_key().update(&hmac_key.metadata.access_id, HmacState::Inactive)?;
25    /// # client.hmac_key().delete(&hmac_key.metadata.access_id)?;
26    /// # Ok(())
27    /// # }
28    /// ```
29    pub fn create(&self) -> crate::Result<HmacKey> {
30        self.0.runtime.block_on(self.0.client.hmac_key().create())
31    }
32
33    /// Retrieves a list of HMAC keys matching the criteria. Since the HmacKey is secret, this does
34    /// not return a `HmacKey`, but a `HmacMeta`. This is a redacted version of a `HmacKey`, but
35    /// with the secret data omitted.
36    ///
37    /// The authenticated user must have `storage.hmacKeys.list` permission for the project in which
38    /// the key exists.
39    ///
40    /// For general information about HMAC keys in Cloud Storage, see
41    /// [HMAC Keys](https://cloud.google.com/storage/docs/authentication/hmackeys).
42    /// ### Example
43    /// ```
44    /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
45    /// use cloud_storage::sync::Client;
46    /// use cloud_storage::hmac_key::HmacKey;
47    ///
48    /// let client = Client::new()?;
49    /// let all_hmac_keys = client.hmac_key().list()?;
50    /// # Ok(())
51    /// # }
52    /// ```
53    pub fn list(&self) -> crate::Result<Vec<HmacMeta>> {
54        self.0.runtime.block_on(self.0.client.hmac_key().list())
55    }
56
57    /// Retrieves an HMAC key's metadata. Since the HmacKey is secret, this does not return a
58    /// `HmacKey`, but a `HmacMeta`. This is a redacted version of a `HmacKey`, but with the secret
59    /// data omitted.
60    ///
61    /// The authenticated user must have `storage.hmacKeys.get` permission for the project in which
62    /// the key exists.
63    ///
64    /// For general information about HMAC keys in Cloud Storage, see
65    /// [HMAC Keys](https://cloud.google.com/storage/docs/authentication/hmackeys).
66    /// ### Example
67    /// ```no_run
68    /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
69    /// use cloud_storage::sync::Client;
70    /// use cloud_storage::hmac_key::HmacKey;
71    ///
72    /// let client = Client::new()?;
73    /// let key = client.hmac_key().read("some identifier")?;
74    /// # Ok(())
75    /// # }
76    pub fn read(&self, access_id: &str) -> crate::Result<HmacMeta> {
77        self.0
78            .runtime
79            .block_on(self.0.client.hmac_key().read(access_id))
80    }
81
82    /// Updates the state of an HMAC key. See the HMAC Key resource descriptor for valid states.
83    /// Since the HmacKey is secret, this does not return a `HmacKey`, but a `HmacMeta`. This is a
84    /// redacted version of a `HmacKey`, but with the secret data omitted.
85    ///
86    /// The authenticated user must have `storage.hmacKeys.update` permission for the project in
87    /// which the key exists.
88    ///
89    /// For general information about HMAC keys in Cloud Storage, see
90    /// [HMAC Keys](https://cloud.google.com/storage/docs/authentication/hmackeys).
91    /// ### Example
92    /// ```no_run
93    /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
94    /// use cloud_storage::sync::Client;
95    /// use cloud_storage::hmac_key::{HmacKey, HmacState};
96    ///
97    /// let client = Client::new()?;
98    /// let key = client.hmac_key().update("your key", HmacState::Active)?;
99    /// # Ok(())
100    /// # }
101    pub fn update(&self, access_id: &str, state: HmacState) -> crate::Result<HmacMeta> {
102        self.0
103            .runtime
104            .block_on(self.0.client.hmac_key().update(access_id, state))
105    }
106
107    /// Deletes an HMAC key. Note that a key must be set to `Inactive` first.
108    ///
109    /// The authenticated user must have storage.hmacKeys.delete permission for the project in which
110    /// the key exists.
111    ///
112    /// For general information about HMAC keys in Cloud Storage, see
113    /// [HMAC Keys](https://cloud.google.com/storage/docs/authentication/hmackeys).
114    /// ### Example
115    /// ```no_run
116    /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
117    /// use cloud_storage::sync::Client;
118    /// use cloud_storage::hmac_key::{HmacKey, HmacState};
119    ///
120    /// let client = Client::new()?;
121    /// let key = client.hmac_key().update("your key", HmacState::Inactive)?; // this is required.
122    /// client.hmac_key().delete(&key.access_id)?;
123    /// # Ok(())
124    /// # }
125    pub fn delete(&self, access_id: &str) -> crate::Result<()> {
126        self.0
127            .runtime
128            .block_on(self.0.client.hmac_key().delete(access_id))
129    }
130}