Skip to content

Commit 35eab3c

Browse files
committed
adds KMS region tags
1 parent 4ea0be3 commit 35eab3c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

kms/src/main/java/com/example/CryptFile.java

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public static byte[] encrypt(String projectId, String ringId, String keyId, byte
7171
return encrypt(projectId, ringId, keyId, null, plaintext);
7272
}
7373

74+
// [START kms_encrypt]
7475
/**
7576
* Encrypts the given bytes, using the specified crypto key version.
7677
*/
@@ -95,7 +96,9 @@ public static byte[] encrypt(
9596

9697
return response.decodeCiphertext();
9798
}
99+
// [END kms_encrypt]
98100

101+
// [START kms_decrypt]
99102
/**
100103
* Decrypts the given encrypted bytes, using the specified crypto key.
101104
*/
@@ -117,6 +120,7 @@ public static byte[] decrypt(String projectId, String ringId, String keyId, byte
117120

118121
return response.decodePlaintext();
119122
}
123+
// [END kms_decrypt]
120124

121125
public static void main(String[] args) throws IOException {
122126
CryptFileCommands commands = new CryptFileCommands();

kms/src/main/java/com/example/Snippets.java

+24
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public static CloudKMS createAuthorizedClient() throws IOException {
6767
.build();
6868
}
6969

70+
// [START kms_create_keyring]
7071
/**
7172
* Creates a new key ring with the given id.
7273
*/
@@ -86,7 +87,9 @@ public static KeyRing createKeyRing(String projectId, String ringId) throws IOEx
8687
System.out.println(keyring);
8788
return keyring;
8889
}
90+
// [END kms_create_keyring]
8991

92+
// [START kms_create_cryptokey]
9093
/**
9194
* Creates a new crypto key with the given id.
9295
*/
@@ -114,7 +117,9 @@ public static CryptoKey createCryptoKey(String projectId, String ringId, String
114117
System.out.println(createdKey);
115118
return createdKey;
116119
}
120+
// [END kms_create_cryptokey]
117121

122+
// [START kms_create_cryptokey_version]
118123
/**
119124
* Creates a new crypto key version for the given id.
120125
*/
@@ -138,7 +143,9 @@ public static void createCryptoKeyVersion(
138143

139144
System.out.println(newVersion);
140145
}
146+
// [END kms_create_cryptokey_version]
141147

148+
// [START kms_disable_cryptokey_version]
142149
/**
143150
* Disables the given version of the crypto key.
144151
*/
@@ -166,7 +173,9 @@ public static CryptoKeyVersion disableCryptoKeyVersion(
166173
System.out.println(response);
167174
return response;
168175
}
176+
// [END kms_disable_cryptokey_version]
169177

178+
// [START kms_destroy_cryptokey_version]
170179
/**
171180
* Marks the given version of a crypto key to be destroyed at a scheduled future point.
172181
*/
@@ -192,7 +201,9 @@ public static CryptoKeyVersion destroyCryptoKeyVersion(
192201
System.out.println(destroyed);
193202
return destroyed;
194203
}
204+
// [END kms_destroy_cryptokey_version]
195205

206+
// [START kms_get_cryptokey_policy]
196207
/**
197208
* Retrieves the IAM policy for the given crypto key.
198209
*/
@@ -215,7 +226,9 @@ public static Policy getCryptoKeyPolicy(String projectId, String ringId, String
215226
System.out.println(iamPolicy.getBindings());
216227
return iamPolicy;
217228
}
229+
// [END kms_get_cryptokey_policy]
218230

231+
// [START kms_get_keyring_policy]
219232
/**
220233
* Retrieves the IAM policy for the given crypto key.
221234
*/
@@ -237,7 +250,9 @@ public static Policy getKeyRingPolicy(String projectId, String ringId) throws IO
237250
System.out.println(iamPolicy.getBindings());
238251
return iamPolicy;
239252
}
253+
// [END kms_get_keyring_policy]
240254

255+
// [START kms_add_member_to_cryptokey_policy]
241256
/**
242257
* Adds the given member to the given key, with the given role.
243258
*
@@ -296,7 +311,9 @@ public static Policy addMemberToCryptoKeyPolicy(
296311
System.out.println("Response: " + newIamPolicy);
297312
return newIamPolicy;
298313
}
314+
// [END kms_add_member_to_cryptokey_policy]
299315

316+
// [START kms_add_member_to_keyring_policy]
300317
/**
301318
* Adds the given member to the given keyring, with the given role.
302319
*
@@ -354,7 +371,9 @@ public static Policy addMemberToKeyRingPolicy(
354371
System.out.println("Response: " + newIamPolicy);
355372
return newIamPolicy;
356373
}
374+
// [END kms_add_member_to_keyring_policy]
357375

376+
// [START kms_remove_member_from_cryptokey_policy]
358377
/**
359378
* Removes the given member from the given policy.
360379
*/
@@ -395,7 +414,9 @@ public static Policy removeMemberFromCryptoKeyPolicy(
395414
System.out.println("Response: " + newIamPolicy);
396415
return newIamPolicy;
397416
}
417+
// [END kms_remove_member_from_cryptokey_policy]
398418

419+
// [START kms_remove_member_from_keyring_policy]
399420
/**
400421
* Removes the given member from the given policy.
401422
*/
@@ -431,7 +452,9 @@ public static Policy removeMemberFromKeyRingPolicy(
431452
System.out.println("Response: " + newIamPolicy);
432453
return newIamPolicy;
433454
}
455+
// [END kms_remove_member_from_keyring_policy]
434456

457+
// [START kms_quickstart]
435458
/**
436459
* Prints all the keyrings in the given project.
437460
*/
@@ -461,6 +484,7 @@ public static void listKeyRings(String projectId) throws IOException {
461484
System.out.println("No keyrings defined.");
462485
}
463486
}
487+
// [END kms_quickstart]
464488

465489
/**
466490
* Prints all the keys in the given key ring.

0 commit comments

Comments
 (0)