Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
feat: replace the usage of KeyName and CryptoKeyPathName with the int…
Browse files Browse the repository at this point in the history
…erface ResourceName (#117)

* Turn on gapic config v2 for kms.
googleapis/googleapis@0341fa3
commit 0341fa3fc2f4073a1b1f260d37b2ce620799f545
Author: Google APIs <noreply@google.com>
Date:   Wed Mar 25 15:11:36 2020 -0700

    Turn on gapic config v2 for kms.

    Committer: @hzyi-google
    PiperOrigin-RevId: 302980301

google/cloud/kms/v1/cloudkms_gapic.legacy.yaml
google/cloud/kms/v1/cloudkms_gapic.yaml

* manual updates

* fmt

Co-authored-by: yoshi-automation <yoshi-automation@google.com>
  • Loading branch information
yihanzhen and yoshi-automation committed Mar 26, 2020
1 parent 163c590 commit 0c57b5f
Show file tree
Hide file tree
Showing 4 changed files with 446 additions and 102 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -1925,7 +1926,46 @@ public final CryptoKeyVersion updateCryptoKeyVersion(UpdateCryptoKeyVersionReque
*
* <pre><code>
* 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);
* }
* </code></pre>
*
* @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.
* <p>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.
* <p>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].
*
* <p>Sample code:
*
* <pre><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);
* }
Expand Down Expand Up @@ -1964,7 +2004,7 @@ public final EncryptResponse encrypt(CryptoKeyPathName name, ByteString plaintex
*
* <pre><code>
* 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);
* }
Expand Down Expand Up @@ -2000,7 +2040,7 @@ public final EncryptResponse encrypt(String name, ByteString plaintext) {
*
* <pre><code>
* 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())
Expand Down Expand Up @@ -2028,7 +2068,7 @@ public final EncryptResponse encrypt(EncryptRequest request) {
*
* <pre><code>
* 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())
Expand Down Expand Up @@ -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.
*
* <p>Can return Public Errors: NOT_FOUND, INVALID_ARGUMENT and PERMISSION_DENIED
*
* <p>Sample code:
*
* <pre><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);
* }
* </code></pre>
*
* @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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -2960,50 +3027,47 @@ public final Policy setIamPolicy(String resource, Policy policy) {
*
* <pre><code>
* 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&lt;Policy&gt; future = keyManagementServiceClient.setIamPolicyCallable().futureCall(request);
* // Do something
* Policy response = future.get();
* }
* </code></pre>
*
* @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<SetIamPolicyRequest, Policy> setIamPolicyCallable() {
return stub.setIamPolicyCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Sets the access control policy on the specified resource. Replaces any existing policy.
*
* <p>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.
*
* <p>Sample code:
*
* <pre><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&lt;Policy&gt; future = keyManagementServiceClient.setIamPolicyCallable().futureCall(request);
* // Do something
* Policy response = future.get();
* Policy response = keyManagementServiceClient.getIamPolicy(request);
* }
* </code></pre>
*
* @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<SetIamPolicyRequest, Policy> 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.
Expand All @@ -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.
Expand Down Expand Up @@ -3061,45 +3125,51 @@ public final Policy getIamPolicy(String resource) {
*
* <pre><code>
* 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&lt;Policy&gt; future = keyManagementServiceClient.getIamPolicyCallable().futureCall(request);
* // Do something
* Policy response = future.get();
* }
* </code></pre>
*
* @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<GetIamPolicyRequest, Policy> 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.
*
* <p>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.
*
* <p>Sample code:
*
* <pre><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&lt;String&gt; permissions = new ArrayList&lt;&gt;();
* TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
* .setResource(resource.toString())
* .addAllPermissions(permissions)
* .build();
* ApiFuture&lt;Policy&gt; future = keyManagementServiceClient.getIamPolicyCallable().futureCall(request);
* // Do something
* Policy response = future.get();
* TestIamPermissionsResponse response = keyManagementServiceClient.testIamPermissions(request);
* }
* </code></pre>
*
* @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<GetIamPolicyRequest, Policy> 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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -3184,37 +3254,7 @@ public final TestIamPermissionsResponse testIamPermissions(
*
* <pre><code>
* try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
* ResourceName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]");
* List&lt;String&gt; permissions = new ArrayList&lt;&gt;();
* TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
* .setResource(resource.toString())
* .addAllPermissions(permissions)
* .build();
* TestIamPermissionsResponse response = keyManagementServiceClient.testIamPermissions(request);
* }
* </code></pre>
*
* @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.
*
* <p>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.
*
* <p>Sample code:
*
* <pre><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&lt;String&gt; permissions = new ArrayList&lt;&gt;();
* TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
* .setResource(resource.toString())
Expand Down

0 comments on commit 0c57b5f

Please sign in to comment.