use of com.google.api.services.cloudkms.v1.model.KeyRing in project java-docs-samples by GoogleCloudPlatform.
the class Snippets method getKeyRingPolicy.
// [END kms_get_cryptokey_policy]
// [START kms_get_keyring_policy]
/**
* Retrieves the IAM policy for the given crypto key.
*/
public static Policy getKeyRingPolicy(String projectId, String locationId, String keyRingId) throws IOException {
// Create the Cloud KMS client.
CloudKMS kms = createAuthorizedClient();
// The resource name of the keyring
String keyring = String.format("projects/%s/locations/%s/keyRings/%s", projectId, locationId, keyRingId);
// Get the current IAM policy and add the new account to it.
Policy iamPolicy = kms.projects().locations().keyRings().getIamPolicy(keyring).execute();
System.out.println(iamPolicy.getBindings());
return iamPolicy;
}
use of com.google.api.services.cloudkms.v1.model.KeyRing in project java-docs-samples by GoogleCloudPlatform.
the class Snippets method createKeyRing.
// [START kms_create_keyring]
/**
* Creates a new key ring with the given id.
*/
public static KeyRing createKeyRing(String projectId, String locationId, String keyRingId) throws IOException {
// Create the Cloud KMS client.
CloudKMS kms = createAuthorizedClient();
// The resource name of the location associated with the KeyRing.
String parent = String.format("projects/%s/locations/%s", projectId, locationId);
// Create the KeyRing for your project.
KeyRing keyring = kms.projects().locations().keyRings().create(parent, new KeyRing()).setKeyRingId(keyRingId).execute();
System.out.println(keyring);
return keyring;
}
Aggregations