Skip to content

Commit

Permalink
adds KMS region tags
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Feb 6, 2017
1 parent 4ea0be3 commit 35eab3c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions kms/src/main/java/com/example/CryptFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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.
*/
Expand All @@ -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();
Expand Down
24 changes: 24 additions & 0 deletions kms/src/main/java/com/example/Snippets.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public static CloudKMS createAuthorizedClient() throws IOException {
.build();
}

// [START kms_create_keyring]
/**
* Creates a new key ring with the given id.
*/
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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.
*/
Expand All @@ -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.
*/
Expand All @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 35eab3c

Please sign in to comment.