diff --git a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/KeyManagementServiceClient.java b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/KeyManagementServiceClient.java index 8568bd5d..47339b39 100644 --- a/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/KeyManagementServiceClient.java +++ b/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/KeyManagementServiceClient.java @@ -25,6 +25,7 @@ import com.google.api.gax.paging.AbstractPagedListResponse; import com.google.api.gax.rpc.PageContext; import com.google.api.gax.rpc.UnaryCallable; +import com.google.api.resourcenames.ResourceName; import com.google.cloud.kms.v1.stub.KeyManagementServiceStub; import com.google.cloud.kms.v1.stub.KeyManagementServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; @@ -1925,7 +1926,46 @@ public final CryptoKeyVersion updateCryptoKeyVersion(UpdateCryptoKeyVersionReque * *
* try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
- * CryptoKeyPathName name = CryptoKeyPathName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY_PATH]");
+ * ResourceName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
+ * ByteString plaintext = ByteString.copyFromUtf8("");
+ * EncryptResponse response = keyManagementServiceClient.encrypt(name, plaintext);
+ * }
+ *
+ *
+ * @param name Required. The resource name of the [CryptoKey][google.cloud.kms.v1.CryptoKey] or
+ * [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] to use for encryption.
+ * If a [CryptoKey][google.cloud.kms.v1.CryptoKey] is specified, the server will use its + * [primary version][google.cloud.kms.v1.CryptoKey.primary]. + * @param plaintext Required. The data to encrypt. Must be no larger than 64KiB. + *
The maximum size depends on the key version's + * [protection_level][google.cloud.kms.v1.CryptoKeyVersionTemplate.protection_level]. For + * [SOFTWARE][google.cloud.kms.v1.ProtectionLevel.SOFTWARE] keys, the plaintext must be no + * larger than 64KiB. For [HSM][google.cloud.kms.v1.ProtectionLevel.HSM] keys, the combined + * length of the plaintext and additional_authenticated_data fields must be no larger than + * 8KiB. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final EncryptResponse encrypt(ResourceName name, ByteString plaintext) { + EncryptRequest request = + EncryptRequest.newBuilder() + .setName(name == null ? null : name.toString()) + .setPlaintext(plaintext) + .build(); + return encrypt(request); + } + + // ADDED BY SYNTH + /** + * Encrypts data, so that it can only be recovered by a call to + * [Decrypt][google.cloud.kms.v1.KeyManagementService.Decrypt]. The + * [CryptoKey.purpose][google.cloud.kms.v1.CryptoKey.purpose] must be + * [ENCRYPT_DECRYPT][google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT]. + * + *
Sample code: + * + *
+ * try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
+ * CryptoKeyPathName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
* ByteString plaintext = ByteString.copyFromUtf8("");
* EncryptResponse response = keyManagementServiceClient.encrypt(name, plaintext);
* }
@@ -1964,7 +2004,7 @@ public final EncryptResponse encrypt(CryptoKeyPathName name, ByteString plaintex
*
*
* try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
- * CryptoKeyPathName name = CryptoKeyPathName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY_PATH]");
+ * ResourceName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
* ByteString plaintext = ByteString.copyFromUtf8("");
* EncryptResponse response = keyManagementServiceClient.encrypt(name.toString(), plaintext);
* }
@@ -2000,7 +2040,7 @@ public final EncryptResponse encrypt(String name, ByteString plaintext) {
*
*
* try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
- * CryptoKeyPathName name = CryptoKeyPathName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY_PATH]");
+ * ResourceName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
* ByteString plaintext = ByteString.copyFromUtf8("");
* EncryptRequest request = EncryptRequest.newBuilder()
* .setName(name.toString())
@@ -2028,7 +2068,7 @@ public final EncryptResponse encrypt(EncryptRequest request) {
*
*
* try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
- * CryptoKeyPathName name = CryptoKeyPathName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY_PATH]");
+ * ResourceName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
* ByteString plaintext = ByteString.copyFromUtf8("");
* EncryptRequest request = EncryptRequest.newBuilder()
* .setName(name.toString())
@@ -2890,6 +2930,33 @@ public final AsymmetricSignResponse asymmetricSign(AsymmetricSignRequest request
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Sets the access control policy on the specified resource. Replaces any existing policy.
+ *
+ * Can return Public Errors: NOT_FOUND, INVALID_ARGUMENT and PERMISSION_DENIED
+ *
+ *
Sample code:
+ *
+ *
+ * try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
+ * ResourceName resource = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
+ * Policy policy = Policy.newBuilder().build();
+ * SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
+ * .setResource(resource.toString())
+ * .setPolicy(policy)
+ * .build();
+ * Policy response = keyManagementServiceClient.setIamPolicy(request);
+ * }
+ *
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final Policy setIamPolicy(SetIamPolicyRequest request) {
+ return setIamPolicyCallable().call(request);
+ }
+
+ // ADDED BY SYNTH
/**
* Sets the access control policy on the specified resource. Replaces any existing policy.
*
@@ -2921,7 +2988,7 @@ public final Policy setIamPolicy(KeyName resource, Policy policy) {
return setIamPolicy(request);
}
- // AUTO-GENERATED DOCUMENTATION AND METHOD
+ // ADDED BY SYNTH
/**
* Sets the access control policy on the specified resource. Replaces any existing policy.
*
@@ -2960,50 +3027,47 @@ public final Policy setIamPolicy(String resource, Policy policy) {
*
*
* try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
- * ResourceName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ * ResourceName resource = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
* Policy policy = Policy.newBuilder().build();
* SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
* .setResource(resource.toString())
* .setPolicy(policy)
* .build();
- * Policy response = keyManagementServiceClient.setIamPolicy(request);
+ * ApiFuture<Policy> future = keyManagementServiceClient.setIamPolicyCallable().futureCall(request);
+ * // Do something
+ * Policy response = future.get();
* }
*
- *
- * @param request The request object containing all of the parameters for the API call.
- * @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
- public final Policy setIamPolicy(SetIamPolicyRequest request) {
- return setIamPolicyCallable().call(request);
+ public final UnaryCallable setIamPolicyCallable() {
+ return stub.setIamPolicyCallable();
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
- * Sets the access control policy on the specified resource. Replaces any existing policy.
- *
- * Can return Public Errors: NOT_FOUND, INVALID_ARGUMENT and PERMISSION_DENIED
+ * Gets the access control policy for a resource. Returns an empty policy if the resource exists
+ * and does not have a policy set.
*
*
Sample code:
*
*
* try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
- * ResourceName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
- * Policy policy = Policy.newBuilder().build();
- * SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
+ * ResourceName resource = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
+ * GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
* .setResource(resource.toString())
- * .setPolicy(policy)
* .build();
- * ApiFuture<Policy> future = keyManagementServiceClient.setIamPolicyCallable().futureCall(request);
- * // Do something
- * Policy response = future.get();
+ * Policy response = keyManagementServiceClient.getIamPolicy(request);
* }
*
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
- public final UnaryCallable setIamPolicyCallable() {
- return stub.setIamPolicyCallable();
+ public final Policy getIamPolicy(GetIamPolicyRequest request) {
+ return getIamPolicyCallable().call(request);
}
- // AUTO-GENERATED DOCUMENTATION AND METHOD
+ // ADDED BY SYNTH
/**
* Gets the access control policy for a resource. Returns an empty policy if the resource exists
* and does not have a policy set.
@@ -3029,7 +3093,7 @@ public final Policy getIamPolicy(KeyName resource) {
return getIamPolicy(request);
}
- // AUTO-GENERATED DOCUMENTATION AND METHOD
+ // ADDED BY SYNTH
/**
* Gets the access control policy for a resource. Returns an empty policy if the resource exists
* and does not have a policy set.
@@ -3061,45 +3125,51 @@ public final Policy getIamPolicy(String resource) {
*
*
* try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
- * ResourceName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ * ResourceName resource = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
* GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
* .setResource(resource.toString())
* .build();
- * Policy response = keyManagementServiceClient.getIamPolicy(request);
+ * ApiFuture<Policy> future = keyManagementServiceClient.getIamPolicyCallable().futureCall(request);
+ * // Do something
+ * Policy response = future.get();
* }
*
- *
- * @param request The request object containing all of the parameters for the API call.
- * @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
- public final Policy getIamPolicy(GetIamPolicyRequest request) {
- return getIamPolicyCallable().call(request);
+ public final UnaryCallable getIamPolicyCallable() {
+ return stub.getIamPolicyCallable();
}
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
- * Gets the access control policy for a resource. Returns an empty policy if the resource exists
- * and does not have a policy set.
+ * Returns permissions that a caller has on the specified resource. If the resource does not
+ * exist, this will return an empty set of permissions, not a NOT_FOUND error.
+ *
+ * Note: This operation is designed to be used for building permission-aware UIs and
+ * command-line tools, not for authorization checking. This operation may "fail open" without
+ * warning.
*
*
Sample code:
*
*
* try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
- * ResourceName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
- * GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
+ * ResourceName resource = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
+ * List<String> permissions = new ArrayList<>();
+ * TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
* .setResource(resource.toString())
+ * .addAllPermissions(permissions)
* .build();
- * ApiFuture<Policy> future = keyManagementServiceClient.getIamPolicyCallable().futureCall(request);
- * // Do something
- * Policy response = future.get();
+ * TestIamPermissionsResponse response = keyManagementServiceClient.testIamPermissions(request);
* }
*
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
- public final UnaryCallable getIamPolicyCallable() {
- return stub.getIamPolicyCallable();
+ public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsRequest request) {
+ return testIamPermissionsCallable().call(request);
}
- // AUTO-GENERATED DOCUMENTATION AND METHOD
+ // ADDED BY SYNTH
/**
* Returns permissions that a caller has on the specified resource. If the resource does not
* exist, this will return an empty set of permissions, not a NOT_FOUND error.
@@ -3135,7 +3205,7 @@ public final TestIamPermissionsResponse testIamPermissions(
return testIamPermissions(request);
}
- // AUTO-GENERATED DOCUMENTATION AND METHOD
+ // ADDED BY SYNTH
/**
* Returns permissions that a caller has on the specified resource. If the resource does not
* exist, this will return an empty set of permissions, not a NOT_FOUND error.
@@ -3184,37 +3254,7 @@ public final TestIamPermissionsResponse testIamPermissions(
*
*
* try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
- * ResourceName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
- * List<String> permissions = new ArrayList<>();
- * TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
- * .setResource(resource.toString())
- * .addAllPermissions(permissions)
- * .build();
- * TestIamPermissionsResponse response = keyManagementServiceClient.testIamPermissions(request);
- * }
- *
- *
- * @param request The request object containing all of the parameters for the API call.
- * @throws com.google.api.gax.rpc.ApiException if the remote call fails
- */
- public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsRequest request) {
- return testIamPermissionsCallable().call(request);
- }
-
- // AUTO-GENERATED DOCUMENTATION AND METHOD
- /**
- * Returns permissions that a caller has on the specified resource. If the resource does not
- * exist, this will return an empty set of permissions, not a NOT_FOUND error.
- *
- * Note: This operation is designed to be used for building permission-aware UIs and
- * command-line tools, not for authorization checking. This operation may "fail open" without
- * warning.
- *
- *
Sample code:
- *
- *
- * try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
- * ResourceName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ * ResourceName resource = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
* List<String> permissions = new ArrayList<>();
* TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
* .setResource(resource.toString())
diff --git a/google-cloud-kms/src/test/java/com/google/cloud/kms/v1/KeyManagementServiceClientTest.java b/google-cloud-kms/src/test/java/com/google/cloud/kms/v1/KeyManagementServiceClientTest.java
index 0dd79d8b..5e0c8612 100644
--- a/google-cloud-kms/src/test/java/com/google/cloud/kms/v1/KeyManagementServiceClientTest.java
+++ b/google-cloud-kms/src/test/java/com/google/cloud/kms/v1/KeyManagementServiceClientTest.java
@@ -27,6 +27,7 @@
import com.google.api.gax.grpc.testing.MockServiceHelper;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.InvalidArgumentException;
+import com.google.api.resourcenames.ResourceName;
import com.google.common.collect.Lists;
import com.google.iam.v1.GetIamPolicyRequest;
import com.google.iam.v1.Policy;
@@ -339,8 +340,8 @@ public void getKeyRingExceptionTest() throws Exception {
@Test
@SuppressWarnings("all")
public void getImportJobTest() {
- String name2 = "name2-1052831874";
- ImportJob expectedResponse = ImportJob.newBuilder().setName(name2).build();
+ ImportJobName name2 = ImportJobName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[IMPORT_JOB]");
+ ImportJob expectedResponse = ImportJob.newBuilder().setName(name2.toString()).build();
mockKeyManagementService.addResponse(expectedResponse);
ImportJobName name = ImportJobName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[IMPORT_JOB]");
@@ -516,8 +517,8 @@ public void createKeyRingExceptionTest() throws Exception {
@Test
@SuppressWarnings("all")
public void createImportJobTest() {
- String name = "name3373707";
- ImportJob expectedResponse = ImportJob.newBuilder().setName(name).build();
+ ImportJobName name = ImportJobName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[IMPORT_JOB]");
+ ImportJob expectedResponse = ImportJob.newBuilder().setName(name.toString()).build();
mockKeyManagementService.addResponse(expectedResponse);
KeyRingName parent = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
@@ -863,8 +864,7 @@ public void encryptTest() {
EncryptResponse.newBuilder().setName(name2).setCiphertext(ciphertext).build();
mockKeyManagementService.addResponse(expectedResponse);
- CryptoKeyPathName name =
- CryptoKeyPathName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY_PATH]");
+ ResourceName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
ByteString plaintext = ByteString.copyFromUtf8("-9");
EncryptResponse actualResponse = client.encrypt(name, plaintext);
@@ -874,7 +874,7 @@ public void encryptTest() {
Assert.assertEquals(1, actualRequests.size());
EncryptRequest actualRequest = (EncryptRequest) actualRequests.get(0);
- Assert.assertEquals(name, CryptoKeyPathName.parse(actualRequest.getName()));
+ Assert.assertEquals(Objects.toString(name), Objects.toString(actualRequest.getName()));
Assert.assertEquals(plaintext, actualRequest.getPlaintext());
Assert.assertTrue(
channelProvider.isHeaderSent(
@@ -889,8 +889,7 @@ public void encryptExceptionTest() throws Exception {
mockKeyManagementService.addException(exception);
try {
- CryptoKeyPathName name =
- CryptoKeyPathName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY_PATH]");
+ ResourceName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
ByteString plaintext = ByteString.copyFromUtf8("-9");
client.encrypt(name, plaintext);
@@ -1238,10 +1237,13 @@ public void setIamPolicyTest() {
Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build();
mockIAMPolicy.addResponse(expectedResponse);
- KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ ResourceName resource =
+ CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
Policy policy = Policy.newBuilder().build();
+ SetIamPolicyRequest request =
+ SetIamPolicyRequest.newBuilder().setResource(resource.toString()).setPolicy(policy).build();
- Policy actualResponse = client.setIamPolicy(resource, policy);
+ Policy actualResponse = client.setIamPolicy(request);
Assert.assertEquals(expectedResponse, actualResponse);
List actualRequests = mockIAMPolicy.getRequests();
@@ -1263,10 +1265,16 @@ public void setIamPolicyExceptionTest() throws Exception {
mockIAMPolicy.addException(exception);
try {
- KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ ResourceName resource =
+ CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
Policy policy = Policy.newBuilder().build();
+ SetIamPolicyRequest request =
+ SetIamPolicyRequest.newBuilder()
+ .setResource(resource.toString())
+ .setPolicy(policy)
+ .build();
- client.setIamPolicy(resource, policy);
+ client.setIamPolicy(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
@@ -1281,9 +1289,12 @@ public void getIamPolicyTest() {
Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build();
mockIAMPolicy.addResponse(expectedResponse);
- KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ ResourceName resource =
+ CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
+ GetIamPolicyRequest request =
+ GetIamPolicyRequest.newBuilder().setResource(resource.toString()).build();
- Policy actualResponse = client.getIamPolicy(resource);
+ Policy actualResponse = client.getIamPolicy(request);
Assert.assertEquals(expectedResponse, actualResponse);
List actualRequests = mockIAMPolicy.getRequests();
@@ -1304,9 +1315,12 @@ public void getIamPolicyExceptionTest() throws Exception {
mockIAMPolicy.addException(exception);
try {
- KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ ResourceName resource =
+ CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
+ GetIamPolicyRequest request =
+ GetIamPolicyRequest.newBuilder().setResource(resource.toString()).build();
- client.getIamPolicy(resource);
+ client.getIamPolicy(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
@@ -1319,10 +1333,16 @@ public void testIamPermissionsTest() {
TestIamPermissionsResponse expectedResponse = TestIamPermissionsResponse.newBuilder().build();
mockIAMPolicy.addResponse(expectedResponse);
- KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ ResourceName resource =
+ CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
List permissions = new ArrayList<>();
+ TestIamPermissionsRequest request =
+ TestIamPermissionsRequest.newBuilder()
+ .setResource(resource.toString())
+ .addAllPermissions(permissions)
+ .build();
- TestIamPermissionsResponse actualResponse = client.testIamPermissions(resource, permissions);
+ TestIamPermissionsResponse actualResponse = client.testIamPermissions(request);
Assert.assertEquals(expectedResponse, actualResponse);
List actualRequests = mockIAMPolicy.getRequests();
@@ -1344,10 +1364,16 @@ public void testIamPermissionsExceptionTest() throws Exception {
mockIAMPolicy.addException(exception);
try {
- KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ ResourceName resource =
+ CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
List permissions = new ArrayList<>();
+ TestIamPermissionsRequest request =
+ TestIamPermissionsRequest.newBuilder()
+ .setResource(resource.toString())
+ .addAllPermissions(permissions)
+ .build();
- client.testIamPermissions(resource, permissions);
+ client.testIamPermissions(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
diff --git a/synth.metadata b/synth.metadata
index 2a9a3bd3..123a973a 100644
--- a/synth.metadata
+++ b/synth.metadata
@@ -1,21 +1,19 @@
{
- "updateTime": "2020-03-25T17:52:18.853146Z",
+ "updateTime": "2020-03-26T02:06:16.498411Z",
"sources": [
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
- "sha": "fd83ab212176a1042e8d45ea90766b3bf59ac679",
- "internalRef": "302913609",
- "log": "fd83ab212176a1042e8d45ea90766b3bf59ac679\nfix: migrate osconfig/agentendpoint/v1 go_gapic_library target to microgen impl\n\nPiperOrigin-RevId: 302913609\n\n0e07113e776bdd8fcc0783372e08bb6e76cb1b5b\ndocs: Update documentation with links to smart home developer guides and reference pages. Remove outdated authorization instructions.\n\nPiperOrigin-RevId: 302892245\n\n"
+ "sha": "d4aa417ed2bba89c2d216900282bddfdafef6128",
+ "internalRef": "303010132"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
- "sha": "e36822bfa0acb355502dab391b8ef9c4f30208d8",
- "log": "e36822bfa0acb355502dab391b8ef9c4f30208d8\nchore(java): treat samples shared configuration dependency update as chore (#457)\n\n\n1b4cc80a7aaf164f6241937dd87f3bd1f4149e0c\nfix: do not run node 8 CI (#456)\n\n\n"
+ "sha": "e36822bfa0acb355502dab391b8ef9c4f30208d8"
}
}
],
diff --git a/synth.py b/synth.py
index c9052335..a18f38c8 100644
--- a/synth.py
+++ b/synth.py
@@ -14,6 +14,7 @@
"""This script is used to synthesize generated parts of this library."""
+import synthtool as s
import synthtool.languages.java as java
AUTOSYNTH_MULTIPLE_COMMITS = True
@@ -21,6 +22,246 @@
service = 'kms'
versions = ['v1']
+IMPLEMENTS_RESOURCE_NAME = "implements ResourceName"
+EXTENDS_KEY_NAME = "extends KeyName"
+
+ENCRYPT_INSERTION_POINT = r'(\s+public final EncryptResponse encrypt\(ResourceName.*\) {\n.*\n.*\n.*\n.*\n.*\n.*return encrypt\(request\);\n\s+})'
+SET_IAM_INSERTION_POINT = r'(\s+public final Policy setIamPolicy\(SetIamPolicyRequest request\) {\n\s+return.*\n\s+})'
+GET_IAM_INSERTION_POINT = r'(\s+public final Policy getIamPolicy\(GetIamPolicyRequest request\) {\n\s+return.*\n\s+})'
+TEST_IAM_INSERTION_POINT = r'(\s+public final TestIamPermissionsResponse testIamPermissions\(TestIamPermissionsRequest request\) {\n\s+return.*\n\s+})'
+
+ENCRYPT_METHOD = """
+ // ADDED BY SYNTH
+ /**
+ * Encrypts data, so that it can only be recovered by a call to
+ * [Decrypt][google.cloud.kms.v1.KeyManagementService.Decrypt]. The
+ * [CryptoKey.purpose][google.cloud.kms.v1.CryptoKey.purpose] must be
+ * [ENCRYPT_DECRYPT][google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT].
+ *
+ * Sample code:
+ *
+ *
+ * try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
+ * CryptoKeyPathName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
+ * ByteString plaintext = ByteString.copyFromUtf8("");
+ * EncryptResponse response = keyManagementServiceClient.encrypt(name, plaintext);
+ * }
+ *
+ *
+ * @param name Required. The resource name of the [CryptoKey][google.cloud.kms.v1.CryptoKey] or
+ * [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] to use for encryption.
+ * If a [CryptoKey][google.cloud.kms.v1.CryptoKey] is specified, the server will use its
+ * [primary version][google.cloud.kms.v1.CryptoKey.primary].
+ * @param plaintext Required. The data to encrypt. Must be no larger than 64KiB.
+ *
The maximum size depends on the key version's
+ * [protection_level][google.cloud.kms.v1.CryptoKeyVersionTemplate.protection_level]. For
+ * [SOFTWARE][google.cloud.kms.v1.ProtectionLevel.SOFTWARE] keys, the plaintext must be no
+ * larger than 64KiB. For [HSM][google.cloud.kms.v1.ProtectionLevel.HSM] keys, the combined
+ * length of the plaintext and additional_authenticated_data fields must be no larger than
+ * 8KiB.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final EncryptResponse encrypt(CryptoKeyPathName name, ByteString plaintext) {
+ EncryptRequest request =
+ EncryptRequest.newBuilder()
+ .setName(name == null ? null : name.toString())
+ .setPlaintext(plaintext)
+ .build();
+ return encrypt(request);
+ }
+"""
+
+
+SET_IAM_METHODS = """
+ // ADDED BY SYNTH
+ /**
+ * Sets the access control policy on the specified resource. Replaces any existing policy.
+ *
+ *
Can return Public Errors: NOT_FOUND, INVALID_ARGUMENT and PERMISSION_DENIED
+ *
+ *
Sample code:
+ *
+ *
+ * try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
+ * KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ * Policy policy = Policy.newBuilder().build();
+ * Policy response = keyManagementServiceClient.setIamPolicy(resource, policy);
+ * }
+ *
+ *
+ * @param resource REQUIRED: The resource for which the policy is being specified. See the
+ * operation documentation for the appropriate value for this field.
+ * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the
+ * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud
+ * Platform services (such as Projects) might reject them.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final Policy setIamPolicy(KeyName resource, Policy policy) {
+ SetIamPolicyRequest request =
+ SetIamPolicyRequest.newBuilder()
+ .setResource(resource == null ? null : resource.toString())
+ .setPolicy(policy)
+ .build();
+ return setIamPolicy(request);
+ }
+
+ // ADDED BY SYNTH
+ /**
+ * Sets the access control policy on the specified resource. Replaces any existing policy.
+ *
+ * Can return Public Errors: NOT_FOUND, INVALID_ARGUMENT and PERMISSION_DENIED
+ *
+ *
Sample code:
+ *
+ *
+ * try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
+ * KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ * Policy policy = Policy.newBuilder().build();
+ * Policy response = keyManagementServiceClient.setIamPolicy(resource.toString(), policy);
+ * }
+ *
+ *
+ * @param resource REQUIRED: The resource for which the policy is being specified. See the
+ * operation documentation for the appropriate value for this field.
+ * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the
+ * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud
+ * Platform services (such as Projects) might reject them.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final Policy setIamPolicy(String resource, Policy policy) {
+ SetIamPolicyRequest request =
+ SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build();
+ return setIamPolicy(request);
+ }
+"""
+
+GET_IAM_METHODS = """
+ // ADDED BY SYNTH
+ /**
+ * Gets the access control policy for a resource. Returns an empty policy if the resource exists
+ * and does not have a policy set.
+ *
+ * Sample code:
+ *
+ *
+ * try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
+ * KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ * Policy response = keyManagementServiceClient.getIamPolicy(resource);
+ * }
+ *
+ *
+ * @param resource REQUIRED: The resource for which the policy is being requested. See the
+ * operation documentation for the appropriate value for this field.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final Policy getIamPolicy(KeyName resource) {
+ GetIamPolicyRequest request =
+ GetIamPolicyRequest.newBuilder()
+ .setResource(resource == null ? null : resource.toString())
+ .build();
+ return getIamPolicy(request);
+ }
+
+ // ADDED BY SYNTH
+ /**
+ * Gets the access control policy for a resource. Returns an empty policy if the resource exists
+ * and does not have a policy set.
+ *
+ * Sample code:
+ *
+ *
+ * try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
+ * KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ * Policy response = keyManagementServiceClient.getIamPolicy(resource.toString());
+ * }
+ *
+ *
+ * @param resource REQUIRED: The resource for which the policy is being requested. See the
+ * operation documentation for the appropriate value for this field.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final Policy getIamPolicy(String resource) {
+ GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build();
+ return getIamPolicy(request);
+ }
+"""
+
+TEST_IAM_METHODS = """
+ // ADDED BY SYNTH
+ /**
+ * Returns permissions that a caller has on the specified resource. If the resource does not
+ * exist, this will return an empty set of permissions, not a NOT_FOUND error.
+ *
+ * Note: This operation is designed to be used for building permission-aware UIs and
+ * command-line tools, not for authorization checking. This operation may "fail open" without
+ * warning.
+ *
+ *
Sample code:
+ *
+ *
+ * try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
+ * KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ * List<String> permissions = new ArrayList<>();
+ * TestIamPermissionsResponse response = keyManagementServiceClient.testIamPermissions(resource, permissions);
+ * }
+ *
+ *
+ * @param resource REQUIRED: The resource for which the policy detail is being requested. See the
+ * operation documentation for the appropriate value for this field.
+ * @param permissions The set of permissions to check for the `resource`. Permissions with
+ * wildcards (such as '*' or 'storage.*') are not allowed. For more information see
+ * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final TestIamPermissionsResponse testIamPermissions(
+ KeyName resource, List permissions) {
+ TestIamPermissionsRequest request =
+ TestIamPermissionsRequest.newBuilder()
+ .setResource(resource == null ? null : resource.toString())
+ .addAllPermissions(permissions)
+ .build();
+ return testIamPermissions(request);
+ }
+
+ // ADDED BY SYNTH
+ /**
+ * Returns permissions that a caller has on the specified resource. If the resource does not
+ * exist, this will return an empty set of permissions, not a NOT_FOUND error.
+ *
+ * Note: This operation is designed to be used for building permission-aware UIs and
+ * command-line tools, not for authorization checking. This operation may "fail open" without
+ * warning.
+ *
+ *
Sample code:
+ *
+ *
+ * try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
+ * KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
+ * List<String> permissions = new ArrayList<>();
+ * TestIamPermissionsResponse response = keyManagementServiceClient.testIamPermissions(resource.toString(), permissions);
+ * }
+ *
+ *
+ * @param resource REQUIRED: The resource for which the policy detail is being requested. See the
+ * operation documentation for the appropriate value for this field.
+ * @param permissions The set of permissions to check for the `resource`. Permissions with
+ * wildcards (such as '*' or 'storage.*') are not allowed. For more information see
+ * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final TestIamPermissionsResponse testIamPermissions(
+ String resource, List permissions) {
+ TestIamPermissionsRequest request =
+ TestIamPermissionsRequest.newBuilder()
+ .setResource(resource)
+ .addAllPermissions(permissions)
+ .build();
+ return testIamPermissions(request);
+ }
+"""
+
+
+
for version in versions:
library = java.bazel_library(
service=service,
@@ -28,4 +269,43 @@
bazel_target=f'//google/cloud/{service}/{version}:google-cloud-{service}-{version}-java',
)
+ s.replace(
+ "**/KeyManagementServiceClient.java",
+ ENCRYPT_INSERTION_POINT,
+ "\g<1>\n\n" + ENCRYPT_METHOD
+ )
+
+ s.replace(
+ "**/KeyManagementServiceClient.java",
+ GET_IAM_INSERTION_POINT,
+ "\g<1>\n\n" + GET_IAM_METHODS
+ )
+
+ s.replace(
+ "**/KeyManagementServiceClient.java",
+ SET_IAM_INSERTION_POINT,
+ "\g<1>\n\n" + SET_IAM_METHODS
+ )
+
+ s.replace(
+ "**/KeyManagementServiceClient.java",
+ TEST_IAM_INSERTION_POINT,
+ "\g<1>\n\n" + TEST_IAM_METHODS
+ )
+
+ s.replace(
+ "**/KeyRingName.java",
+ IMPLEMENTS_RESOURCE_NAME,
+ EXTENDS_KEY_NAME
+ )
+
+ s.replace(
+ "**/CryptoKeyName.java",
+ IMPLEMENTS_RESOURCE_NAME,
+ EXTENDS_KEY_NAME)
+
+ java.format_code('google-cloud-kms/src')
+ java.format_code(f'grpc-google-cloud-{service}-{version}/src')
+ java.format_code(f'proto-google-cloud-{service}-{version}/src')
+
java.common_templates()