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 55 56 57 58 59 60 61 62 63 64 65 66 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 122 123 124 125 126 127 128 129 130
use crate::hmac_key::{HmacKey, HmacMeta, HmacState};
/// Operations on [`HmacKey`](HmacKey)s.
#[derive(Debug)]
pub struct HmacKeyClient<'a>(pub(super) &'a super::Client);
impl<'a> HmacKeyClient<'a> {
/// Creates a new HMAC key for the specified service account.
///
/// The authenticated user must have `storage.hmacKeys.create` permission for the project in
/// which the key will be created.
///
/// For general information about HMAC keys in Cloud Storage, see
/// [HMAC Keys](https://cloud.google.com/storage/docs/authentication/hmackeys).
/// ### Example
/// ```
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use cloud_storage::sync::Client;
/// use cloud_storage::hmac_key::HmacKey;
///
/// let client = Client::new()?;
/// let hmac_key = client.hmac_key().create()?;
/// # use cloud_storage::hmac_key::HmacState;
/// # client.hmac_key().update(&hmac_key.metadata.access_id, HmacState::Inactive)?;
/// # client.hmac_key().delete(&hmac_key.metadata.access_id)?;
/// # Ok(())
/// # }
/// ```
pub fn create(&self) -> crate::Result<HmacKey> {
self.0.runtime.block_on(self.0.client.hmac_key().create())
}
/// Retrieves a list of HMAC keys matching the criteria. Since the HmacKey is secret, this does
/// not return a `HmacKey`, but a `HmacMeta`. This is a redacted version of a `HmacKey`, but
/// with the secret data omitted.
///
/// The authenticated user must have `storage.hmacKeys.list` permission for the project in which
/// the key exists.
///
/// For general information about HMAC keys in Cloud Storage, see
/// [HMAC Keys](https://cloud.google.com/storage/docs/authentication/hmackeys).
/// ### Example
/// ```
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use cloud_storage::sync::Client;
/// use cloud_storage::hmac_key::HmacKey;
///
/// let client = Client::new()?;
/// let all_hmac_keys = client.hmac_key().list()?;
/// # Ok(())
/// # }
/// ```
pub fn list(&self) -> crate::Result<Vec<HmacMeta>> {
self.0.runtime.block_on(self.0.client.hmac_key().list())
}
/// Retrieves an HMAC key's metadata. Since the HmacKey is secret, this does not return a
/// `HmacKey`, but a `HmacMeta`. This is a redacted version of a `HmacKey`, but with the secret
/// data omitted.
///
/// The authenticated user must have `storage.hmacKeys.get` permission for the project in which
/// the key exists.
///
/// For general information about HMAC keys in Cloud Storage, see
/// [HMAC Keys](https://cloud.google.com/storage/docs/authentication/hmackeys).
/// ### Example
/// ```no_run
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use cloud_storage::sync::Client;
/// use cloud_storage::hmac_key::HmacKey;
///
/// let client = Client::new()?;
/// let key = client.hmac_key().read("some identifier")?;
/// # Ok(())
/// # }
pub fn read(&self, access_id: &str) -> crate::Result<HmacMeta> {
self.0
.runtime
.block_on(self.0.client.hmac_key().read(access_id))
}
/// Updates the state of an HMAC key. See the HMAC Key resource descriptor for valid states.
/// Since the HmacKey is secret, this does not return a `HmacKey`, but a `HmacMeta`. This is a
/// redacted version of a `HmacKey`, but with the secret data omitted.
///
/// The authenticated user must have `storage.hmacKeys.update` permission for the project in
/// which the key exists.
///
/// For general information about HMAC keys in Cloud Storage, see
/// [HMAC Keys](https://cloud.google.com/storage/docs/authentication/hmackeys).
/// ### Example
/// ```no_run
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use cloud_storage::sync::Client;
/// use cloud_storage::hmac_key::{HmacKey, HmacState};
///
/// let client = Client::new()?;
/// let key = client.hmac_key().update("your key", HmacState::Active)?;
/// # Ok(())
/// # }
pub fn update(&self, access_id: &str, state: HmacState) -> crate::Result<HmacMeta> {
self.0
.runtime
.block_on(self.0.client.hmac_key().update(access_id, state))
}
/// Deletes an HMAC key. Note that a key must be set to `Inactive` first.
///
/// The authenticated user must have storage.hmacKeys.delete permission for the project in which
/// the key exists.
///
/// For general information about HMAC keys in Cloud Storage, see
/// [HMAC Keys](https://cloud.google.com/storage/docs/authentication/hmackeys).
/// ### Example
/// ```no_run
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use cloud_storage::sync::Client;
/// use cloud_storage::hmac_key::{HmacKey, HmacState};
///
/// let client = Client::new()?;
/// let key = client.hmac_key().update("your key", HmacState::Inactive)?; // this is required.
/// client.hmac_key().delete(&key.access_id)?;
/// # Ok(())
/// # }
pub fn delete(&self, access_id: &str) -> crate::Result<()> {
self.0
.runtime
.block_on(self.0.client.hmac_key().delete(access_id))
}
}