Search in sources :

Example 6 with KeyRing

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;
}
Also used : Policy(com.google.api.services.cloudkms.v1.model.Policy) CloudKMS(com.google.api.services.cloudkms.v1.CloudKMS)

Example 7 with KeyRing

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;
}
Also used : KeyRing(com.google.api.services.cloudkms.v1.model.KeyRing) CloudKMS(com.google.api.services.cloudkms.v1.CloudKMS)

Aggregations

CloudKMS (com.google.api.services.cloudkms.v1.CloudKMS)7 KeyRing (com.google.api.services.cloudkms.v1.model.KeyRing)3 Policy (com.google.api.services.cloudkms.v1.model.Policy)3 Binding (com.google.api.services.cloudkms.v1.model.Binding)2 ListKeyRingsResponse (com.google.api.services.cloudkms.v1.model.ListKeyRingsResponse)2 SetIamPolicyRequest (com.google.api.services.cloudkms.v1.model.SetIamPolicyRequest)2 CryptoKey (com.google.api.services.cloudkms.v1.model.CryptoKey)1