pub struct KeyManagementService { /* private fields */ }Expand description
Implements a client for the Cloud Key Management Service (KMS) API.
§Example
use google_cloud_gax::paginator::ItemPaginator as _;
let client = KeyManagementService::builder().build().await?;
let parent = "parent_value";
let mut list = client.list_key_rings()
.set_parent(parent)
.by_item();
while let Some(item) = list.next().await.transpose()? {
println!("{:?}", item);
}§Service Description
Google Cloud Key Management Service
Manages cryptographic keys and operations using those keys. Implements a REST model with the following objects:
If you are using manual gRPC libraries, see Using gRPC with Cloud KMS.
§Configuration
To configure KeyManagementService use the with_* methods in the type returned
by builder(). The default configuration should
work for most applications. Common configuration changes include
- with_endpoint(): by default this client uses the global default endpoint
(
https://cloudkms.googleapis.com). Applications using regional endpoints or running in restricted networks (e.g. a network configured override this default. - with_credentials(): by default this client uses Application Default Credentials. Applications using custom authentication may need to override this default.
§Pooling and Cloning
KeyManagementService holds a connection pool internally, it is advised to
create one and reuse it. You do not need to wrap KeyManagementService in
an Rc or Arc to reuse it, because it
already uses an Arc internally.
Implementations§
Source§impl KeyManagementService
impl KeyManagementService
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Returns a builder for KeyManagementService.
let client = KeyManagementService::builder().build().await?;Sourcepub fn from_stub<T>(stub: T) -> Selfwhere
T: KeyManagementService + 'static,
pub fn from_stub<T>(stub: T) -> Selfwhere
T: KeyManagementService + 'static,
Creates a new client from the provided stub.
The most common case for calling this function is in tests mocking the client’s behavior.
Sourcepub fn list_key_rings(&self) -> ListKeyRings
pub fn list_key_rings(&self) -> ListKeyRings
Lists KeyRings.
§Example
use google_cloud_gax::paginator::ItemPaginator as _;
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, parent: &str
) -> Result<()> {
let mut list = client.list_key_rings()
.set_parent(parent)
.by_item();
while let Some(item) = list.next().await.transpose()? {
println!("{:?}", item);
}
Ok(())
}Sourcepub fn list_crypto_keys(&self) -> ListCryptoKeys
pub fn list_crypto_keys(&self) -> ListCryptoKeys
Lists CryptoKeys.
§Example
use google_cloud_gax::paginator::ItemPaginator as _;
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, parent: &str
) -> Result<()> {
let mut list = client.list_crypto_keys()
.set_parent(parent)
.by_item();
while let Some(item) = list.next().await.transpose()? {
println!("{:?}", item);
}
Ok(())
}Sourcepub fn list_crypto_key_versions(&self) -> ListCryptoKeyVersions
pub fn list_crypto_key_versions(&self) -> ListCryptoKeyVersions
Lists CryptoKeyVersions.
§Example
use google_cloud_gax::paginator::ItemPaginator as _;
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, parent: &str
) -> Result<()> {
let mut list = client.list_crypto_key_versions()
.set_parent(parent)
.by_item();
while let Some(item) = list.next().await.transpose()? {
println!("{:?}", item);
}
Ok(())
}Sourcepub fn list_import_jobs(&self) -> ListImportJobs
pub fn list_import_jobs(&self) -> ListImportJobs
Lists ImportJobs.
§Example
use google_cloud_gax::paginator::ItemPaginator as _;
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, parent: &str
) -> Result<()> {
let mut list = client.list_import_jobs()
.set_parent(parent)
.by_item();
while let Some(item) = list.next().await.transpose()? {
println!("{:?}", item);
}
Ok(())
}Sourcepub fn list_retired_resources(&self) -> ListRetiredResources
pub fn list_retired_resources(&self) -> ListRetiredResources
Lists the RetiredResources which are the records of deleted CryptoKeys. RetiredResources prevent the reuse of these resource names after deletion.
§Example
use google_cloud_gax::paginator::ItemPaginator as _;
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, parent: &str
) -> Result<()> {
let mut list = client.list_retired_resources()
.set_parent(parent)
.by_item();
while let Some(item) = list.next().await.transpose()? {
println!("{:?}", item);
}
Ok(())
}Sourcepub fn get_key_ring(&self) -> GetKeyRing
pub fn get_key_ring(&self) -> GetKeyRing
Sourcepub fn get_crypto_key(&self) -> GetCryptoKey
pub fn get_crypto_key(&self) -> GetCryptoKey
Returns metadata for a given CryptoKey, as well as its primary CryptoKeyVersion.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, name: &str
) -> Result<()> {
let response = client.get_crypto_key()
.set_name(name)
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn get_crypto_key_version(&self) -> GetCryptoKeyVersion
pub fn get_crypto_key_version(&self) -> GetCryptoKeyVersion
Returns metadata for a given CryptoKeyVersion.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, name: &str
) -> Result<()> {
let response = client.get_crypto_key_version()
.set_name(name)
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn get_public_key(&self) -> GetPublicKey
pub fn get_public_key(&self) -> GetPublicKey
Returns the public key for the given CryptoKeyVersion. The CryptoKey.purpose must be ASYMMETRIC_SIGN or ASYMMETRIC_DECRYPT.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.get_public_key()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn get_import_job(&self) -> GetImportJob
pub fn get_import_job(&self) -> GetImportJob
Sourcepub fn get_retired_resource(&self) -> GetRetiredResource
pub fn get_retired_resource(&self) -> GetRetiredResource
Retrieves a specific RetiredResource resource, which represents the record of a deleted CryptoKey.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, name: &str
) -> Result<()> {
let response = client.get_retired_resource()
.set_name(name)
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn create_key_ring(&self) -> CreateKeyRing
pub fn create_key_ring(&self) -> CreateKeyRing
Create a new KeyRing in a given Project and Location.
§Example
use google_cloud_kms_v1::model::KeyRing;
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, parent: &str
) -> Result<()> {
let response = client.create_key_ring()
.set_parent(parent)
.set_key_ring(
KeyRing::new()/* set fields */
)
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn create_crypto_key(&self) -> CreateCryptoKey
pub fn create_crypto_key(&self) -> CreateCryptoKey
Create a new CryptoKey within a KeyRing.
CryptoKey.purpose and CryptoKey.version_template.algorithm are required.
§Example
use google_cloud_kms_v1::model::CryptoKey;
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, parent: &str
) -> Result<()> {
let response = client.create_crypto_key()
.set_parent(parent)
.set_crypto_key(
CryptoKey::new()/* set fields */
)
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn create_crypto_key_version(&self) -> CreateCryptoKeyVersion
pub fn create_crypto_key_version(&self) -> CreateCryptoKeyVersion
Create a new CryptoKeyVersion in a CryptoKey.
The server will assign the next sequential id. If unset, state will be set to ENABLED.
§Example
use google_cloud_kms_v1::model::CryptoKeyVersion;
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, parent: &str
) -> Result<()> {
let response = client.create_crypto_key_version()
.set_parent(parent)
.set_crypto_key_version(
CryptoKeyVersion::new()/* set fields */
)
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn delete_crypto_key(&self) -> DeleteCryptoKey
pub fn delete_crypto_key(&self) -> DeleteCryptoKey
Permanently deletes the given CryptoKey. All child CryptoKeyVersions must have been previously deleted using KeyManagementService.DeleteCryptoKeyVersion. The specified crypto key will be immediately and permanently deleted upon calling this method. This action cannot be undone.
§Long running operations
This method is used to start, and/or poll a long-running Operation. The Working with long-running operations chapter in the user guide covers these operations in detail.
§Example
use google_cloud_lro::Poller;
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, name: &str
) -> Result<()> {
client.delete_crypto_key()
.set_name(name)
.poller().until_done().await?;
Ok(())
}Sourcepub fn delete_crypto_key_version(&self) -> DeleteCryptoKeyVersion
pub fn delete_crypto_key_version(&self) -> DeleteCryptoKeyVersion
Permanently deletes the given CryptoKeyVersion. Only possible if the version has not been previously imported and if its state is one of [DESTROYED][CryptoKeyVersionState.DESTROYED], [IMPORT_FAILED][CryptoKeyVersionState.IMPORT_FAILED], or [GENERATION_FAILED][CryptoKeyVersionState.GENERATION_FAILED]. Successfully imported CryptoKeyVersions cannot be deleted at this time. The specified version will be immediately and permanently deleted upon calling this method. This action cannot be undone.
§Long running operations
This method is used to start, and/or poll a long-running Operation. The Working with long-running operations chapter in the user guide covers these operations in detail.
§Example
use google_cloud_lro::Poller;
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, name: &str
) -> Result<()> {
client.delete_crypto_key_version()
.set_name(name)
.poller().until_done().await?;
Ok(())
}Sourcepub fn import_crypto_key_version(&self) -> ImportCryptoKeyVersion
pub fn import_crypto_key_version(&self) -> ImportCryptoKeyVersion
Import wrapped key material into a CryptoKeyVersion.
All requests must specify a CryptoKey. If a CryptoKeyVersion is additionally specified in the request, key material will be reimported into that version. Otherwise, a new version will be created, and will be assigned the next sequential id within the CryptoKey.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.import_crypto_key_version()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn create_import_job(&self) -> CreateImportJob
pub fn create_import_job(&self) -> CreateImportJob
Create a new ImportJob within a KeyRing.
ImportJob.import_method is required.
§Example
use google_cloud_kms_v1::model::ImportJob;
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, parent: &str
) -> Result<()> {
let response = client.create_import_job()
.set_parent(parent)
.set_import_job(
ImportJob::new()/* set fields */
)
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn update_crypto_key(&self) -> UpdateCryptoKey
pub fn update_crypto_key(&self) -> UpdateCryptoKey
Update a CryptoKey.
§Example
use google_cloud_wkt::FieldMask;
use google_cloud_kms_v1::model::CryptoKey;
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, name: &str
) -> Result<()> {
let response = client.update_crypto_key()
.set_crypto_key(
CryptoKey::new().set_name(name)/* set fields */
)
.set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn update_crypto_key_version(&self) -> UpdateCryptoKeyVersion
pub fn update_crypto_key_version(&self) -> UpdateCryptoKeyVersion
Update a CryptoKeyVersion’s metadata.
state may be changed between ENABLED and DISABLED using this method. See DestroyCryptoKeyVersion and RestoreCryptoKeyVersion to move between other states.
§Example
use google_cloud_wkt::FieldMask;
use google_cloud_kms_v1::model::CryptoKeyVersion;
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService, name: &str
) -> Result<()> {
let response = client.update_crypto_key_version()
.set_crypto_key_version(
CryptoKeyVersion::new().set_name(name)/* set fields */
)
.set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn update_crypto_key_primary_version(&self) -> UpdateCryptoKeyPrimaryVersion
pub fn update_crypto_key_primary_version(&self) -> UpdateCryptoKeyPrimaryVersion
Update the version of a CryptoKey that will be used in Encrypt.
Returns an error if called on a key whose purpose is not ENCRYPT_DECRYPT.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.update_crypto_key_primary_version()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn destroy_crypto_key_version(&self) -> DestroyCryptoKeyVersion
pub fn destroy_crypto_key_version(&self) -> DestroyCryptoKeyVersion
Schedule a CryptoKeyVersion for destruction.
Upon calling this method, CryptoKeyVersion.state will be set to DESTROY_SCHEDULED, and destroy_time will be set to the time destroy_scheduled_duration in the future. At that time, the state will automatically change to DESTROYED, and the key material will be irrevocably destroyed.
Before the destroy_time is reached, RestoreCryptoKeyVersion may be called to reverse the process.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.destroy_crypto_key_version()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn restore_crypto_key_version(&self) -> RestoreCryptoKeyVersion
pub fn restore_crypto_key_version(&self) -> RestoreCryptoKeyVersion
Restore a CryptoKeyVersion in the DESTROY_SCHEDULED state.
Upon restoration of the CryptoKeyVersion, state will be set to DISABLED, and destroy_time will be cleared.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.restore_crypto_key_version()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn encrypt(&self) -> Encrypt
pub fn encrypt(&self) -> Encrypt
Encrypts data, so that it can only be recovered by a call to Decrypt. The CryptoKey.purpose must be ENCRYPT_DECRYPT.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.encrypt()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn decrypt(&self) -> Decrypt
pub fn decrypt(&self) -> Decrypt
Decrypts data that was protected by Encrypt. The CryptoKey.purpose must be ENCRYPT_DECRYPT.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.decrypt()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn raw_encrypt(&self) -> RawEncrypt
pub fn raw_encrypt(&self) -> RawEncrypt
Encrypts data using portable cryptographic primitives. Most users should choose Encrypt and Decrypt rather than their raw counterparts. The CryptoKey.purpose must be RAW_ENCRYPT_DECRYPT.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.raw_encrypt()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn raw_decrypt(&self) -> RawDecrypt
pub fn raw_decrypt(&self) -> RawDecrypt
Decrypts data that was originally encrypted using a raw cryptographic mechanism. The CryptoKey.purpose must be RAW_ENCRYPT_DECRYPT.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.raw_decrypt()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn asymmetric_sign(&self) -> AsymmetricSign
pub fn asymmetric_sign(&self) -> AsymmetricSign
Signs data using a CryptoKeyVersion with CryptoKey.purpose ASYMMETRIC_SIGN, producing a signature that can be verified with the public key retrieved from GetPublicKey.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.asymmetric_sign()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn asymmetric_decrypt(&self) -> AsymmetricDecrypt
pub fn asymmetric_decrypt(&self) -> AsymmetricDecrypt
Decrypts data that was encrypted with a public key retrieved from GetPublicKey corresponding to a CryptoKeyVersion with CryptoKey.purpose ASYMMETRIC_DECRYPT.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.asymmetric_decrypt()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn mac_sign(&self) -> MacSign
pub fn mac_sign(&self) -> MacSign
Signs data using a CryptoKeyVersion with CryptoKey.purpose MAC, producing a tag that can be verified by another source with the same key.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.mac_sign()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn mac_verify(&self) -> MacVerify
pub fn mac_verify(&self) -> MacVerify
Verifies MAC tag using a CryptoKeyVersion with CryptoKey.purpose MAC, and returns a response that indicates whether or not the verification was successful.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.mac_verify()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn decapsulate(&self) -> Decapsulate
pub fn decapsulate(&self) -> Decapsulate
Decapsulates data that was encapsulated with a public key retrieved from GetPublicKey corresponding to a CryptoKeyVersion with CryptoKey.purpose KEY_ENCAPSULATION.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.decapsulate()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn generate_random_bytes(&self) -> GenerateRandomBytes
pub fn generate_random_bytes(&self) -> GenerateRandomBytes
Generate random bytes using the Cloud KMS randomness source in the provided location.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.generate_random_bytes()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn list_locations(&self) -> ListLocations
pub fn list_locations(&self) -> ListLocations
Lists information about the supported locations for this service. This method can be called in two ways:
- List all public locations: Use the path
GET /v1/locations. - List project-visible locations: Use the path
GET /v1/projects/{project_id}/locations. This may include public locations as well as private or other locations specifically visible to the project.
§Example
use google_cloud_gax::paginator::ItemPaginator as _;
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let mut list = client.list_locations()
/* set fields */
.by_item();
while let Some(item) = list.next().await.transpose()? {
println!("{:?}", item);
}
Ok(())
}Sourcepub fn get_location(&self) -> GetLocation
pub fn get_location(&self) -> GetLocation
Gets information about a location.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.get_location()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn set_iam_policy(&self) -> SetIamPolicy
pub fn set_iam_policy(&self) -> SetIamPolicy
Sets the access control policy on the specified resource. Replaces any existing policy.
Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
errors.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.set_iam_policy()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn get_iam_policy(&self) -> GetIamPolicy
pub fn get_iam_policy(&self) -> GetIamPolicy
Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.get_iam_policy()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn test_iam_permissions(&self) -> TestIamPermissions
pub fn test_iam_permissions(&self) -> TestIamPermissions
Returns permissions that a caller has on the specified resource. If the
resource does not exist, this will return an empty set of
permissions, not a NOT_FOUND error.
Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may “fail open” without warning.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.test_iam_permissions()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn get_operation(&self) -> GetOperation
pub fn get_operation(&self) -> GetOperation
Provides the Operations service functionality in this service.
§Example
use google_cloud_kms_v1::Result;
async fn sample(
client: &KeyManagementService
) -> Result<()> {
let response = client.get_operation()
/* set fields */
.send().await?;
println!("response {:?}", response);
Ok(())
}Trait Implementations§
Source§impl Clone for KeyManagementService
impl Clone for KeyManagementService
Source§fn clone(&self) -> KeyManagementService
fn clone(&self) -> KeyManagementService
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more