From 35eab3ccee78f75f8731f27c5873f92cfaf835b5 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 6 Feb 2017 13:11:14 -0800 Subject: [PATCH] adds KMS region tags --- kms/src/main/java/com/example/CryptFile.java | 4 ++++ kms/src/main/java/com/example/Snippets.java | 24 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/kms/src/main/java/com/example/CryptFile.java b/kms/src/main/java/com/example/CryptFile.java index 094aec04a55..f0c59d844ae 100644 --- a/kms/src/main/java/com/example/CryptFile.java +++ b/kms/src/main/java/com/example/CryptFile.java @@ -71,6 +71,7 @@ public static byte[] encrypt(String projectId, String ringId, String keyId, byte return encrypt(projectId, ringId, keyId, null, plaintext); } + // [START kms_encrypt] /** * Encrypts the given bytes, using the specified crypto key version. */ @@ -95,7 +96,9 @@ public static byte[] encrypt( return response.decodeCiphertext(); } + // [END kms_encrypt] + // [START kms_decrypt] /** * Decrypts the given encrypted bytes, using the specified crypto key. */ @@ -117,6 +120,7 @@ public static byte[] decrypt(String projectId, String ringId, String keyId, byte return response.decodePlaintext(); } + // [END kms_decrypt] public static void main(String[] args) throws IOException { CryptFileCommands commands = new CryptFileCommands(); diff --git a/kms/src/main/java/com/example/Snippets.java b/kms/src/main/java/com/example/Snippets.java index 42dd7329cd7..a6bb89b671d 100644 --- a/kms/src/main/java/com/example/Snippets.java +++ b/kms/src/main/java/com/example/Snippets.java @@ -67,6 +67,7 @@ public static CloudKMS createAuthorizedClient() throws IOException { .build(); } + // [START kms_create_keyring] /** * Creates a new key ring with the given id. */ @@ -86,7 +87,9 @@ public static KeyRing createKeyRing(String projectId, String ringId) throws IOEx System.out.println(keyring); return keyring; } + // [END kms_create_keyring] + // [START kms_create_cryptokey] /** * Creates a new crypto key with the given id. */ @@ -114,7 +117,9 @@ public static CryptoKey createCryptoKey(String projectId, String ringId, String System.out.println(createdKey); return createdKey; } + // [END kms_create_cryptokey] + // [START kms_create_cryptokey_version] /** * Creates a new crypto key version for the given id. */ @@ -138,7 +143,9 @@ public static void createCryptoKeyVersion( System.out.println(newVersion); } + // [END kms_create_cryptokey_version] + // [START kms_disable_cryptokey_version] /** * Disables the given version of the crypto key. */ @@ -166,7 +173,9 @@ public static CryptoKeyVersion disableCryptoKeyVersion( System.out.println(response); return response; } + // [END kms_disable_cryptokey_version] + // [START kms_destroy_cryptokey_version] /** * Marks the given version of a crypto key to be destroyed at a scheduled future point. */ @@ -192,7 +201,9 @@ public static CryptoKeyVersion destroyCryptoKeyVersion( System.out.println(destroyed); return destroyed; } + // [END kms_destroy_cryptokey_version] + // [START kms_get_cryptokey_policy] /** * Retrieves the IAM policy for the given crypto key. */ @@ -215,7 +226,9 @@ public static Policy getCryptoKeyPolicy(String projectId, String ringId, String System.out.println(iamPolicy.getBindings()); return iamPolicy; } + // [END kms_get_cryptokey_policy] + // [START kms_get_keyring_policy] /** * Retrieves the IAM policy for the given crypto key. */ @@ -237,7 +250,9 @@ public static Policy getKeyRingPolicy(String projectId, String ringId) throws IO System.out.println(iamPolicy.getBindings()); return iamPolicy; } + // [END kms_get_keyring_policy] + // [START kms_add_member_to_cryptokey_policy] /** * Adds the given member to the given key, with the given role. * @@ -296,7 +311,9 @@ public static Policy addMemberToCryptoKeyPolicy( System.out.println("Response: " + newIamPolicy); return newIamPolicy; } + // [END kms_add_member_to_cryptokey_policy] + // [START kms_add_member_to_keyring_policy] /** * Adds the given member to the given keyring, with the given role. * @@ -354,7 +371,9 @@ public static Policy addMemberToKeyRingPolicy( System.out.println("Response: " + newIamPolicy); return newIamPolicy; } + // [END kms_add_member_to_keyring_policy] + // [START kms_remove_member_from_cryptokey_policy] /** * Removes the given member from the given policy. */ @@ -395,7 +414,9 @@ public static Policy removeMemberFromCryptoKeyPolicy( System.out.println("Response: " + newIamPolicy); return newIamPolicy; } + // [END kms_remove_member_from_cryptokey_policy] + // [START kms_remove_member_from_keyring_policy] /** * Removes the given member from the given policy. */ @@ -431,7 +452,9 @@ public static Policy removeMemberFromKeyRingPolicy( System.out.println("Response: " + newIamPolicy); return newIamPolicy; } + // [END kms_remove_member_from_keyring_policy] + // [START kms_quickstart] /** * Prints all the keyrings in the given project. */ @@ -461,6 +484,7 @@ public static void listKeyRings(String projectId) throws IOException { System.out.println("No keyrings defined."); } } + // [END kms_quickstart] /** * Prints all the keys in the given key ring.