From 285d90cc00f78b37402f2bd590562737d9688321 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Mon, 12 Jun 2023 22:41:45 -0400 Subject: [PATCH 01/26] chore: Add framework for iam showcase tests --- .../com/google/showcase/v1beta1/it/ITIam.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java new file mode 100644 index 0000000000..bb6a297c0b --- /dev/null +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -0,0 +1,54 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.showcase.v1beta1.it; + +import com.google.iam.v1.Binding; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.it.util.TestClientInitializer; +import java.util.concurrent.TimeUnit; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class ITIam { + private static EchoClient grpcClient; + private static EchoClient httpjsonClient; + + @BeforeClass + public static void createClients() throws Exception { + grpcClient = TestClientInitializer.createGrpcEchoClient(); + httpjsonClient = TestClientInitializer.createHttpJsonEchoClient(); + } + + @AfterClass + public static void destroyClients() throws InterruptedException { + grpcClient.close(); + httpjsonClient.close(); + + grpcClient.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); + httpjsonClient.awaitTermination( + TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); + } + + public void testGrpc_setIamPolicy() { + SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() + .setPolicy( + Policy.newBuilder() + .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers"))) + .build(); + } +} From dbf80852cf65a0e591642a1ffd4c2b1c0576296d Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Tue, 13 Jun 2023 11:12:50 -0400 Subject: [PATCH 02/26] chore: Generate clients with IAM stubs --- showcase/BUILD.bazel | 9 +- .../showcase/v1beta1/ComplianceClient.java | 208 ++++++++++++++++++ .../showcase/v1beta1/ComplianceSettings.java | 37 ++++ .../google/showcase/v1beta1/EchoClient.java | 208 ++++++++++++++++++ .../google/showcase/v1beta1/EchoSettings.java | 37 ++++ .../showcase/v1beta1/IdentityClient.java | 208 ++++++++++++++++++ .../showcase/v1beta1/IdentitySettings.java | 37 ++++ .../showcase/v1beta1/MessagingClient.java | 208 ++++++++++++++++++ .../showcase/v1beta1/MessagingSettings.java | 37 ++++ .../v1beta1/SequenceServiceClient.java | 208 ++++++++++++++++++ .../v1beta1/SequenceServiceSettings.java | 37 ++++ .../showcase/v1beta1/TestingClient.java | 208 ++++++++++++++++++ .../showcase/v1beta1/TestingSettings.java | 37 ++++ .../showcase/v1beta1/gapic_metadata.json | 54 +++++ .../showcase/v1beta1/stub/ComplianceStub.java | 18 ++ .../v1beta1/stub/ComplianceStubSettings.java | 79 ++++++- .../showcase/v1beta1/stub/EchoStub.java | 18 ++ .../v1beta1/stub/EchoStubSettings.java | 79 ++++++- .../v1beta1/stub/GrpcComplianceStub.java | 94 ++++++++ .../showcase/v1beta1/stub/GrpcEchoStub.java | 94 ++++++++ .../v1beta1/stub/GrpcIdentityStub.java | 94 ++++++++ .../v1beta1/stub/GrpcMessagingStub.java | 94 ++++++++ .../v1beta1/stub/GrpcSequenceServiceStub.java | 94 ++++++++ .../v1beta1/stub/GrpcTestingStub.java | 94 ++++++++ .../v1beta1/stub/HttpJsonComplianceStub.java | 190 ++++++++++++++++ .../v1beta1/stub/HttpJsonEchoStub.java | 190 ++++++++++++++++ .../v1beta1/stub/HttpJsonIdentityStub.java | 190 ++++++++++++++++ .../v1beta1/stub/HttpJsonMessagingStub.java | 190 ++++++++++++++++ .../stub/HttpJsonSequenceServiceStub.java | 190 ++++++++++++++++ .../v1beta1/stub/HttpJsonTestingStub.java | 190 ++++++++++++++++ .../showcase/v1beta1/stub/IdentityStub.java | 18 ++ .../v1beta1/stub/IdentityStubSettings.java | 79 ++++++- .../showcase/v1beta1/stub/MessagingStub.java | 18 ++ .../v1beta1/stub/MessagingStubSettings.java | 79 ++++++- .../v1beta1/stub/SequenceServiceStub.java | 18 ++ .../stub/SequenceServiceStubSettings.java | 79 ++++++- .../showcase/v1beta1/stub/TestingStub.java | 18 ++ .../v1beta1/stub/TestingStubSettings.java | 79 ++++++- .../v1beta1/ComplianceClientHttpJsonTest.java | 184 ++++++++++++++++ .../v1beta1/ComplianceClientTest.java | 175 ++++++++++++++- .../v1beta1/EchoClientHttpJsonTest.java | 184 ++++++++++++++++ .../showcase/v1beta1/EchoClientTest.java | 175 ++++++++++++++- .../v1beta1/IdentityClientHttpJsonTest.java | 184 ++++++++++++++++ .../showcase/v1beta1/IdentityClientTest.java | 174 ++++++++++++++- .../v1beta1/MessagingClientHttpJsonTest.java | 182 +++++++++++++++ .../showcase/v1beta1/MessagingClientTest.java | 172 ++++++++++++++- .../SequenceServiceClientHttpJsonTest.java | 184 ++++++++++++++++ .../v1beta1/SequenceServiceClientTest.java | 174 ++++++++++++++- .../v1beta1/TestingClientHttpJsonTest.java | 183 +++++++++++++++ .../showcase/v1beta1/TestingClientTest.java | 173 ++++++++++++++- 50 files changed, 5942 insertions(+), 21 deletions(-) diff --git a/showcase/BUILD.bazel b/showcase/BUILD.bazel index 9c893230e0..14435f6903 100644 --- a/showcase/BUILD.bazel +++ b/showcase/BUILD.bazel @@ -19,7 +19,8 @@ proto_library_with_info( "@com_google_gapic_showcase//schema/google/showcase/v1beta1:showcase_proto", # "//showcase/gapic-showcase-extended/proto:showcase_proto_extended", "@com_google_googleapis//google/cloud:common_resources_proto", - "@com_google_googleapis//google/cloud/location:location_proto" + "@com_google_googleapis//google/cloud/location:location_proto", + "@com_google_googleapis//google/iam/v1:iam_policy_proto" ], ) @@ -57,13 +58,15 @@ java_gapic_library( test_deps = [ ":showcase_java_grpc", # ":showcase_java_grpc_extended", - "@com_google_googleapis//google/cloud/location:location_java_grpc" + "@com_google_googleapis//google/cloud/location:location_java_grpc", + "@com_google_googleapis//google/iam/v1:iam_java_grpc" ], transport = "grpc+rest", deps = [ ":showcase_java_proto", "@com_google_googleapis//google/api:api_java_proto", - "@com_google_googleapis//google/cloud/location:location_java_proto" + "@com_google_googleapis//google/cloud/location:location_java_proto", + "@com_google_googleapis//google/iam/v1:iam_java_proto" ], ) diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ComplianceClient.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ComplianceClient.java index 1b1b9cd00a..920440bde1 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ComplianceClient.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ComplianceClient.java @@ -30,6 +30,11 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.util.concurrent.MoreExecutors; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.showcase.v1beta1.stub.ComplianceStub; import com.google.showcase.v1beta1.stub.ComplianceStubSettings; import java.io.IOException; @@ -1081,6 +1086,209 @@ public final UnaryCallable getLocationCallable() { return stub.getLocationCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sets the access control policy on the specified resource. Replaces any existing policy. + * + *

Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   SetIamPolicyRequest request =
+   *       SetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setPolicy(Policy.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   Policy response = complianceClient.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); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sets the access control policy on the specified resource. Replaces any existing policy. + * + *

Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   SetIamPolicyRequest request =
+   *       SetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setPolicy(Policy.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = complianceClient.setIamPolicyCallable().futureCall(request);
+   *   // Do something.
+   *   Policy response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable setIamPolicyCallable() { + return stub.setIamPolicyCallable(); + } + + // 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. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   GetIamPolicyRequest request =
+   *       GetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setOptions(GetPolicyOptions.newBuilder().build())
+   *           .build();
+   *   Policy response = complianceClient.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 Policy getIamPolicy(GetIamPolicyRequest request) { + return getIamPolicyCallable().call(request); + } + + // 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. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   GetIamPolicyRequest request =
+   *       GetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setOptions(GetPolicyOptions.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = complianceClient.getIamPolicyCallable().futureCall(request);
+   *   // Do something.
+   *   Policy response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getIamPolicyCallable() { + return stub.getIamPolicyCallable(); + } + + // 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: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   TestIamPermissionsRequest request =
+   *       TestIamPermissionsRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .addAllPermissions(new ArrayList())
+   *           .build();
+   *   TestIamPermissionsResponse response = complianceClient.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: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (ComplianceClient complianceClient = ComplianceClient.create()) {
+   *   TestIamPermissionsRequest request =
+   *       TestIamPermissionsRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .addAllPermissions(new ArrayList())
+   *           .build();
+   *   ApiFuture future =
+   *       complianceClient.testIamPermissionsCallable().futureCall(request);
+   *   // Do something.
+   *   TestIamPermissionsResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + testIamPermissionsCallable() { + return stub.testIamPermissionsCallable(); + } + @Override public final void close() { stub.close(); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ComplianceSettings.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ComplianceSettings.java index 3e3a4beaa5..050afe24dd 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ComplianceSettings.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ComplianceSettings.java @@ -35,6 +35,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.showcase.v1beta1.stub.ComplianceStubSettings; import java.io.IOException; import java.util.List; @@ -141,6 +146,22 @@ public UnaryCallSettings getLocationSettings() { return ((ComplianceStubSettings) getStubSettings()).getLocationSettings(); } + /** Returns the object with the settings used for calls to setIamPolicy. */ + public UnaryCallSettings setIamPolicySettings() { + return ((ComplianceStubSettings) getStubSettings()).setIamPolicySettings(); + } + + /** Returns the object with the settings used for calls to getIamPolicy. */ + public UnaryCallSettings getIamPolicySettings() { + return ((ComplianceStubSettings) getStubSettings()).getIamPolicySettings(); + } + + /** Returns the object with the settings used for calls to testIamPermissions. */ + public UnaryCallSettings + testIamPermissionsSettings() { + return ((ComplianceStubSettings) getStubSettings()).testIamPermissionsSettings(); + } + public static final ComplianceSettings create(ComplianceStubSettings stub) throws IOException { return new ComplianceSettings.Builder(stub.toBuilder()).build(); } @@ -319,6 +340,22 @@ public UnaryCallSettings.Builder getLocationSettin return getStubSettingsBuilder().getLocationSettings(); } + /** Returns the builder for the settings used for calls to setIamPolicy. */ + public UnaryCallSettings.Builder setIamPolicySettings() { + return getStubSettingsBuilder().setIamPolicySettings(); + } + + /** Returns the builder for the settings used for calls to getIamPolicy. */ + public UnaryCallSettings.Builder getIamPolicySettings() { + return getStubSettingsBuilder().getIamPolicySettings(); + } + + /** Returns the builder for the settings used for calls to testIamPermissions. */ + public UnaryCallSettings.Builder + testIamPermissionsSettings() { + return getStubSettingsBuilder().testIamPermissionsSettings(); + } + @Override public ComplianceSettings build() throws IOException { return new ComplianceSettings(this); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/EchoClient.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/EchoClient.java index 7eae457785..270edd3f81 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/EchoClient.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/EchoClient.java @@ -36,6 +36,11 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.util.concurrent.MoreExecutors; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.showcase.v1beta1.stub.EchoStub; import com.google.showcase.v1beta1.stub.EchoStubSettings; @@ -957,6 +962,209 @@ public final UnaryCallable getLocationCallable() { return stub.getLocationCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sets the access control policy on the specified resource. Replaces any existing policy. + * + *

Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   SetIamPolicyRequest request =
+   *       SetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setPolicy(Policy.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   Policy response = echoClient.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); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sets the access control policy on the specified resource. Replaces any existing policy. + * + *

Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   SetIamPolicyRequest request =
+   *       SetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setPolicy(Policy.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = echoClient.setIamPolicyCallable().futureCall(request);
+   *   // Do something.
+   *   Policy response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable setIamPolicyCallable() { + return stub.setIamPolicyCallable(); + } + + // 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. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   GetIamPolicyRequest request =
+   *       GetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setOptions(GetPolicyOptions.newBuilder().build())
+   *           .build();
+   *   Policy response = echoClient.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 Policy getIamPolicy(GetIamPolicyRequest request) { + return getIamPolicyCallable().call(request); + } + + // 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. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   GetIamPolicyRequest request =
+   *       GetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setOptions(GetPolicyOptions.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = echoClient.getIamPolicyCallable().futureCall(request);
+   *   // Do something.
+   *   Policy response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getIamPolicyCallable() { + return stub.getIamPolicyCallable(); + } + + // 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: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   TestIamPermissionsRequest request =
+   *       TestIamPermissionsRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .addAllPermissions(new ArrayList())
+   *           .build();
+   *   TestIamPermissionsResponse response = echoClient.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: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (EchoClient echoClient = EchoClient.create()) {
+   *   TestIamPermissionsRequest request =
+   *       TestIamPermissionsRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .addAllPermissions(new ArrayList())
+   *           .build();
+   *   ApiFuture future =
+   *       echoClient.testIamPermissionsCallable().futureCall(request);
+   *   // Do something.
+   *   TestIamPermissionsResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + testIamPermissionsCallable() { + return stub.testIamPermissionsCallable(); + } + @Override public final void close() { stub.close(); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/EchoSettings.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/EchoSettings.java index dfac5477a8..7725d2cdd2 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/EchoSettings.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/EchoSettings.java @@ -40,6 +40,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.showcase.v1beta1.stub.EchoStubSettings; import java.io.IOException; @@ -151,6 +156,22 @@ public UnaryCallSettings getLocationSettings() { return ((EchoStubSettings) getStubSettings()).getLocationSettings(); } + /** Returns the object with the settings used for calls to setIamPolicy. */ + public UnaryCallSettings setIamPolicySettings() { + return ((EchoStubSettings) getStubSettings()).setIamPolicySettings(); + } + + /** Returns the object with the settings used for calls to getIamPolicy. */ + public UnaryCallSettings getIamPolicySettings() { + return ((EchoStubSettings) getStubSettings()).getIamPolicySettings(); + } + + /** Returns the object with the settings used for calls to testIamPermissions. */ + public UnaryCallSettings + testIamPermissionsSettings() { + return ((EchoStubSettings) getStubSettings()).testIamPermissionsSettings(); + } + public static final EchoSettings create(EchoStubSettings stub) throws IOException { return new EchoSettings.Builder(stub.toBuilder()).build(); } @@ -335,6 +356,22 @@ public UnaryCallSettings.Builder getLocationSettin return getStubSettingsBuilder().getLocationSettings(); } + /** Returns the builder for the settings used for calls to setIamPolicy. */ + public UnaryCallSettings.Builder setIamPolicySettings() { + return getStubSettingsBuilder().setIamPolicySettings(); + } + + /** Returns the builder for the settings used for calls to getIamPolicy. */ + public UnaryCallSettings.Builder getIamPolicySettings() { + return getStubSettingsBuilder().getIamPolicySettings(); + } + + /** Returns the builder for the settings used for calls to testIamPermissions. */ + public UnaryCallSettings.Builder + testIamPermissionsSettings() { + return getStubSettingsBuilder().testIamPermissionsSettings(); + } + @Override public EchoSettings build() throws IOException { return new EchoSettings(this); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/IdentityClient.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/IdentityClient.java index e9d0a348b7..2641382e45 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/IdentityClient.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/IdentityClient.java @@ -30,6 +30,11 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.util.concurrent.MoreExecutors; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.stub.IdentityStub; import com.google.showcase.v1beta1.stub.IdentityStubSettings; @@ -835,6 +840,209 @@ public final UnaryCallable getLocationCallable() { return stub.getLocationCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sets the access control policy on the specified resource. Replaces any existing policy. + * + *

Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   SetIamPolicyRequest request =
+   *       SetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setPolicy(Policy.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   Policy response = identityClient.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); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sets the access control policy on the specified resource. Replaces any existing policy. + * + *

Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   SetIamPolicyRequest request =
+   *       SetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setPolicy(Policy.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = identityClient.setIamPolicyCallable().futureCall(request);
+   *   // Do something.
+   *   Policy response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable setIamPolicyCallable() { + return stub.setIamPolicyCallable(); + } + + // 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. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   GetIamPolicyRequest request =
+   *       GetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setOptions(GetPolicyOptions.newBuilder().build())
+   *           .build();
+   *   Policy response = identityClient.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 Policy getIamPolicy(GetIamPolicyRequest request) { + return getIamPolicyCallable().call(request); + } + + // 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. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   GetIamPolicyRequest request =
+   *       GetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setOptions(GetPolicyOptions.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = identityClient.getIamPolicyCallable().futureCall(request);
+   *   // Do something.
+   *   Policy response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getIamPolicyCallable() { + return stub.getIamPolicyCallable(); + } + + // 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: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   TestIamPermissionsRequest request =
+   *       TestIamPermissionsRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .addAllPermissions(new ArrayList())
+   *           .build();
+   *   TestIamPermissionsResponse response = identityClient.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: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (IdentityClient identityClient = IdentityClient.create()) {
+   *   TestIamPermissionsRequest request =
+   *       TestIamPermissionsRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .addAllPermissions(new ArrayList())
+   *           .build();
+   *   ApiFuture future =
+   *       identityClient.testIamPermissionsCallable().futureCall(request);
+   *   // Do something.
+   *   TestIamPermissionsResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + testIamPermissionsCallable() { + return stub.testIamPermissionsCallable(); + } + @Override public final void close() { stub.close(); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/IdentitySettings.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/IdentitySettings.java index 0cf54dacbc..81d98ff0c1 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/IdentitySettings.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/IdentitySettings.java @@ -36,6 +36,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.stub.IdentityStubSettings; import java.io.IOException; @@ -119,6 +124,22 @@ public UnaryCallSettings getLocationSettings() { return ((IdentityStubSettings) getStubSettings()).getLocationSettings(); } + /** Returns the object with the settings used for calls to setIamPolicy. */ + public UnaryCallSettings setIamPolicySettings() { + return ((IdentityStubSettings) getStubSettings()).setIamPolicySettings(); + } + + /** Returns the object with the settings used for calls to getIamPolicy. */ + public UnaryCallSettings getIamPolicySettings() { + return ((IdentityStubSettings) getStubSettings()).getIamPolicySettings(); + } + + /** Returns the object with the settings used for calls to testIamPermissions. */ + public UnaryCallSettings + testIamPermissionsSettings() { + return ((IdentityStubSettings) getStubSettings()).testIamPermissionsSettings(); + } + public static final IdentitySettings create(IdentityStubSettings stub) throws IOException { return new IdentitySettings.Builder(stub.toBuilder()).build(); } @@ -271,6 +292,22 @@ public UnaryCallSettings.Builder getLocationSettin return getStubSettingsBuilder().getLocationSettings(); } + /** Returns the builder for the settings used for calls to setIamPolicy. */ + public UnaryCallSettings.Builder setIamPolicySettings() { + return getStubSettingsBuilder().setIamPolicySettings(); + } + + /** Returns the builder for the settings used for calls to getIamPolicy. */ + public UnaryCallSettings.Builder getIamPolicySettings() { + return getStubSettingsBuilder().getIamPolicySettings(); + } + + /** Returns the builder for the settings used for calls to testIamPermissions. */ + public UnaryCallSettings.Builder + testIamPermissionsSettings() { + return getStubSettingsBuilder().testIamPermissionsSettings(); + } + @Override public IdentitySettings build() throws IOException { return new IdentitySettings(this); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/MessagingClient.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/MessagingClient.java index d2476e05ee..01e09e2257 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/MessagingClient.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/MessagingClient.java @@ -36,6 +36,11 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.util.concurrent.MoreExecutors; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.protobuf.ByteString; import com.google.protobuf.Empty; @@ -2105,6 +2110,209 @@ public final UnaryCallable getLocationCallable() { return stub.getLocationCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sets the access control policy on the specified resource. Replaces any existing policy. + * + *

Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   SetIamPolicyRequest request =
+   *       SetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setPolicy(Policy.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   Policy response = messagingClient.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); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sets the access control policy on the specified resource. Replaces any existing policy. + * + *

Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   SetIamPolicyRequest request =
+   *       SetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setPolicy(Policy.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = messagingClient.setIamPolicyCallable().futureCall(request);
+   *   // Do something.
+   *   Policy response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable setIamPolicyCallable() { + return stub.setIamPolicyCallable(); + } + + // 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. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   GetIamPolicyRequest request =
+   *       GetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setOptions(GetPolicyOptions.newBuilder().build())
+   *           .build();
+   *   Policy response = messagingClient.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 Policy getIamPolicy(GetIamPolicyRequest request) { + return getIamPolicyCallable().call(request); + } + + // 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. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   GetIamPolicyRequest request =
+   *       GetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setOptions(GetPolicyOptions.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = messagingClient.getIamPolicyCallable().futureCall(request);
+   *   // Do something.
+   *   Policy response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getIamPolicyCallable() { + return stub.getIamPolicyCallable(); + } + + // 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: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   TestIamPermissionsRequest request =
+   *       TestIamPermissionsRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .addAllPermissions(new ArrayList())
+   *           .build();
+   *   TestIamPermissionsResponse response = messagingClient.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: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (MessagingClient messagingClient = MessagingClient.create()) {
+   *   TestIamPermissionsRequest request =
+   *       TestIamPermissionsRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .addAllPermissions(new ArrayList())
+   *           .build();
+   *   ApiFuture future =
+   *       messagingClient.testIamPermissionsCallable().futureCall(request);
+   *   // Do something.
+   *   TestIamPermissionsResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + testIamPermissionsCallable() { + return stub.testIamPermissionsCallable(); + } + @Override public final void close() { stub.close(); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/MessagingSettings.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/MessagingSettings.java index 9b699b6e94..102ec93cd4 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/MessagingSettings.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/MessagingSettings.java @@ -40,6 +40,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.stub.MessagingStubSettings; @@ -177,6 +182,22 @@ public UnaryCallSettings getLocationSettings() { return ((MessagingStubSettings) getStubSettings()).getLocationSettings(); } + /** Returns the object with the settings used for calls to setIamPolicy. */ + public UnaryCallSettings setIamPolicySettings() { + return ((MessagingStubSettings) getStubSettings()).setIamPolicySettings(); + } + + /** Returns the object with the settings used for calls to getIamPolicy. */ + public UnaryCallSettings getIamPolicySettings() { + return ((MessagingStubSettings) getStubSettings()).getIamPolicySettings(); + } + + /** Returns the object with the settings used for calls to testIamPermissions. */ + public UnaryCallSettings + testIamPermissionsSettings() { + return ((MessagingStubSettings) getStubSettings()).testIamPermissionsSettings(); + } + public static final MessagingSettings create(MessagingStubSettings stub) throws IOException { return new MessagingSettings.Builder(stub.toBuilder()).build(); } @@ -384,6 +405,22 @@ public UnaryCallSettings.Builder getLocationSettin return getStubSettingsBuilder().getLocationSettings(); } + /** Returns the builder for the settings used for calls to setIamPolicy. */ + public UnaryCallSettings.Builder setIamPolicySettings() { + return getStubSettingsBuilder().setIamPolicySettings(); + } + + /** Returns the builder for the settings used for calls to getIamPolicy. */ + public UnaryCallSettings.Builder getIamPolicySettings() { + return getStubSettingsBuilder().getIamPolicySettings(); + } + + /** Returns the builder for the settings used for calls to testIamPermissions. */ + public UnaryCallSettings.Builder + testIamPermissionsSettings() { + return getStubSettingsBuilder().testIamPermissionsSettings(); + } + @Override public MessagingSettings build() throws IOException { return new MessagingSettings(this); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/SequenceServiceClient.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/SequenceServiceClient.java index 378bc855b3..54faf59462 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/SequenceServiceClient.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/SequenceServiceClient.java @@ -31,6 +31,11 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.util.concurrent.MoreExecutors; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.stub.SequenceServiceStub; import com.google.showcase.v1beta1.stub.SequenceServiceStubSettings; @@ -865,6 +870,209 @@ public final UnaryCallable getLocationCallable() { return stub.getLocationCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sets the access control policy on the specified resource. Replaces any existing policy. + * + *

Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   SetIamPolicyRequest request =
+   *       SetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setPolicy(Policy.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   Policy response = sequenceServiceClient.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); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sets the access control policy on the specified resource. Replaces any existing policy. + * + *

Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   SetIamPolicyRequest request =
+   *       SetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setPolicy(Policy.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = sequenceServiceClient.setIamPolicyCallable().futureCall(request);
+   *   // Do something.
+   *   Policy response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable setIamPolicyCallable() { + return stub.setIamPolicyCallable(); + } + + // 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. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   GetIamPolicyRequest request =
+   *       GetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setOptions(GetPolicyOptions.newBuilder().build())
+   *           .build();
+   *   Policy response = sequenceServiceClient.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 Policy getIamPolicy(GetIamPolicyRequest request) { + return getIamPolicyCallable().call(request); + } + + // 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. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   GetIamPolicyRequest request =
+   *       GetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setOptions(GetPolicyOptions.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = sequenceServiceClient.getIamPolicyCallable().futureCall(request);
+   *   // Do something.
+   *   Policy response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getIamPolicyCallable() { + return stub.getIamPolicyCallable(); + } + + // 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: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   TestIamPermissionsRequest request =
+   *       TestIamPermissionsRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .addAllPermissions(new ArrayList())
+   *           .build();
+   *   TestIamPermissionsResponse response = sequenceServiceClient.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: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) {
+   *   TestIamPermissionsRequest request =
+   *       TestIamPermissionsRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .addAllPermissions(new ArrayList())
+   *           .build();
+   *   ApiFuture future =
+   *       sequenceServiceClient.testIamPermissionsCallable().futureCall(request);
+   *   // Do something.
+   *   TestIamPermissionsResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + testIamPermissionsCallable() { + return stub.testIamPermissionsCallable(); + } + @Override public final void close() { stub.close(); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/SequenceServiceSettings.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/SequenceServiceSettings.java index 4b1de81967..1d14057c11 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/SequenceServiceSettings.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/SequenceServiceSettings.java @@ -36,6 +36,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.stub.SequenceServiceStubSettings; import java.io.IOException; @@ -128,6 +133,22 @@ public UnaryCallSettings getLocationSettings() { return ((SequenceServiceStubSettings) getStubSettings()).getLocationSettings(); } + /** Returns the object with the settings used for calls to setIamPolicy. */ + public UnaryCallSettings setIamPolicySettings() { + return ((SequenceServiceStubSettings) getStubSettings()).setIamPolicySettings(); + } + + /** Returns the object with the settings used for calls to getIamPolicy. */ + public UnaryCallSettings getIamPolicySettings() { + return ((SequenceServiceStubSettings) getStubSettings()).getIamPolicySettings(); + } + + /** Returns the object with the settings used for calls to testIamPermissions. */ + public UnaryCallSettings + testIamPermissionsSettings() { + return ((SequenceServiceStubSettings) getStubSettings()).testIamPermissionsSettings(); + } + public static final SequenceServiceSettings create(SequenceServiceStubSettings stub) throws IOException { return new SequenceServiceSettings.Builder(stub.toBuilder()).build(); @@ -290,6 +311,22 @@ public UnaryCallSettings.Builder getLocationSettin return getStubSettingsBuilder().getLocationSettings(); } + /** Returns the builder for the settings used for calls to setIamPolicy. */ + public UnaryCallSettings.Builder setIamPolicySettings() { + return getStubSettingsBuilder().setIamPolicySettings(); + } + + /** Returns the builder for the settings used for calls to getIamPolicy. */ + public UnaryCallSettings.Builder getIamPolicySettings() { + return getStubSettingsBuilder().getIamPolicySettings(); + } + + /** Returns the builder for the settings used for calls to testIamPermissions. */ + public UnaryCallSettings.Builder + testIamPermissionsSettings() { + return getStubSettingsBuilder().testIamPermissionsSettings(); + } + @Override public SequenceServiceSettings build() throws IOException { return new SequenceServiceSettings(this); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/TestingClient.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/TestingClient.java index a0cacc1455..acb13d6b68 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/TestingClient.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/TestingClient.java @@ -30,6 +30,11 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.util.concurrent.MoreExecutors; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.stub.TestingStub; import com.google.showcase.v1beta1.stub.TestingStubSettings; @@ -866,6 +871,209 @@ public final UnaryCallable getLocationCallable() { return stub.getLocationCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sets the access control policy on the specified resource. Replaces any existing policy. + * + *

Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   SetIamPolicyRequest request =
+   *       SetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setPolicy(Policy.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   Policy response = testingClient.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); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Sets the access control policy on the specified resource. Replaces any existing policy. + * + *

Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   SetIamPolicyRequest request =
+   *       SetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setPolicy(Policy.newBuilder().build())
+   *           .setUpdateMask(FieldMask.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = testingClient.setIamPolicyCallable().futureCall(request);
+   *   // Do something.
+   *   Policy response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable setIamPolicyCallable() { + return stub.setIamPolicyCallable(); + } + + // 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. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   GetIamPolicyRequest request =
+   *       GetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setOptions(GetPolicyOptions.newBuilder().build())
+   *           .build();
+   *   Policy response = testingClient.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 Policy getIamPolicy(GetIamPolicyRequest request) { + return getIamPolicyCallable().call(request); + } + + // 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. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   GetIamPolicyRequest request =
+   *       GetIamPolicyRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .setOptions(GetPolicyOptions.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = testingClient.getIamPolicyCallable().futureCall(request);
+   *   // Do something.
+   *   Policy response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable getIamPolicyCallable() { + return stub.getIamPolicyCallable(); + } + + // 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: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   TestIamPermissionsRequest request =
+   *       TestIamPermissionsRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .addAllPermissions(new ArrayList())
+   *           .build();
+   *   TestIamPermissionsResponse response = testingClient.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: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (TestingClient testingClient = TestingClient.create()) {
+   *   TestIamPermissionsRequest request =
+   *       TestIamPermissionsRequest.newBuilder()
+   *           .setResource(
+   *               BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]")
+   *                   .toString())
+   *           .addAllPermissions(new ArrayList())
+   *           .build();
+   *   ApiFuture future =
+   *       testingClient.testIamPermissionsCallable().futureCall(request);
+   *   // Do something.
+   *   TestIamPermissionsResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + testIamPermissionsCallable() { + return stub.testIamPermissionsCallable(); + } + @Override public final void close() { stub.close(); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/TestingSettings.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/TestingSettings.java index 7fb5f25b5b..7c864ae4eb 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/TestingSettings.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/TestingSettings.java @@ -37,6 +37,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.stub.TestingStubSettings; import java.io.IOException; @@ -136,6 +141,22 @@ public UnaryCallSettings getLocationSettings() { return ((TestingStubSettings) getStubSettings()).getLocationSettings(); } + /** Returns the object with the settings used for calls to setIamPolicy. */ + public UnaryCallSettings setIamPolicySettings() { + return ((TestingStubSettings) getStubSettings()).setIamPolicySettings(); + } + + /** Returns the object with the settings used for calls to getIamPolicy. */ + public UnaryCallSettings getIamPolicySettings() { + return ((TestingStubSettings) getStubSettings()).getIamPolicySettings(); + } + + /** Returns the object with the settings used for calls to testIamPermissions. */ + public UnaryCallSettings + testIamPermissionsSettings() { + return ((TestingStubSettings) getStubSettings()).testIamPermissionsSettings(); + } + public static final TestingSettings create(TestingStubSettings stub) throws IOException { return new TestingSettings.Builder(stub.toBuilder()).build(); } @@ -306,6 +327,22 @@ public UnaryCallSettings.Builder getLocationSettin return getStubSettingsBuilder().getLocationSettings(); } + /** Returns the builder for the settings used for calls to setIamPolicy. */ + public UnaryCallSettings.Builder setIamPolicySettings() { + return getStubSettingsBuilder().setIamPolicySettings(); + } + + /** Returns the builder for the settings used for calls to getIamPolicy. */ + public UnaryCallSettings.Builder getIamPolicySettings() { + return getStubSettingsBuilder().getIamPolicySettings(); + } + + /** Returns the builder for the settings used for calls to testIamPermissions. */ + public UnaryCallSettings.Builder + testIamPermissionsSettings() { + return getStubSettingsBuilder().testIamPermissionsSettings(); + } + @Override public TestingSettings build() throws IOException { return new TestingSettings(this); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/gapic_metadata.json b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/gapic_metadata.json index b79bfb905f..3d10c53f8d 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/gapic_metadata.json +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/gapic_metadata.json @@ -13,6 +13,9 @@ "GetEnum": { "methods": ["getEnum", "getEnumCallable"] }, + "GetIamPolicy": { + "methods": ["getIamPolicy", "getIamPolicyCallable"] + }, "GetLocation": { "methods": ["getLocation", "getLocationCallable"] }, @@ -43,6 +46,12 @@ "RepeatDataSimplePath": { "methods": ["repeatDataSimplePath", "repeatDataSimplePathCallable"] }, + "SetIamPolicy": { + "methods": ["setIamPolicy", "setIamPolicyCallable"] + }, + "TestIamPermissions": { + "methods": ["testIamPermissions", "testIamPermissionsCallable"] + }, "VerifyEnum": { "methods": ["verifyEnum", "verifyEnumCallable"] } @@ -70,6 +79,9 @@ "Expand": { "methods": ["expandCallable"] }, + "GetIamPolicy": { + "methods": ["getIamPolicy", "getIamPolicyCallable"] + }, "GetLocation": { "methods": ["getLocation", "getLocationCallable"] }, @@ -85,6 +97,12 @@ "PagedExpandLegacyMapped": { "methods": ["pagedExpandLegacyMapped", "pagedExpandLegacyMappedPagedCallable", "pagedExpandLegacyMappedCallable"] }, + "SetIamPolicy": { + "methods": ["setIamPolicy", "setIamPolicyCallable"] + }, + "TestIamPermissions": { + "methods": ["testIamPermissions", "testIamPermissionsCallable"] + }, "Wait": { "methods": ["waitAsync", "waitOperationCallable", "waitCallable"] } @@ -103,6 +121,9 @@ "DeleteUser": { "methods": ["deleteUser", "deleteUser", "deleteUser", "deleteUserCallable"] }, + "GetIamPolicy": { + "methods": ["getIamPolicy", "getIamPolicyCallable"] + }, "GetLocation": { "methods": ["getLocation", "getLocationCallable"] }, @@ -115,6 +136,12 @@ "ListUsers": { "methods": ["listUsers", "listUsersPagedCallable", "listUsersCallable"] }, + "SetIamPolicy": { + "methods": ["setIamPolicy", "setIamPolicyCallable"] + }, + "TestIamPermissions": { + "methods": ["testIamPermissions", "testIamPermissionsCallable"] + }, "UpdateUser": { "methods": ["updateUser", "updateUserCallable"] } @@ -145,6 +172,9 @@ "GetBlurb": { "methods": ["getBlurb", "getBlurb", "getBlurb", "getBlurbCallable"] }, + "GetIamPolicy": { + "methods": ["getIamPolicy", "getIamPolicyCallable"] + }, "GetLocation": { "methods": ["getLocation", "getLocationCallable"] }, @@ -166,9 +196,15 @@ "SendBlurbs": { "methods": ["sendBlurbsCallable"] }, + "SetIamPolicy": { + "methods": ["setIamPolicy", "setIamPolicyCallable"] + }, "StreamBlurbs": { "methods": ["streamBlurbsCallable"] }, + "TestIamPermissions": { + "methods": ["testIamPermissions", "testIamPermissionsCallable"] + }, "UpdateBlurb": { "methods": ["updateBlurb", "updateBlurbCallable"] }, @@ -196,6 +232,9 @@ "CreateStreamingSequence": { "methods": ["createStreamingSequence", "createStreamingSequence", "createStreamingSequenceCallable"] }, + "GetIamPolicy": { + "methods": ["getIamPolicy", "getIamPolicyCallable"] + }, "GetLocation": { "methods": ["getLocation", "getLocationCallable"] }, @@ -207,6 +246,12 @@ }, "ListLocations": { "methods": ["listLocations", "listLocationsPagedCallable", "listLocationsCallable"] + }, + "SetIamPolicy": { + "methods": ["setIamPolicy", "setIamPolicyCallable"] + }, + "TestIamPermissions": { + "methods": ["testIamPermissions", "testIamPermissionsCallable"] } } } @@ -226,6 +271,9 @@ "DeleteTest": { "methods": ["deleteTest", "deleteTestCallable"] }, + "GetIamPolicy": { + "methods": ["getIamPolicy", "getIamPolicyCallable"] + }, "GetLocation": { "methods": ["getLocation", "getLocationCallable"] }, @@ -244,6 +292,12 @@ "ReportSession": { "methods": ["reportSession", "reportSessionCallable"] }, + "SetIamPolicy": { + "methods": ["setIamPolicy", "setIamPolicyCallable"] + }, + "TestIamPermissions": { + "methods": ["testIamPermissions", "testIamPermissionsCallable"] + }, "VerifyTest": { "methods": ["verifyTest", "verifyTestCallable"] } diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ComplianceStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ComplianceStub.java index 1ad896afb3..033e6024fc 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ComplianceStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ComplianceStub.java @@ -25,6 +25,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.showcase.v1beta1.EnumRequest; import com.google.showcase.v1beta1.EnumResponse; import com.google.showcase.v1beta1.RepeatRequest; @@ -95,6 +100,19 @@ public UnaryCallable getLocationCallable() { throw new UnsupportedOperationException("Not implemented: getLocationCallable()"); } + public UnaryCallable setIamPolicyCallable() { + throw new UnsupportedOperationException("Not implemented: setIamPolicyCallable()"); + } + + public UnaryCallable getIamPolicyCallable() { + throw new UnsupportedOperationException("Not implemented: getIamPolicyCallable()"); + } + + public UnaryCallable + testIamPermissionsCallable() { + throw new UnsupportedOperationException("Not implemented: testIamPermissionsCallable()"); + } + @Override public abstract void close(); } diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ComplianceStubSettings.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ComplianceStubSettings.java index 6cb3ac63de..2fb7b2745c 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ComplianceStubSettings.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ComplianceStubSettings.java @@ -51,6 +51,11 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.showcase.v1beta1.EnumRequest; import com.google.showcase.v1beta1.EnumResponse; import com.google.showcase.v1beta1.RepeatRequest; @@ -117,6 +122,10 @@ public class ComplianceStubSettings extends StubSettings ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse> listLocationsSettings; private final UnaryCallSettings getLocationSettings; + private final UnaryCallSettings setIamPolicySettings; + private final UnaryCallSettings getIamPolicySettings; + private final UnaryCallSettings + testIamPermissionsSettings; private static final PagedListDescriptor LIST_LOCATIONS_PAGE_STR_DESC = @@ -232,6 +241,22 @@ public UnaryCallSettings getLocationSettings() { return getLocationSettings; } + /** Returns the object with the settings used for calls to setIamPolicy. */ + public UnaryCallSettings setIamPolicySettings() { + return setIamPolicySettings; + } + + /** Returns the object with the settings used for calls to getIamPolicy. */ + public UnaryCallSettings getIamPolicySettings() { + return getIamPolicySettings; + } + + /** Returns the object with the settings used for calls to testIamPermissions. */ + public UnaryCallSettings + testIamPermissionsSettings() { + return testIamPermissionsSettings; + } + public ComplianceStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() @@ -351,6 +376,9 @@ protected ComplianceStubSettings(Builder settingsBuilder) throws IOException { verifyEnumSettings = settingsBuilder.verifyEnumSettings().build(); listLocationsSettings = settingsBuilder.listLocationsSettings().build(); getLocationSettings = settingsBuilder.getLocationSettings().build(); + setIamPolicySettings = settingsBuilder.setIamPolicySettings().build(); + getIamPolicySettings = settingsBuilder.getIamPolicySettings().build(); + testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build(); } /** Builder for ComplianceStubSettings. */ @@ -376,6 +404,10 @@ public static class Builder extends StubSettings.Builder listLocationsSettings; private final UnaryCallSettings.Builder getLocationSettings; + private final UnaryCallSettings.Builder setIamPolicySettings; + private final UnaryCallSettings.Builder getIamPolicySettings; + private final UnaryCallSettings.Builder + testIamPermissionsSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -415,6 +447,9 @@ protected Builder(ClientContext clientContext) { verifyEnumSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); listLocationsSettings = PagedCallSettings.newBuilder(LIST_LOCATIONS_PAGE_STR_FACT); getLocationSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + setIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + getIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -429,7 +464,10 @@ protected Builder(ClientContext clientContext) { getEnumSettings, verifyEnumSettings, listLocationsSettings, - getLocationSettings); + getLocationSettings, + setIamPolicySettings, + getIamPolicySettings, + testIamPermissionsSettings); initDefaults(this); } @@ -449,6 +487,9 @@ protected Builder(ComplianceStubSettings settings) { verifyEnumSettings = settings.verifyEnumSettings.toBuilder(); listLocationsSettings = settings.listLocationsSettings.toBuilder(); getLocationSettings = settings.getLocationSettings.toBuilder(); + setIamPolicySettings = settings.setIamPolicySettings.toBuilder(); + getIamPolicySettings = settings.getIamPolicySettings.toBuilder(); + testIamPermissionsSettings = settings.testIamPermissionsSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -463,7 +504,10 @@ protected Builder(ComplianceStubSettings settings) { getEnumSettings, verifyEnumSettings, listLocationsSettings, - getLocationSettings); + getLocationSettings, + setIamPolicySettings, + getIamPolicySettings, + testIamPermissionsSettings); } private static Builder createDefault() { @@ -553,6 +597,21 @@ private static Builder initDefaults(Builder builder) { .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + builder + .setIamPolicySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .getIamPolicySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .testIamPermissionsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + return builder; } @@ -635,6 +694,22 @@ public UnaryCallSettings.Builder getLocationSettin return getLocationSettings; } + /** Returns the builder for the settings used for calls to setIamPolicy. */ + public UnaryCallSettings.Builder setIamPolicySettings() { + return setIamPolicySettings; + } + + /** Returns the builder for the settings used for calls to getIamPolicy. */ + public UnaryCallSettings.Builder getIamPolicySettings() { + return getIamPolicySettings; + } + + /** Returns the builder for the settings used for calls to testIamPermissions. */ + public UnaryCallSettings.Builder + testIamPermissionsSettings() { + return testIamPermissionsSettings; + } + @Override public ComplianceStubSettings build() throws IOException { return new ComplianceStubSettings(this); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/EchoStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/EchoStub.java index 04316a20cf..a2aca8c1a0 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/EchoStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/EchoStub.java @@ -31,6 +31,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.longrunning.stub.OperationsStub; import com.google.showcase.v1beta1.BlockRequest; @@ -129,6 +134,19 @@ public UnaryCallable getLocationCallable() { throw new UnsupportedOperationException("Not implemented: getLocationCallable()"); } + public UnaryCallable setIamPolicyCallable() { + throw new UnsupportedOperationException("Not implemented: setIamPolicyCallable()"); + } + + public UnaryCallable getIamPolicyCallable() { + throw new UnsupportedOperationException("Not implemented: getIamPolicyCallable()"); + } + + public UnaryCallable + testIamPermissionsCallable() { + throw new UnsupportedOperationException("Not implemented: testIamPermissionsCallable()"); + } + @Override public abstract void close(); } diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/EchoStubSettings.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/EchoStubSettings.java index 8228740686..8e1d7bb5e2 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/EchoStubSettings.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/EchoStubSettings.java @@ -59,6 +59,11 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.showcase.v1beta1.BlockRequest; import com.google.showcase.v1beta1.BlockResponse; @@ -142,6 +147,10 @@ public class EchoStubSettings extends StubSettings { ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse> listLocationsSettings; private final UnaryCallSettings getLocationSettings; + private final UnaryCallSettings setIamPolicySettings; + private final UnaryCallSettings getIamPolicySettings; + private final UnaryCallSettings + testIamPermissionsSettings; private static final PagedListDescriptor PAGED_EXPAND_PAGE_STR_DESC = @@ -381,6 +390,22 @@ public UnaryCallSettings getLocationSettings() { return getLocationSettings; } + /** Returns the object with the settings used for calls to setIamPolicy. */ + public UnaryCallSettings setIamPolicySettings() { + return setIamPolicySettings; + } + + /** Returns the object with the settings used for calls to getIamPolicy. */ + public UnaryCallSettings getIamPolicySettings() { + return getIamPolicySettings; + } + + /** Returns the object with the settings used for calls to testIamPermissions. */ + public UnaryCallSettings + testIamPermissionsSettings() { + return testIamPermissionsSettings; + } + public EchoStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() @@ -497,6 +522,9 @@ protected EchoStubSettings(Builder settingsBuilder) throws IOException { blockSettings = settingsBuilder.blockSettings().build(); listLocationsSettings = settingsBuilder.listLocationsSettings().build(); getLocationSettings = settingsBuilder.getLocationSettings().build(); + setIamPolicySettings = settingsBuilder.setIamPolicySettings().build(); + getIamPolicySettings = settingsBuilder.getIamPolicySettings().build(); + testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build(); } /** Builder for EchoStubSettings. */ @@ -524,6 +552,10 @@ public static class Builder extends StubSettings.Builder listLocationsSettings; private final UnaryCallSettings.Builder getLocationSettings; + private final UnaryCallSettings.Builder setIamPolicySettings; + private final UnaryCallSettings.Builder getIamPolicySettings; + private final UnaryCallSettings.Builder + testIamPermissionsSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -587,6 +619,9 @@ protected Builder(ClientContext clientContext) { blockSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); listLocationsSettings = PagedCallSettings.newBuilder(LIST_LOCATIONS_PAGE_STR_FACT); getLocationSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + setIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + getIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -597,7 +632,10 @@ protected Builder(ClientContext clientContext) { waitSettings, blockSettings, listLocationsSettings, - getLocationSettings); + getLocationSettings, + setIamPolicySettings, + getIamPolicySettings, + testIamPermissionsSettings); initDefaults(this); } @@ -616,6 +654,9 @@ protected Builder(EchoStubSettings settings) { blockSettings = settings.blockSettings.toBuilder(); listLocationsSettings = settings.listLocationsSettings.toBuilder(); getLocationSettings = settings.getLocationSettings.toBuilder(); + setIamPolicySettings = settings.setIamPolicySettings.toBuilder(); + getIamPolicySettings = settings.getIamPolicySettings.toBuilder(); + testIamPermissionsSettings = settings.testIamPermissionsSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -626,7 +667,10 @@ protected Builder(EchoStubSettings settings) { waitSettings, blockSettings, listLocationsSettings, - getLocationSettings); + getLocationSettings, + setIamPolicySettings, + getIamPolicySettings, + testIamPermissionsSettings); } private static Builder createDefault() { @@ -701,6 +745,21 @@ private static Builder initDefaults(Builder builder) { .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + builder + .setIamPolicySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .getIamPolicySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .testIamPermissionsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + builder .waitOperationSettings() .setInitialCallSettings( @@ -814,6 +873,22 @@ public UnaryCallSettings.Builder getLocationSettin return getLocationSettings; } + /** Returns the builder for the settings used for calls to setIamPolicy. */ + public UnaryCallSettings.Builder setIamPolicySettings() { + return setIamPolicySettings; + } + + /** Returns the builder for the settings used for calls to getIamPolicy. */ + public UnaryCallSettings.Builder getIamPolicySettings() { + return getIamPolicySettings; + } + + /** Returns the builder for the settings used for calls to testIamPermissions. */ + public UnaryCallSettings.Builder + testIamPermissionsSettings() { + return testIamPermissionsSettings; + } + @Override public EchoStubSettings build() throws IOException { return new EchoStubSettings(this); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcComplianceStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcComplianceStub.java index c6dcf25bf3..876e5f3eef 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcComplianceStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcComplianceStub.java @@ -30,6 +30,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.showcase.v1beta1.EnumRequest; import com.google.showcase.v1beta1.EnumResponse; @@ -159,6 +164,33 @@ public class GrpcComplianceStub extends ComplianceStub { .setResponseMarshaller(ProtoUtils.marshaller(Location.getDefaultInstance())) .build(); + private static final MethodDescriptor setIamPolicyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/SetIamPolicy") + .setRequestMarshaller(ProtoUtils.marshaller(SetIamPolicyRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) + .build(); + + private static final MethodDescriptor getIamPolicyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/GetIamPolicy") + .setRequestMarshaller(ProtoUtils.marshaller(GetIamPolicyRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + testIamPermissionsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/TestIamPermissions") + .setRequestMarshaller( + ProtoUtils.marshaller(TestIamPermissionsRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(TestIamPermissionsResponse.getDefaultInstance())) + .build(); + private final UnaryCallable repeatDataBodyCallable; private final UnaryCallable repeatDataBodyInfoCallable; private final UnaryCallable repeatDataQueryCallable; @@ -173,6 +205,10 @@ public class GrpcComplianceStub extends ComplianceStub { private final UnaryCallable listLocationsPagedCallable; private final UnaryCallable getLocationCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; private final BackgroundResource backgroundResources; private final GrpcOperationsStub operationsStub; @@ -306,6 +342,37 @@ protected GrpcComplianceStub( return builder.build(); }) .build(); + GrpcCallSettings setIamPolicyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + GrpcCallSettings getIamPolicyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + GrpcCallSettings + testIamPermissionsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); this.repeatDataBodyCallable = callableFactory.createUnaryCallable( @@ -358,6 +425,17 @@ protected GrpcComplianceStub( this.getLocationCallable = callableFactory.createUnaryCallable( getLocationTransportSettings, settings.getLocationSettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -433,6 +511,22 @@ public UnaryCallable getLocationCallable() { return getLocationCallable; } + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + @Override public final void close() { try { diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcEchoStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcEchoStub.java index 36c6e630d5..fdaf681056 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcEchoStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcEchoStub.java @@ -37,6 +37,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.showcase.v1beta1.BlockRequest; @@ -165,6 +170,33 @@ public class GrpcEchoStub extends EchoStub { .setResponseMarshaller(ProtoUtils.marshaller(Location.getDefaultInstance())) .build(); + private static final MethodDescriptor setIamPolicyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/SetIamPolicy") + .setRequestMarshaller(ProtoUtils.marshaller(SetIamPolicyRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) + .build(); + + private static final MethodDescriptor getIamPolicyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/GetIamPolicy") + .setRequestMarshaller(ProtoUtils.marshaller(GetIamPolicyRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + testIamPermissionsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/TestIamPermissions") + .setRequestMarshaller( + ProtoUtils.marshaller(TestIamPermissionsRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(TestIamPermissionsResponse.getDefaultInstance())) + .build(); + private final UnaryCallable echoCallable; private final ServerStreamingCallable expandCallable; private final ClientStreamingCallable collectCallable; @@ -185,6 +217,10 @@ public class GrpcEchoStub extends EchoStub { private final UnaryCallable listLocationsPagedCallable; private final UnaryCallable getLocationCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; private final BackgroundResource backgroundResources; private final GrpcOperationsStub operationsStub; @@ -309,6 +345,37 @@ protected GrpcEchoStub( return builder.build(); }) .build(); + GrpcCallSettings setIamPolicyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + GrpcCallSettings getIamPolicyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + GrpcCallSettings + testIamPermissionsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); this.echoCallable = callableFactory.createUnaryCallable( @@ -361,6 +428,17 @@ protected GrpcEchoStub( this.getLocationCallable = callableFactory.createUnaryCallable( getLocationTransportSettings, settings.getLocationSettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -448,6 +526,22 @@ public UnaryCallable getLocationCallable() { return getLocationCallable; } + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + @Override public final void close() { try { diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcIdentityStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcIdentityStub.java index 1e2c7c0b4c..facfb04c0d 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcIdentityStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcIdentityStub.java @@ -31,6 +31,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.CreateUserRequest; @@ -116,6 +121,33 @@ public class GrpcIdentityStub extends IdentityStub { .setResponseMarshaller(ProtoUtils.marshaller(Location.getDefaultInstance())) .build(); + private static final MethodDescriptor setIamPolicyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/SetIamPolicy") + .setRequestMarshaller(ProtoUtils.marshaller(SetIamPolicyRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) + .build(); + + private static final MethodDescriptor getIamPolicyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/GetIamPolicy") + .setRequestMarshaller(ProtoUtils.marshaller(GetIamPolicyRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + testIamPermissionsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/TestIamPermissions") + .setRequestMarshaller( + ProtoUtils.marshaller(TestIamPermissionsRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(TestIamPermissionsResponse.getDefaultInstance())) + .build(); + private final UnaryCallable createUserCallable; private final UnaryCallable getUserCallable; private final UnaryCallable updateUserCallable; @@ -126,6 +158,10 @@ public class GrpcIdentityStub extends IdentityStub { private final UnaryCallable listLocationsPagedCallable; private final UnaryCallable getLocationCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; private final BackgroundResource backgroundResources; private final GrpcOperationsStub operationsStub; @@ -224,6 +260,37 @@ protected GrpcIdentityStub( return builder.build(); }) .build(); + GrpcCallSettings setIamPolicyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + GrpcCallSettings getIamPolicyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + GrpcCallSettings + testIamPermissionsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); this.createUserCallable = callableFactory.createUnaryCallable( @@ -252,6 +319,17 @@ protected GrpcIdentityStub( this.getLocationCallable = callableFactory.createUnaryCallable( getLocationTransportSettings, settings.getLocationSettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -307,6 +385,22 @@ public UnaryCallable getLocationCallable() { return getLocationCallable; } + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + @Override public final void close() { try { diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcMessagingStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcMessagingStub.java index 52bc2b8c36..8846164182 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcMessagingStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcMessagingStub.java @@ -36,6 +36,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; @@ -215,6 +220,33 @@ public class GrpcMessagingStub extends MessagingStub { .setResponseMarshaller(ProtoUtils.marshaller(Location.getDefaultInstance())) .build(); + private static final MethodDescriptor setIamPolicyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/SetIamPolicy") + .setRequestMarshaller(ProtoUtils.marshaller(SetIamPolicyRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) + .build(); + + private static final MethodDescriptor getIamPolicyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/GetIamPolicy") + .setRequestMarshaller(ProtoUtils.marshaller(GetIamPolicyRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + testIamPermissionsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/TestIamPermissions") + .setRequestMarshaller( + ProtoUtils.marshaller(TestIamPermissionsRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(TestIamPermissionsResponse.getDefaultInstance())) + .build(); + private final UnaryCallable createRoomCallable; private final UnaryCallable getRoomCallable; private final UnaryCallable updateRoomCallable; @@ -238,6 +270,10 @@ public class GrpcMessagingStub extends MessagingStub { private final UnaryCallable listLocationsPagedCallable; private final UnaryCallable getLocationCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; private final BackgroundResource backgroundResources; private final GrpcOperationsStub operationsStub; @@ -422,6 +458,37 @@ protected GrpcMessagingStub( return builder.build(); }) .build(); + GrpcCallSettings setIamPolicyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + GrpcCallSettings getIamPolicyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + GrpcCallSettings + testIamPermissionsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); this.createRoomCallable = callableFactory.createUnaryCallable( @@ -486,6 +553,17 @@ protected GrpcMessagingStub( this.getLocationCallable = callableFactory.createUnaryCallable( getLocationTransportSettings, settings.getLocationSettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -597,6 +675,22 @@ public UnaryCallable getLocationCallable() { return getLocationCallable; } + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + @Override public final void close() { try { diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcSequenceServiceStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcSequenceServiceStub.java index e2c47d1117..422fada24a 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcSequenceServiceStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcSequenceServiceStub.java @@ -31,6 +31,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.AttemptSequenceRequest; @@ -144,6 +149,33 @@ public class GrpcSequenceServiceStub extends SequenceServiceStub { .setResponseMarshaller(ProtoUtils.marshaller(Location.getDefaultInstance())) .build(); + private static final MethodDescriptor setIamPolicyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/SetIamPolicy") + .setRequestMarshaller(ProtoUtils.marshaller(SetIamPolicyRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) + .build(); + + private static final MethodDescriptor getIamPolicyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/GetIamPolicy") + .setRequestMarshaller(ProtoUtils.marshaller(GetIamPolicyRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + testIamPermissionsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/TestIamPermissions") + .setRequestMarshaller( + ProtoUtils.marshaller(TestIamPermissionsRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(TestIamPermissionsResponse.getDefaultInstance())) + .build(); + private final UnaryCallable createSequenceCallable; private final UnaryCallable createStreamingSequenceCallable; @@ -158,6 +190,10 @@ public class GrpcSequenceServiceStub extends SequenceServiceStub { private final UnaryCallable listLocationsPagedCallable; private final UnaryCallable getLocationCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; private final BackgroundResource backgroundResources; private final GrpcOperationsStub operationsStub; @@ -276,6 +312,37 @@ protected GrpcSequenceServiceStub( return builder.build(); }) .build(); + GrpcCallSettings setIamPolicyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + GrpcCallSettings getIamPolicyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + GrpcCallSettings + testIamPermissionsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); this.createSequenceCallable = callableFactory.createUnaryCallable( @@ -312,6 +379,17 @@ protected GrpcSequenceServiceStub( this.getLocationCallable = callableFactory.createUnaryCallable( getLocationTransportSettings, settings.getLocationSettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -370,6 +448,22 @@ public UnaryCallable getLocationCallable() { return getLocationCallable; } + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + @Override public final void close() { try { diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcTestingStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcTestingStub.java index fb4f36ca08..c1df2142d2 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcTestingStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcTestingStub.java @@ -32,6 +32,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.CreateSessionRequest; @@ -155,6 +160,33 @@ public class GrpcTestingStub extends TestingStub { .setResponseMarshaller(ProtoUtils.marshaller(Location.getDefaultInstance())) .build(); + private static final MethodDescriptor setIamPolicyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/SetIamPolicy") + .setRequestMarshaller(ProtoUtils.marshaller(SetIamPolicyRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) + .build(); + + private static final MethodDescriptor getIamPolicyMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/GetIamPolicy") + .setRequestMarshaller(ProtoUtils.marshaller(GetIamPolicyRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + testIamPermissionsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.iam.v1.IAMPolicy/TestIamPermissions") + .setRequestMarshaller( + ProtoUtils.marshaller(TestIamPermissionsRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(TestIamPermissionsResponse.getDefaultInstance())) + .build(); + private final UnaryCallable createSessionCallable; private final UnaryCallable getSessionCallable; private final UnaryCallable listSessionsCallable; @@ -170,6 +202,10 @@ public class GrpcTestingStub extends TestingStub { private final UnaryCallable listLocationsPagedCallable; private final UnaryCallable getLocationCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; private final BackgroundResource backgroundResources; private final GrpcOperationsStub operationsStub; @@ -298,6 +334,37 @@ protected GrpcTestingStub( return builder.build(); }) .build(); + GrpcCallSettings setIamPolicyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + GrpcCallSettings getIamPolicyTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + GrpcCallSettings + testIamPermissionsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); this.createSessionCallable = callableFactory.createUnaryCallable( @@ -338,6 +405,17 @@ protected GrpcTestingStub( this.getLocationCallable = callableFactory.createUnaryCallable( getLocationTransportSettings, settings.getLocationSettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -413,6 +491,22 @@ public UnaryCallable getLocationCallable() { return getLocationCallable; } + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + @Override public final void close() { try { diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonComplianceStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonComplianceStub.java index d03d9ee917..9fe85b496f 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonComplianceStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonComplianceStub.java @@ -35,6 +35,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.TypeRegistry; import com.google.showcase.v1beta1.EnumRequest; import com.google.showcase.v1beta1.EnumResponse; @@ -579,6 +584,123 @@ public class HttpJsonComplianceStub extends ComplianceStub { .build()) .build(); + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:setIamPolicy", + "/v1beta1/{resource=rooms/*/blurbs/*}:setIamPolicy", + "/v1beta1/{resource=sequences/*}:setIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build(), false)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/GetIamPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:getIamPolicy", + "/v1beta1/{resource=rooms/*/blurbs/*}:getIamPolicy", + "/v1beta1/{resource=sequences/*}:getIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:testIamPermissions", + "/v1beta1/{resource=rooms/*/blurbs/*}:testIamPermissions", + "/v1beta1/{resource=sequences/*}:testIamPermissions") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build(), false)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + private final UnaryCallable repeatDataBodyCallable; private final UnaryCallable repeatDataBodyInfoCallable; private final UnaryCallable repeatDataQueryCallable; @@ -593,6 +715,10 @@ public class HttpJsonComplianceStub extends ComplianceStub { private final UnaryCallable listLocationsPagedCallable; private final UnaryCallable getLocationCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; private final BackgroundResource backgroundResources; private final HttpJsonStubCallableFactory callableFactory; @@ -739,6 +865,40 @@ protected HttpJsonComplianceStub( return builder.build(); }) .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); this.repeatDataBodyCallable = callableFactory.createUnaryCallable( @@ -791,6 +951,17 @@ protected HttpJsonComplianceStub( this.getLocationCallable = callableFactory.createUnaryCallable( getLocationTransportSettings, settings.getLocationSettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -811,6 +982,9 @@ public static List getMethodDescriptors() { methodDescriptors.add(verifyEnumMethodDescriptor); methodDescriptors.add(listLocationsMethodDescriptor); methodDescriptors.add(getLocationMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); return methodDescriptors; } @@ -880,6 +1054,22 @@ public UnaryCallable getLocationCallable() { return getLocationCallable; } + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + @Override public final void close() { try { diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java index 494d6613c7..fd39bf8711 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java @@ -47,6 +47,11 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.collect.ImmutableMap; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.protobuf.TypeRegistry; import com.google.showcase.v1beta1.BlockRequest; @@ -388,6 +393,123 @@ public class HttpJsonEchoStub extends EchoStub { .build()) .build(); + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:setIamPolicy", + "/v1beta1/{resource=rooms/*/blurbs/*}:setIamPolicy", + "/v1beta1/{resource=sequences/*}:setIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build(), false)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/GetIamPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:getIamPolicy", + "/v1beta1/{resource=rooms/*/blurbs/*}:getIamPolicy", + "/v1beta1/{resource=sequences/*}:getIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:testIamPermissions", + "/v1beta1/{resource=rooms/*/blurbs/*}:testIamPermissions", + "/v1beta1/{resource=sequences/*}:testIamPermissions") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build(), false)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + private final UnaryCallable echoCallable; private final ServerStreamingCallable expandCallable; private final UnaryCallable pagedExpandCallable; @@ -406,6 +528,10 @@ public class HttpJsonEchoStub extends EchoStub { private final UnaryCallable listLocationsPagedCallable; private final UnaryCallable getLocationCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; private final BackgroundResource backgroundResources; private final HttpJsonOperationsStub httpJsonOperationsStub; @@ -551,6 +677,40 @@ protected HttpJsonEchoStub( return builder.build(); }) .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); this.echoCallable = callableFactory.createUnaryCallable( @@ -600,6 +760,17 @@ protected HttpJsonEchoStub( this.getLocationCallable = callableFactory.createUnaryCallable( getLocationTransportSettings, settings.getLocationSettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -617,6 +788,9 @@ public static List getMethodDescriptors() { methodDescriptors.add(blockMethodDescriptor); methodDescriptors.add(listLocationsMethodDescriptor); methodDescriptors.add(getLocationMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); return methodDescriptors; } @@ -692,6 +866,22 @@ public UnaryCallable getLocationCallable() { return getLocationCallable; } + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + @Override public ClientStreamingCallable collectCallable() { throw new UnsupportedOperationException( diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonIdentityStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonIdentityStub.java index 264eb6c5bc..baa9736528 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonIdentityStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonIdentityStub.java @@ -36,6 +36,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.protobuf.TypeRegistry; import com.google.showcase.v1beta1.CreateUserRequest; @@ -297,6 +302,123 @@ public class HttpJsonIdentityStub extends IdentityStub { .build()) .build(); + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:setIamPolicy", + "/v1beta1/{resource=rooms/*/blurbs/*}:setIamPolicy", + "/v1beta1/{resource=sequences/*}:setIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build(), false)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/GetIamPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:getIamPolicy", + "/v1beta1/{resource=rooms/*/blurbs/*}:getIamPolicy", + "/v1beta1/{resource=sequences/*}:getIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:testIamPermissions", + "/v1beta1/{resource=rooms/*/blurbs/*}:testIamPermissions", + "/v1beta1/{resource=sequences/*}:testIamPermissions") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build(), false)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + private final UnaryCallable createUserCallable; private final UnaryCallable getUserCallable; private final UnaryCallable updateUserCallable; @@ -307,6 +429,10 @@ public class HttpJsonIdentityStub extends IdentityStub { private final UnaryCallable listLocationsPagedCallable; private final UnaryCallable getLocationCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; private final BackgroundResource backgroundResources; private final HttpJsonStubCallableFactory callableFactory; @@ -415,6 +541,40 @@ protected HttpJsonIdentityStub( return builder.build(); }) .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); this.createUserCallable = callableFactory.createUnaryCallable( @@ -443,6 +603,17 @@ protected HttpJsonIdentityStub( this.getLocationCallable = callableFactory.createUnaryCallable( getLocationTransportSettings, settings.getLocationSettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -458,6 +629,9 @@ public static List getMethodDescriptors() { methodDescriptors.add(listUsersMethodDescriptor); methodDescriptors.add(listLocationsMethodDescriptor); methodDescriptors.add(getLocationMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); return methodDescriptors; } @@ -507,6 +681,22 @@ public UnaryCallable getLocationCallable() { return getLocationCallable; } + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + @Override public final void close() { try { diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonMessagingStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonMessagingStub.java index 100623c169..dde66e8083 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonMessagingStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonMessagingStub.java @@ -46,6 +46,11 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.collect.ImmutableMap; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.protobuf.Empty; import com.google.protobuf.TypeRegistry; @@ -577,6 +582,123 @@ public class HttpJsonMessagingStub extends MessagingStub { .build()) .build(); + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:setIamPolicy", + "/v1beta1/{resource=rooms/*/blurbs/*}:setIamPolicy", + "/v1beta1/{resource=sequences/*}:setIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build(), false)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/GetIamPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:getIamPolicy", + "/v1beta1/{resource=rooms/*/blurbs/*}:getIamPolicy", + "/v1beta1/{resource=sequences/*}:getIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:testIamPermissions", + "/v1beta1/{resource=rooms/*/blurbs/*}:testIamPermissions", + "/v1beta1/{resource=sequences/*}:testIamPermissions") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build(), false)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + private final UnaryCallable createRoomCallable; private final UnaryCallable getRoomCallable; private final UnaryCallable updateRoomCallable; @@ -598,6 +720,10 @@ public class HttpJsonMessagingStub extends MessagingStub { private final UnaryCallable listLocationsPagedCallable; private final UnaryCallable getLocationCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; private final BackgroundResource backgroundResources; private final HttpJsonOperationsStub httpJsonOperationsStub; @@ -803,6 +929,40 @@ protected HttpJsonMessagingStub( return builder.build(); }) .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); this.createRoomCallable = callableFactory.createUnaryCallable( @@ -861,6 +1021,17 @@ protected HttpJsonMessagingStub( this.getLocationCallable = callableFactory.createUnaryCallable( getLocationTransportSettings, settings.getLocationSettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -883,6 +1054,9 @@ public static List getMethodDescriptors() { methodDescriptors.add(streamBlurbsMethodDescriptor); methodDescriptors.add(listLocationsMethodDescriptor); methodDescriptors.add(getLocationMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); return methodDescriptors; } @@ -982,6 +1156,22 @@ public UnaryCallable getLocationCallable() { return getLocationCallable; } + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + @Override public ClientStreamingCallable sendBlurbsCallable() { throw new UnsupportedOperationException( diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceStub.java index 4652aef4a4..5c1f451476 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceStub.java @@ -36,6 +36,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.protobuf.TypeRegistry; import com.google.showcase.v1beta1.AttemptSequenceRequest; @@ -348,6 +353,123 @@ public class HttpJsonSequenceServiceStub extends SequenceServiceStub { .build()) .build(); + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:setIamPolicy", + "/v1beta1/{resource=rooms/*/blurbs/*}:setIamPolicy", + "/v1beta1/{resource=sequences/*}:setIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build(), false)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/GetIamPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:getIamPolicy", + "/v1beta1/{resource=rooms/*/blurbs/*}:getIamPolicy", + "/v1beta1/{resource=sequences/*}:getIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:testIamPermissions", + "/v1beta1/{resource=rooms/*/blurbs/*}:testIamPermissions", + "/v1beta1/{resource=sequences/*}:testIamPermissions") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build(), false)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + private final UnaryCallable createSequenceCallable; private final UnaryCallable createStreamingSequenceCallable; @@ -362,6 +484,10 @@ public class HttpJsonSequenceServiceStub extends SequenceServiceStub { private final UnaryCallable listLocationsPagedCallable; private final UnaryCallable getLocationCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; private final BackgroundResource backgroundResources; private final HttpJsonStubCallableFactory callableFactory; @@ -488,6 +614,40 @@ protected HttpJsonSequenceServiceStub( return builder.build(); }) .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); this.createSequenceCallable = callableFactory.createUnaryCallable( @@ -524,6 +684,17 @@ protected HttpJsonSequenceServiceStub( this.getLocationCallable = callableFactory.createUnaryCallable( getLocationTransportSettings, settings.getLocationSettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -540,6 +711,9 @@ public static List getMethodDescriptors() { methodDescriptors.add(attemptStreamingSequenceMethodDescriptor); methodDescriptors.add(listLocationsMethodDescriptor); methodDescriptors.add(getLocationMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); return methodDescriptors; } @@ -592,6 +766,22 @@ public UnaryCallable getLocationCallable() { return getLocationCallable; } + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + @Override public final void close() { try { diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonTestingStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonTestingStub.java index 560f9a1fb6..fd075a3229 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonTestingStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonTestingStub.java @@ -37,6 +37,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.protobuf.TypeRegistry; import com.google.showcase.v1beta1.CreateSessionRequest; @@ -406,6 +411,123 @@ public class HttpJsonTestingStub extends TestingStub { .build()) .build(); + private static final ApiMethodDescriptor + setIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/SetIamPolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:setIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:setIamPolicy", + "/v1beta1/{resource=rooms/*/blurbs/*}:setIamPolicy", + "/v1beta1/{resource=sequences/*}:setIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build(), false)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/GetIamPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:getIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:getIamPolicy", + "/v1beta1/{resource=rooms/*/blurbs/*}:getIamPolicy", + "/v1beta1/{resource=sequences/*}:getIamPolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + testIamPermissionsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.iam.v1.IAMPolicy/TestIamPermissions") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{resource=users/*}:testIamPermissions", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setAdditionalPaths( + "/v1beta1/{resource=rooms/*}:testIamPermissions", + "/v1beta1/{resource=rooms/*/blurbs/*}:testIamPermissions", + "/v1beta1/{resource=sequences/*}:testIamPermissions") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearResource().build(), false)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TestIamPermissionsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + private final UnaryCallable createSessionCallable; private final UnaryCallable getSessionCallable; private final UnaryCallable listSessionsCallable; @@ -421,6 +543,10 @@ public class HttpJsonTestingStub extends TestingStub { private final UnaryCallable listLocationsPagedCallable; private final UnaryCallable getLocationCallable; + private final UnaryCallable setIamPolicyCallable; + private final UnaryCallable getIamPolicyCallable; + private final UnaryCallable + testIamPermissionsCallable; private final BackgroundResource backgroundResources; private final HttpJsonStubCallableFactory callableFactory; @@ -561,6 +687,40 @@ protected HttpJsonTestingStub( return builder.build(); }) .build(); + HttpJsonCallSettings setIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(setIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings getIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); + HttpJsonCallSettings + testIamPermissionsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(testIamPermissionsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add("resource", String.valueOf(request.getResource())); + return builder.build(); + }) + .build(); this.createSessionCallable = callableFactory.createUnaryCallable( @@ -601,6 +761,17 @@ protected HttpJsonTestingStub( this.getLocationCallable = callableFactory.createUnaryCallable( getLocationTransportSettings, settings.getLocationSettings(), clientContext); + this.setIamPolicyCallable = + callableFactory.createUnaryCallable( + setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); + this.getIamPolicyCallable = + callableFactory.createUnaryCallable( + getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); + this.testIamPermissionsCallable = + callableFactory.createUnaryCallable( + testIamPermissionsTransportSettings, + settings.testIamPermissionsSettings(), + clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); @@ -619,6 +790,9 @@ public static List getMethodDescriptors() { methodDescriptors.add(verifyTestMethodDescriptor); methodDescriptors.add(listLocationsMethodDescriptor); methodDescriptors.add(getLocationMethodDescriptor); + methodDescriptors.add(setIamPolicyMethodDescriptor); + methodDescriptors.add(getIamPolicyMethodDescriptor); + methodDescriptors.add(testIamPermissionsMethodDescriptor); return methodDescriptors; } @@ -688,6 +862,22 @@ public UnaryCallable getLocationCallable() { return getLocationCallable; } + @Override + public UnaryCallable setIamPolicyCallable() { + return setIamPolicyCallable; + } + + @Override + public UnaryCallable getIamPolicyCallable() { + return getIamPolicyCallable; + } + + @Override + public UnaryCallable + testIamPermissionsCallable() { + return testIamPermissionsCallable; + } + @Override public final void close() { try { diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/IdentityStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/IdentityStub.java index 04f4dfca64..55a003cfde 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/IdentityStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/IdentityStub.java @@ -26,6 +26,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.CreateUserRequest; import com.google.showcase.v1beta1.DeleteUserRequest; @@ -83,6 +88,19 @@ public UnaryCallable getLocationCallable() { throw new UnsupportedOperationException("Not implemented: getLocationCallable()"); } + public UnaryCallable setIamPolicyCallable() { + throw new UnsupportedOperationException("Not implemented: setIamPolicyCallable()"); + } + + public UnaryCallable getIamPolicyCallable() { + throw new UnsupportedOperationException("Not implemented: getIamPolicyCallable()"); + } + + public UnaryCallable + testIamPermissionsCallable() { + throw new UnsupportedOperationException("Not implemented: testIamPermissionsCallable()"); + } + @Override public abstract void close(); } diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/IdentityStubSettings.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/IdentityStubSettings.java index 4618068588..90aa163708 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/IdentityStubSettings.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/IdentityStubSettings.java @@ -52,6 +52,11 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.CreateUserRequest; import com.google.showcase.v1beta1.DeleteUserRequest; @@ -118,6 +123,10 @@ public class IdentityStubSettings extends StubSettings { ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse> listLocationsSettings; private final UnaryCallSettings getLocationSettings; + private final UnaryCallSettings setIamPolicySettings; + private final UnaryCallSettings getIamPolicySettings; + private final UnaryCallSettings + testIamPermissionsSettings; private static final PagedListDescriptor LIST_USERS_PAGE_STR_DESC = @@ -262,6 +271,22 @@ public UnaryCallSettings getLocationSettings() { return getLocationSettings; } + /** Returns the object with the settings used for calls to setIamPolicy. */ + public UnaryCallSettings setIamPolicySettings() { + return setIamPolicySettings; + } + + /** Returns the object with the settings used for calls to getIamPolicy. */ + public UnaryCallSettings getIamPolicySettings() { + return getIamPolicySettings; + } + + /** Returns the object with the settings used for calls to testIamPermissions. */ + public UnaryCallSettings + testIamPermissionsSettings() { + return testIamPermissionsSettings; + } + public IdentityStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() @@ -373,6 +398,9 @@ protected IdentityStubSettings(Builder settingsBuilder) throws IOException { listUsersSettings = settingsBuilder.listUsersSettings().build(); listLocationsSettings = settingsBuilder.listLocationsSettings().build(); getLocationSettings = settingsBuilder.getLocationSettings().build(); + setIamPolicySettings = settingsBuilder.setIamPolicySettings().build(); + getIamPolicySettings = settingsBuilder.getIamPolicySettings().build(); + testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build(); } /** Builder for IdentityStubSettings. */ @@ -389,6 +417,10 @@ public static class Builder extends StubSettings.Builder listLocationsSettings; private final UnaryCallSettings.Builder getLocationSettings; + private final UnaryCallSettings.Builder setIamPolicySettings; + private final UnaryCallSettings.Builder getIamPolicySettings; + private final UnaryCallSettings.Builder + testIamPermissionsSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -439,6 +471,9 @@ protected Builder(ClientContext clientContext) { listUsersSettings = PagedCallSettings.newBuilder(LIST_USERS_PAGE_STR_FACT); listLocationsSettings = PagedCallSettings.newBuilder(LIST_LOCATIONS_PAGE_STR_FACT); getLocationSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + setIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + getIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -448,7 +483,10 @@ protected Builder(ClientContext clientContext) { deleteUserSettings, listUsersSettings, listLocationsSettings, - getLocationSettings); + getLocationSettings, + setIamPolicySettings, + getIamPolicySettings, + testIamPermissionsSettings); initDefaults(this); } @@ -462,6 +500,9 @@ protected Builder(IdentityStubSettings settings) { listUsersSettings = settings.listUsersSettings.toBuilder(); listLocationsSettings = settings.listLocationsSettings.toBuilder(); getLocationSettings = settings.getLocationSettings.toBuilder(); + setIamPolicySettings = settings.setIamPolicySettings.toBuilder(); + getIamPolicySettings = settings.getIamPolicySettings.toBuilder(); + testIamPermissionsSettings = settings.testIamPermissionsSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -471,7 +512,10 @@ protected Builder(IdentityStubSettings settings) { deleteUserSettings, listUsersSettings, listLocationsSettings, - getLocationSettings); + getLocationSettings, + setIamPolicySettings, + getIamPolicySettings, + testIamPermissionsSettings); } private static Builder createDefault() { @@ -536,6 +580,21 @@ private static Builder initDefaults(Builder builder) { .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + builder + .setIamPolicySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .getIamPolicySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .testIamPermissionsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + return builder; } @@ -592,6 +651,22 @@ public UnaryCallSettings.Builder getLocationSettin return getLocationSettings; } + /** Returns the builder for the settings used for calls to setIamPolicy. */ + public UnaryCallSettings.Builder setIamPolicySettings() { + return setIamPolicySettings; + } + + /** Returns the builder for the settings used for calls to getIamPolicy. */ + public UnaryCallSettings.Builder getIamPolicySettings() { + return getIamPolicySettings; + } + + /** Returns the builder for the settings used for calls to testIamPermissions. */ + public UnaryCallSettings.Builder + testIamPermissionsSettings() { + return testIamPermissionsSettings; + } + @Override public IdentityStubSettings build() throws IOException { return new IdentityStubSettings(this); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/MessagingStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/MessagingStub.java index 8a88520533..19ed93f930 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/MessagingStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/MessagingStub.java @@ -31,6 +31,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.longrunning.stub.OperationsStub; import com.google.protobuf.Empty; @@ -157,6 +162,19 @@ public UnaryCallable getLocationCallable() { throw new UnsupportedOperationException("Not implemented: getLocationCallable()"); } + public UnaryCallable setIamPolicyCallable() { + throw new UnsupportedOperationException("Not implemented: setIamPolicyCallable()"); + } + + public UnaryCallable getIamPolicyCallable() { + throw new UnsupportedOperationException("Not implemented: getIamPolicyCallable()"); + } + + public UnaryCallable + testIamPermissionsCallable() { + throw new UnsupportedOperationException("Not implemented: testIamPermissionsCallable()"); + } + @Override public abstract void close(); } diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/MessagingStubSettings.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/MessagingStubSettings.java index a781f36c3e..ca632dbf10 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/MessagingStubSettings.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/MessagingStubSettings.java @@ -59,6 +59,11 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.Blurb; @@ -154,6 +159,10 @@ public class MessagingStubSettings extends StubSettings { ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse> listLocationsSettings; private final UnaryCallSettings getLocationSettings; + private final UnaryCallSettings setIamPolicySettings; + private final UnaryCallSettings getIamPolicySettings; + private final UnaryCallSettings + testIamPermissionsSettings; private static final PagedListDescriptor LIST_ROOMS_PAGE_STR_DESC = @@ -404,6 +413,22 @@ public UnaryCallSettings getLocationSettings() { return getLocationSettings; } + /** Returns the object with the settings used for calls to setIamPolicy. */ + public UnaryCallSettings setIamPolicySettings() { + return setIamPolicySettings; + } + + /** Returns the object with the settings used for calls to getIamPolicy. */ + public UnaryCallSettings getIamPolicySettings() { + return getIamPolicySettings; + } + + /** Returns the object with the settings used for calls to testIamPermissions. */ + public UnaryCallSettings + testIamPermissionsSettings() { + return testIamPermissionsSettings; + } + public MessagingStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() @@ -525,6 +550,9 @@ protected MessagingStubSettings(Builder settingsBuilder) throws IOException { connectSettings = settingsBuilder.connectSettings().build(); listLocationsSettings = settingsBuilder.listLocationsSettings().build(); getLocationSettings = settingsBuilder.getLocationSettings().build(); + setIamPolicySettings = settingsBuilder.setIamPolicySettings().build(); + getIamPolicySettings = settingsBuilder.getIamPolicySettings().build(); + testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build(); } /** Builder for MessagingStubSettings. */ @@ -558,6 +586,10 @@ public static class Builder extends StubSettings.Builder listLocationsSettings; private final UnaryCallSettings.Builder getLocationSettings; + private final UnaryCallSettings.Builder setIamPolicySettings; + private final UnaryCallSettings.Builder getIamPolicySettings; + private final UnaryCallSettings.Builder + testIamPermissionsSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -625,6 +657,9 @@ protected Builder(ClientContext clientContext) { connectSettings = StreamingCallSettings.newBuilder(); listLocationsSettings = PagedCallSettings.newBuilder(LIST_LOCATIONS_PAGE_STR_FACT); getLocationSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + setIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + getIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -640,7 +675,10 @@ protected Builder(ClientContext clientContext) { listBlurbsSettings, searchBlurbsSettings, listLocationsSettings, - getLocationSettings); + getLocationSettings, + setIamPolicySettings, + getIamPolicySettings, + testIamPermissionsSettings); initDefaults(this); } @@ -664,6 +702,9 @@ protected Builder(MessagingStubSettings settings) { connectSettings = settings.connectSettings.toBuilder(); listLocationsSettings = settings.listLocationsSettings.toBuilder(); getLocationSettings = settings.getLocationSettings.toBuilder(); + setIamPolicySettings = settings.setIamPolicySettings.toBuilder(); + getIamPolicySettings = settings.getIamPolicySettings.toBuilder(); + testIamPermissionsSettings = settings.testIamPermissionsSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -679,7 +720,10 @@ protected Builder(MessagingStubSettings settings) { listBlurbsSettings, searchBlurbsSettings, listLocationsSettings, - getLocationSettings); + getLocationSettings, + setIamPolicySettings, + getIamPolicySettings, + testIamPermissionsSettings); } private static Builder createDefault() { @@ -779,6 +823,21 @@ private static Builder initDefaults(Builder builder) { .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + builder + .setIamPolicySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .getIamPolicySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .testIamPermissionsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + builder .searchBlurbsOperationSettings() .setInitialCallSettings( @@ -916,6 +975,22 @@ public UnaryCallSettings.Builder getLocationSettin return getLocationSettings; } + /** Returns the builder for the settings used for calls to setIamPolicy. */ + public UnaryCallSettings.Builder setIamPolicySettings() { + return setIamPolicySettings; + } + + /** Returns the builder for the settings used for calls to getIamPolicy. */ + public UnaryCallSettings.Builder getIamPolicySettings() { + return getIamPolicySettings; + } + + /** Returns the builder for the settings used for calls to testIamPermissions. */ + public UnaryCallSettings.Builder + testIamPermissionsSettings() { + return testIamPermissionsSettings; + } + @Override public MessagingStubSettings build() throws IOException { return new MessagingStubSettings(this); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/SequenceServiceStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/SequenceServiceStub.java index 1442052ddc..d657fe528b 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/SequenceServiceStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/SequenceServiceStub.java @@ -26,6 +26,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.AttemptSequenceRequest; import com.google.showcase.v1beta1.AttemptStreamingSequenceRequest; @@ -91,6 +96,19 @@ public UnaryCallable getLocationCallable() { throw new UnsupportedOperationException("Not implemented: getLocationCallable()"); } + public UnaryCallable setIamPolicyCallable() { + throw new UnsupportedOperationException("Not implemented: setIamPolicyCallable()"); + } + + public UnaryCallable getIamPolicyCallable() { + throw new UnsupportedOperationException("Not implemented: getIamPolicyCallable()"); + } + + public UnaryCallable + testIamPermissionsCallable() { + throw new UnsupportedOperationException("Not implemented: testIamPermissionsCallable()"); + } + @Override public abstract void close(); } diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/SequenceServiceStubSettings.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/SequenceServiceStubSettings.java index d95c94c97c..f4e0d2f82a 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/SequenceServiceStubSettings.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/SequenceServiceStubSettings.java @@ -52,6 +52,11 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.AttemptSequenceRequest; import com.google.showcase.v1beta1.AttemptStreamingSequenceRequest; @@ -128,6 +133,10 @@ public class SequenceServiceStubSettings extends StubSettings listLocationsSettings; private final UnaryCallSettings getLocationSettings; + private final UnaryCallSettings setIamPolicySettings; + private final UnaryCallSettings getIamPolicySettings; + private final UnaryCallSettings + testIamPermissionsSettings; private static final PagedListDescriptor LIST_LOCATIONS_PAGE_STR_DESC = @@ -227,6 +236,22 @@ public UnaryCallSettings getLocationSettings() { return getLocationSettings; } + /** Returns the object with the settings used for calls to setIamPolicy. */ + public UnaryCallSettings setIamPolicySettings() { + return setIamPolicySettings; + } + + /** Returns the object with the settings used for calls to getIamPolicy. */ + public UnaryCallSettings getIamPolicySettings() { + return getIamPolicySettings; + } + + /** Returns the object with the settings used for calls to testIamPermissions. */ + public UnaryCallSettings + testIamPermissionsSettings() { + return testIamPermissionsSettings; + } + public SequenceServiceStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() @@ -342,6 +367,9 @@ protected SequenceServiceStubSettings(Builder settingsBuilder) throws IOExceptio attemptStreamingSequenceSettings = settingsBuilder.attemptStreamingSequenceSettings().build(); listLocationsSettings = settingsBuilder.listLocationsSettings().build(); getLocationSettings = settingsBuilder.getLocationSettings().build(); + setIamPolicySettings = settingsBuilder.setIamPolicySettings().build(); + getIamPolicySettings = settingsBuilder.getIamPolicySettings().build(); + testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build(); } /** Builder for SequenceServiceStubSettings. */ @@ -363,6 +391,10 @@ public static class Builder extends StubSettings.Builder listLocationsSettings; private final UnaryCallSettings.Builder getLocationSettings; + private final UnaryCallSettings.Builder setIamPolicySettings; + private final UnaryCallSettings.Builder getIamPolicySettings; + private final UnaryCallSettings.Builder + testIamPermissionsSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -421,6 +453,9 @@ protected Builder(ClientContext clientContext) { attemptStreamingSequenceSettings = ServerStreamingCallSettings.newBuilder(); listLocationsSettings = PagedCallSettings.newBuilder(LIST_LOCATIONS_PAGE_STR_FACT); getLocationSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + setIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + getIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -430,7 +465,10 @@ protected Builder(ClientContext clientContext) { getStreamingSequenceReportSettings, attemptSequenceSettings, listLocationsSettings, - getLocationSettings); + getLocationSettings, + setIamPolicySettings, + getIamPolicySettings, + testIamPermissionsSettings); initDefaults(this); } @@ -445,6 +483,9 @@ protected Builder(SequenceServiceStubSettings settings) { attemptStreamingSequenceSettings = settings.attemptStreamingSequenceSettings.toBuilder(); listLocationsSettings = settings.listLocationsSettings.toBuilder(); getLocationSettings = settings.getLocationSettings.toBuilder(); + setIamPolicySettings = settings.setIamPolicySettings.toBuilder(); + getIamPolicySettings = settings.getIamPolicySettings.toBuilder(); + testIamPermissionsSettings = settings.testIamPermissionsSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -454,7 +495,10 @@ protected Builder(SequenceServiceStubSettings settings) { getStreamingSequenceReportSettings, attemptSequenceSettings, listLocationsSettings, - getLocationSettings); + getLocationSettings, + setIamPolicySettings, + getIamPolicySettings, + testIamPermissionsSettings); } private static Builder createDefault() { @@ -524,6 +568,21 @@ private static Builder initDefaults(Builder builder) { .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + builder + .setIamPolicySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .getIamPolicySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .testIamPermissionsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + return builder; } @@ -589,6 +648,22 @@ public UnaryCallSettings.Builder getLocationSettin return getLocationSettings; } + /** Returns the builder for the settings used for calls to setIamPolicy. */ + public UnaryCallSettings.Builder setIamPolicySettings() { + return setIamPolicySettings; + } + + /** Returns the builder for the settings used for calls to getIamPolicy. */ + public UnaryCallSettings.Builder getIamPolicySettings() { + return getIamPolicySettings; + } + + /** Returns the builder for the settings used for calls to testIamPermissions. */ + public UnaryCallSettings.Builder + testIamPermissionsSettings() { + return testIamPermissionsSettings; + } + @Override public SequenceServiceStubSettings build() throws IOException { return new SequenceServiceStubSettings(this); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/TestingStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/TestingStub.java index 48ac98f3d2..bd8e9759ff 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/TestingStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/TestingStub.java @@ -27,6 +27,11 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.CreateSessionRequest; import com.google.showcase.v1beta1.DeleteSessionRequest; @@ -106,6 +111,19 @@ public UnaryCallable getLocationCallable() { throw new UnsupportedOperationException("Not implemented: getLocationCallable()"); } + public UnaryCallable setIamPolicyCallable() { + throw new UnsupportedOperationException("Not implemented: setIamPolicyCallable()"); + } + + public UnaryCallable getIamPolicyCallable() { + throw new UnsupportedOperationException("Not implemented: getIamPolicyCallable()"); + } + + public UnaryCallable + testIamPermissionsCallable() { + throw new UnsupportedOperationException("Not implemented: testIamPermissionsCallable()"); + } + @Override public abstract void close(); } diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/TestingStubSettings.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/TestingStubSettings.java index decec2e84a..37bba7d806 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/TestingStubSettings.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/TestingStubSettings.java @@ -53,6 +53,11 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Empty; import com.google.showcase.v1beta1.CreateSessionRequest; import com.google.showcase.v1beta1.DeleteSessionRequest; @@ -131,6 +136,10 @@ public class TestingStubSettings extends StubSettings { ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse> listLocationsSettings; private final UnaryCallSettings getLocationSettings; + private final UnaryCallSettings setIamPolicySettings; + private final UnaryCallSettings getIamPolicySettings; + private final UnaryCallSettings + testIamPermissionsSettings; private static final PagedListDescriptor LIST_SESSIONS_PAGE_STR_DESC = @@ -344,6 +353,22 @@ public UnaryCallSettings getLocationSettings() { return getLocationSettings; } + /** Returns the object with the settings used for calls to setIamPolicy. */ + public UnaryCallSettings setIamPolicySettings() { + return setIamPolicySettings; + } + + /** Returns the object with the settings used for calls to getIamPolicy. */ + public UnaryCallSettings getIamPolicySettings() { + return getIamPolicySettings; + } + + /** Returns the object with the settings used for calls to testIamPermissions. */ + public UnaryCallSettings + testIamPermissionsSettings() { + return testIamPermissionsSettings; + } + public TestingStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() @@ -458,6 +483,9 @@ protected TestingStubSettings(Builder settingsBuilder) throws IOException { verifyTestSettings = settingsBuilder.verifyTestSettings().build(); listLocationsSettings = settingsBuilder.listLocationsSettings().build(); getLocationSettings = settingsBuilder.getLocationSettings().build(); + setIamPolicySettings = settingsBuilder.setIamPolicySettings().build(); + getIamPolicySettings = settingsBuilder.getIamPolicySettings().build(); + testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build(); } /** Builder for TestingStubSettings. */ @@ -481,6 +509,10 @@ public static class Builder extends StubSettings.Builder listLocationsSettings; private final UnaryCallSettings.Builder getLocationSettings; + private final UnaryCallSettings.Builder setIamPolicySettings; + private final UnaryCallSettings.Builder getIamPolicySettings; + private final UnaryCallSettings.Builder + testIamPermissionsSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; @@ -518,6 +550,9 @@ protected Builder(ClientContext clientContext) { verifyTestSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); listLocationsSettings = PagedCallSettings.newBuilder(LIST_LOCATIONS_PAGE_STR_FACT); getLocationSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + setIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + getIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -530,7 +565,10 @@ protected Builder(ClientContext clientContext) { deleteTestSettings, verifyTestSettings, listLocationsSettings, - getLocationSettings); + getLocationSettings, + setIamPolicySettings, + getIamPolicySettings, + testIamPermissionsSettings); initDefaults(this); } @@ -547,6 +585,9 @@ protected Builder(TestingStubSettings settings) { verifyTestSettings = settings.verifyTestSettings.toBuilder(); listLocationsSettings = settings.listLocationsSettings.toBuilder(); getLocationSettings = settings.getLocationSettings.toBuilder(); + setIamPolicySettings = settings.setIamPolicySettings.toBuilder(); + getIamPolicySettings = settings.getIamPolicySettings.toBuilder(); + testIamPermissionsSettings = settings.testIamPermissionsSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( @@ -559,7 +600,10 @@ protected Builder(TestingStubSettings settings) { deleteTestSettings, verifyTestSettings, listLocationsSettings, - getLocationSettings); + getLocationSettings, + setIamPolicySettings, + getIamPolicySettings, + testIamPermissionsSettings); } private static Builder createDefault() { @@ -639,6 +683,21 @@ private static Builder initDefaults(Builder builder) { .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + builder + .setIamPolicySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .getIamPolicySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + builder + .testIamPermissionsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + return builder; } @@ -713,6 +772,22 @@ public UnaryCallSettings.Builder getLocationSettin return getLocationSettings; } + /** Returns the builder for the settings used for calls to setIamPolicy. */ + public UnaryCallSettings.Builder setIamPolicySettings() { + return setIamPolicySettings; + } + + /** Returns the builder for the settings used for calls to getIamPolicy. */ + public UnaryCallSettings.Builder getIamPolicySettings() { + return getIamPolicySettings; + } + + /** Returns the builder for the settings used for calls to testIamPermissions. */ + public UnaryCallSettings.Builder + testIamPermissionsSettings() { + return testIamPermissionsSettings; + } + @Override public TestingStubSettings build() throws IOException { return new TestingStubSettings(this); diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ComplianceClientHttpJsonTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ComplianceClientHttpJsonTest.java index 14bd0a271a..db60b8419c 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ComplianceClientHttpJsonTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ComplianceClientHttpJsonTest.java @@ -32,10 +32,20 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Any; import com.google.protobuf.ByteString; +import com.google.protobuf.FieldMask; import com.google.showcase.v1beta1.stub.HttpJsonComplianceStub; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -1040,4 +1050,178 @@ public void getLocationExceptionTest() throws Exception { // Expected exception. } } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } } diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ComplianceClientTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ComplianceClientTest.java index b7b7c00a3d..efed7fd2eb 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ComplianceClientTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ComplianceClientTest.java @@ -30,10 +30,21 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.AbstractMessage; import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import com.google.protobuf.FieldMask; import io.grpc.StatusRuntimeException; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -49,6 +60,7 @@ @Generated("by gapic-generator-java") public class ComplianceClientTest { private static MockCompliance mockCompliance; + private static MockIAMPolicy mockIAMPolicy; private static MockLocations mockLocations; private static MockServiceHelper mockServiceHelper; private LocalChannelProvider channelProvider; @@ -58,10 +70,11 @@ public class ComplianceClientTest { public static void startStaticServer() { mockCompliance = new MockCompliance(); mockLocations = new MockLocations(); + mockIAMPolicy = new MockIAMPolicy(); mockServiceHelper = new MockServiceHelper( UUID.randomUUID().toString(), - Arrays.asList(mockCompliance, mockLocations)); + Arrays.asList(mockCompliance, mockLocations, mockIAMPolicy)); mockServiceHelper.start(); } @@ -850,4 +863,164 @@ public void getLocationExceptionTest() throws Exception { // Expected exception. } } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockIAMPolicy.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + SetIamPolicyRequest actualRequest = ((SetIamPolicyRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getPolicy(), actualRequest.getPolicy()); + Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockIAMPolicy.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetIamPolicyRequest actualRequest = ((GetIamPolicyRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getOptions(), actualRequest.getOptions()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockIAMPolicy.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + TestIamPermissionsRequest actualRequest = ((TestIamPermissionsRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getPermissionsList(), actualRequest.getPermissionsList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } } diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/EchoClientHttpJsonTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/EchoClientHttpJsonTest.java index 908fd142a6..98b26c3ef6 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/EchoClientHttpJsonTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/EchoClientHttpJsonTest.java @@ -34,9 +34,19 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.protobuf.Any; +import com.google.protobuf.ByteString; import com.google.protobuf.Duration; +import com.google.protobuf.FieldMask; import com.google.showcase.v1beta1.stub.HttpJsonEchoStub; import java.io.IOException; import java.util.ArrayList; @@ -550,4 +560,178 @@ public void getLocationExceptionTest() throws Exception { // Expected exception. } } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } } diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/EchoClientTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/EchoClientTest.java index dfce67ccc0..9c0bcba1b3 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/EchoClientTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/EchoClientTest.java @@ -38,10 +38,20 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.protobuf.AbstractMessage; import com.google.protobuf.Any; +import com.google.protobuf.ByteString; import com.google.protobuf.Duration; +import com.google.protobuf.FieldMask; import com.google.rpc.Status; import io.grpc.StatusRuntimeException; import java.io.IOException; @@ -64,6 +74,7 @@ @Generated("by gapic-generator-java") public class EchoClientTest { private static MockEcho mockEcho; + private static MockIAMPolicy mockIAMPolicy; private static MockLocations mockLocations; private static MockServiceHelper mockServiceHelper; private LocalChannelProvider channelProvider; @@ -73,9 +84,11 @@ public class EchoClientTest { public static void startStaticServer() { mockEcho = new MockEcho(); mockLocations = new MockLocations(); + mockIAMPolicy = new MockIAMPolicy(); mockServiceHelper = new MockServiceHelper( - UUID.randomUUID().toString(), Arrays.asList(mockEcho, mockLocations)); + UUID.randomUUID().toString(), + Arrays.asList(mockEcho, mockLocations, mockIAMPolicy)); mockServiceHelper.start(); } @@ -670,4 +683,164 @@ public void getLocationExceptionTest() throws Exception { // Expected exception. } } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockIAMPolicy.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + SetIamPolicyRequest actualRequest = ((SetIamPolicyRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getPolicy(), actualRequest.getPolicy()); + Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockIAMPolicy.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetIamPolicyRequest actualRequest = ((GetIamPolicyRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getOptions(), actualRequest.getOptions()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockIAMPolicy.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + TestIamPermissionsRequest actualRequest = ((TestIamPermissionsRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getPermissionsList(), actualRequest.getPermissionsList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } } diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/IdentityClientHttpJsonTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/IdentityClientHttpJsonTest.java index 89f3a1f93c..4c5ae45c07 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/IdentityClientHttpJsonTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/IdentityClientHttpJsonTest.java @@ -33,12 +33,22 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Any; +import com.google.protobuf.ByteString; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import com.google.protobuf.Timestamp; import com.google.showcase.v1beta1.stub.HttpJsonIdentityStub; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -640,4 +650,178 @@ public void getLocationExceptionTest() throws Exception { // Expected exception. } } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } } diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/IdentityClientTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/IdentityClientTest.java index d94f41876c..348fad29c6 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/IdentityClientTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/IdentityClientTest.java @@ -31,13 +31,23 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.AbstractMessage; import com.google.protobuf.Any; +import com.google.protobuf.ByteString; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import com.google.protobuf.Timestamp; import io.grpc.StatusRuntimeException; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -52,6 +62,7 @@ @Generated("by gapic-generator-java") public class IdentityClientTest { + private static MockIAMPolicy mockIAMPolicy; private static MockIdentity mockIdentity; private static MockLocations mockLocations; private static MockServiceHelper mockServiceHelper; @@ -62,10 +73,11 @@ public class IdentityClientTest { public static void startStaticServer() { mockIdentity = new MockIdentity(); mockLocations = new MockLocations(); + mockIAMPolicy = new MockIAMPolicy(); mockServiceHelper = new MockServiceHelper( UUID.randomUUID().toString(), - Arrays.asList(mockIdentity, mockLocations)); + Arrays.asList(mockIdentity, mockLocations, mockIAMPolicy)); mockServiceHelper.start(); } @@ -570,4 +582,164 @@ public void getLocationExceptionTest() throws Exception { // Expected exception. } } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockIAMPolicy.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + SetIamPolicyRequest actualRequest = ((SetIamPolicyRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getPolicy(), actualRequest.getPolicy()); + Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockIAMPolicy.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetIamPolicyRequest actualRequest = ((GetIamPolicyRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getOptions(), actualRequest.getOptions()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockIAMPolicy.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + TestIamPermissionsRequest actualRequest = ((TestIamPermissionsRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getPermissionsList(), actualRequest.getPermissionsList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } } diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MessagingClientHttpJsonTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MessagingClientHttpJsonTest.java index dcea965000..a630a83e64 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MessagingClientHttpJsonTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MessagingClientHttpJsonTest.java @@ -34,6 +34,14 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.protobuf.Any; import com.google.protobuf.ByteString; @@ -1768,4 +1776,178 @@ public void getLocationExceptionTest() throws Exception { // Expected exception. } } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } } diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MessagingClientTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MessagingClientTest.java index 20eab215c8..4aeac6d256 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MessagingClientTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MessagingClientTest.java @@ -38,6 +38,14 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.longrunning.Operation; import com.google.protobuf.AbstractMessage; import com.google.protobuf.Any; @@ -63,6 +71,7 @@ @Generated("by gapic-generator-java") public class MessagingClientTest { + private static MockIAMPolicy mockIAMPolicy; private static MockLocations mockLocations; private static MockMessaging mockMessaging; private static MockServiceHelper mockServiceHelper; @@ -73,10 +82,11 @@ public class MessagingClientTest { public static void startStaticServer() { mockMessaging = new MockMessaging(); mockLocations = new MockLocations(); + mockIAMPolicy = new MockIAMPolicy(); mockServiceHelper = new MockServiceHelper( UUID.randomUUID().toString(), - Arrays.asList(mockMessaging, mockLocations)); + Arrays.asList(mockMessaging, mockLocations, mockIAMPolicy)); mockServiceHelper.start(); } @@ -1721,4 +1731,164 @@ public void getLocationExceptionTest() throws Exception { // Expected exception. } } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockIAMPolicy.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + SetIamPolicyRequest actualRequest = ((SetIamPolicyRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getPolicy(), actualRequest.getPolicy()); + Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockIAMPolicy.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetIamPolicyRequest actualRequest = ((GetIamPolicyRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getOptions(), actualRequest.getOptions()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockIAMPolicy.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + TestIamPermissionsRequest actualRequest = ((TestIamPermissionsRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getPermissionsList(), actualRequest.getPermissionsList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } } diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/SequenceServiceClientHttpJsonTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/SequenceServiceClientHttpJsonTest.java index 88bb1605ea..1d564d1e16 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/SequenceServiceClientHttpJsonTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/SequenceServiceClientHttpJsonTest.java @@ -32,8 +32,18 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Any; +import com.google.protobuf.ByteString; import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; import com.google.showcase.v1beta1.stub.HttpJsonSequenceServiceStub; import java.io.IOException; import java.util.ArrayList; @@ -560,4 +570,178 @@ public void getLocationExceptionTest() throws Exception { // Expected exception. } } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } } diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/SequenceServiceClientTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/SequenceServiceClientTest.java index 15d3443e81..e1d372d833 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/SequenceServiceClientTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/SequenceServiceClientTest.java @@ -33,9 +33,19 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.AbstractMessage; import com.google.protobuf.Any; +import com.google.protobuf.ByteString; import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; import io.grpc.StatusRuntimeException; import java.io.IOException; import java.util.ArrayList; @@ -54,6 +64,7 @@ @Generated("by gapic-generator-java") public class SequenceServiceClientTest { + private static MockIAMPolicy mockIAMPolicy; private static MockLocations mockLocations; private static MockSequenceService mockSequenceService; private static MockServiceHelper mockServiceHelper; @@ -64,10 +75,11 @@ public class SequenceServiceClientTest { public static void startStaticServer() { mockSequenceService = new MockSequenceService(); mockLocations = new MockLocations(); + mockIAMPolicy = new MockIAMPolicy(); mockServiceHelper = new MockServiceHelper( UUID.randomUUID().toString(), - Arrays.asList(mockSequenceService, mockLocations)); + Arrays.asList(mockSequenceService, mockLocations, mockIAMPolicy)); mockServiceHelper.start(); } @@ -547,4 +559,164 @@ public void getLocationExceptionTest() throws Exception { // Expected exception. } } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockIAMPolicy.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + SetIamPolicyRequest actualRequest = ((SetIamPolicyRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getPolicy(), actualRequest.getPolicy()); + Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockIAMPolicy.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetIamPolicyRequest actualRequest = ((GetIamPolicyRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getOptions(), actualRequest.getOptions()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockIAMPolicy.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + TestIamPermissionsRequest actualRequest = ((TestIamPermissionsRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getPermissionsList(), actualRequest.getPermissionsList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } } diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/TestingClientHttpJsonTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/TestingClientHttpJsonTest.java index 10a408b18b..3a593c32fa 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/TestingClientHttpJsonTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/TestingClientHttpJsonTest.java @@ -34,9 +34,18 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.Any; import com.google.protobuf.ByteString; import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; import com.google.showcase.v1beta1.stub.HttpJsonTestingStub; import java.io.IOException; import java.util.ArrayList; @@ -592,4 +601,178 @@ public void getLocationExceptionTest() throws Exception { // Expected exception. } } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } } diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/TestingClientTest.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/TestingClientTest.java index da33afcb02..3120f534ba 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/TestingClientTest.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/TestingClientTest.java @@ -32,10 +32,19 @@ import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; import com.google.common.collect.Lists; +import com.google.iam.v1.AuditConfig; +import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.AbstractMessage; import com.google.protobuf.Any; import com.google.protobuf.ByteString; import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; import io.grpc.StatusRuntimeException; import java.io.IOException; import java.util.ArrayList; @@ -53,6 +62,7 @@ @Generated("by gapic-generator-java") public class TestingClientTest { + private static MockIAMPolicy mockIAMPolicy; private static MockLocations mockLocations; private static MockServiceHelper mockServiceHelper; private static MockTesting mockTesting; @@ -63,10 +73,11 @@ public class TestingClientTest { public static void startStaticServer() { mockTesting = new MockTesting(); mockLocations = new MockLocations(); + mockIAMPolicy = new MockIAMPolicy(); mockServiceHelper = new MockServiceHelper( UUID.randomUUID().toString(), - Arrays.asList(mockTesting, mockLocations)); + Arrays.asList(mockTesting, mockLocations, mockIAMPolicy)); mockServiceHelper.start(); } @@ -541,4 +552,164 @@ public void getLocationExceptionTest() throws Exception { // Expected exception. } } + + @Test + public void setIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockIAMPolicy.addResponse(expectedResponse); + + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + + Policy actualResponse = client.setIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + SetIamPolicyRequest actualRequest = ((SetIamPolicyRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getPolicy(), actualRequest.getPolicy()); + Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void setIamPolicyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + client.setIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getIamPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setVersion(351608024) + .addAllBindings(new ArrayList()) + .addAllAuditConfigs(new ArrayList()) + .setEtag(ByteString.EMPTY) + .build(); + mockIAMPolicy.addResponse(expectedResponse); + + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + + Policy actualResponse = client.getIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetIamPolicyRequest actualRequest = ((GetIamPolicyRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getOptions(), actualRequest.getOptions()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getIamPolicyExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + client.getIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void testIamPermissionsTest() throws Exception { + TestIamPermissionsResponse expectedResponse = + TestIamPermissionsResponse.newBuilder().addAllPermissions(new ArrayList()).build(); + mockIAMPolicy.addResponse(expectedResponse); + + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + + TestIamPermissionsResponse actualResponse = client.testIamPermissions(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockIAMPolicy.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + TestIamPermissionsRequest actualRequest = ((TestIamPermissionsRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getResource(), actualRequest.getResource()); + Assert.assertEquals(request.getPermissionsList(), actualRequest.getPermissionsList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void testIamPermissionsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockIAMPolicy.addException(exception); + + try { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + client.testIamPermissions(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } } From 5bf473b392016b5d1e6a26bc587ac883264afd68 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Tue, 20 Jun 2023 11:58:00 -0400 Subject: [PATCH 03/26] chore: Add IAM showcase tests --- showcase/gapic-showcase/pom.xml | 5 + .../com/google/showcase/v1beta1/it/ITIam.java | 214 +++++++++++++++++- 2 files changed, 215 insertions(+), 4 deletions(-) diff --git a/showcase/gapic-showcase/pom.xml b/showcase/gapic-showcase/pom.xml index 8663ade568..db54898790 100644 --- a/showcase/gapic-showcase/pom.xml +++ b/showcase/gapic-showcase/pom.xml @@ -229,5 +229,10 @@ testlib test + + com.google.api.grpc + grpc-google-iam-v1 + test + diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index bb6a297c0b..0ec484f770 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -15,14 +15,26 @@ */ package com.google.showcase.v1beta1.it; +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertThrows; + +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.NotFoundException; +import com.google.common.collect.ImmutableList; import com.google.iam.v1.Binding; +import com.google.iam.v1.GetIamPolicyRequest; import com.google.iam.v1.Policy; import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.showcase.v1beta1.EchoClient; import com.google.showcase.v1beta1.it.util.TestClientInitializer; +import java.util.List; +import java.util.UUID; import java.util.concurrent.TimeUnit; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.Test; public class ITIam { private static EchoClient grpcClient; @@ -44,11 +56,205 @@ public static void destroyClients() throws InterruptedException { TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS); } + @Test public void testGrpc_setIamPolicy() { - SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() - .setPolicy( - Policy.newBuilder() - .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers"))) + String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + Policy expectedPolicy = + Policy.newBuilder() + .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) + .build(); + SetIamPolicyRequest policyRequest = + SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); + Policy policy = grpcClient.setIamPolicy(policyRequest); + assertThat(policy).isEqualTo(expectedPolicy); + } + + @Test + public void testHttpJson_setIamPolicy() { + String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + Policy expectedPolicy = + Policy.newBuilder() + .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) + .build(); + SetIamPolicyRequest policyRequest = + SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); + Policy policy = httpjsonClient.setIamPolicy(policyRequest); + assertThat(policy).isEqualTo(expectedPolicy); + } + + @Test + public void testGrpc_getIamPolicy() { + String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + Policy expectedPolicy = + Policy.newBuilder() + .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) + .build(); + SetIamPolicyRequest policyRequest = + SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); + grpcClient.setIamPolicy(policyRequest); + + Policy policy = + grpcClient.getIamPolicy(GetIamPolicyRequest.newBuilder().setResource(resource).build()); + assertThat(policy).isEqualTo(expectedPolicy); + } + + @Test + public void testHttpJson_getIamPolicy() { + String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + Policy expectedPolicy = + Policy.newBuilder() + .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) .build(); + SetIamPolicyRequest policyRequest = + SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); + httpjsonClient.setIamPolicy(policyRequest); + + Policy policy = + httpjsonClient.getIamPolicy(GetIamPolicyRequest.newBuilder().setResource(resource).build()); + assertThat(policy).isEqualTo(expectedPolicy); + } + + @Test + public void testGrpc_testIamPermissions() { + String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + Policy expectedPolicy = + Policy.newBuilder() + .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) + .build(); + SetIamPolicyRequest policyRequest = + SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); + grpcClient.setIamPolicy(policyRequest); + List permissions = ImmutableList.of("foo.create"); + TestIamPermissionsResponse testIamPermissionsResponse = + grpcClient.testIamPermissions( + TestIamPermissionsRequest.newBuilder() + .setResource(resource) + .addAllPermissions(permissions) + .build()); + assertThat(testIamPermissionsResponse.getPermissionsList()) + .containsExactlyElementsIn(permissions); + } + + @Test + public void testHttpJson_testIamPermissions() { + String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + Policy expectedPolicy = + Policy.newBuilder() + .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) + .build(); + SetIamPolicyRequest policyRequest = + SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); + httpjsonClient.setIamPolicy(policyRequest); + List permissions = ImmutableList.of("foo.create"); + TestIamPermissionsResponse testIamPermissionsResponse = + httpjsonClient.testIamPermissions( + TestIamPermissionsRequest.newBuilder() + .setResource(resource) + .addAllPermissions(permissions) + .build()); + assertThat(testIamPermissionsResponse.getPermissionsList()) + .containsExactlyElementsIn(permissions); + } + + @Test + public void testGrpc_getIamPolicy_doesNotExist() { + String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + assertThrows( + NotFoundException.class, + () -> + grpcClient.getIamPolicy( + GetIamPolicyRequest.newBuilder().setResource(resource).build())); + } + + @Test + public void testHttpJson_getIamPolicy_doesNotExist() { + String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + assertThrows( + NotFoundException.class, + () -> + httpjsonClient.getIamPolicy( + GetIamPolicyRequest.newBuilder().setResource(resource).build())); + } + + @Test + public void testGrpc_getIamPolicy_missingResource() { + assertThrows( + InvalidArgumentException.class, + () -> grpcClient.getIamPolicy(GetIamPolicyRequest.newBuilder().build())); + } + + @Test + public void testHttpJson_getIamPolicy_missingResource() { + assertThrows( + InvalidArgumentException.class, + () -> httpjsonClient.getIamPolicy(GetIamPolicyRequest.newBuilder().build())); + } + + @Test + public void testGrpc_setIamPolicy_missingResource() { + assertThrows( + InvalidArgumentException.class, + () -> grpcClient.setIamPolicy(SetIamPolicyRequest.newBuilder().build())); + } + + @Test + public void testHttpJson_setIamPolicy_missingResource() { + assertThrows( + InvalidArgumentException.class, + () -> httpjsonClient.setIamPolicy(SetIamPolicyRequest.newBuilder().build())); + } + + @Test + public void testGrpc_setIamPolicy_missingPolicy() { + String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + assertThrows( + InvalidArgumentException.class, + () -> + grpcClient.setIamPolicy( + SetIamPolicyRequest.newBuilder().setResource(resource).build())); + } + + @Test + public void testHttpJson_setIamPolicy_missingPolicy() { + String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + assertThrows( + InvalidArgumentException.class, + () -> + httpjsonClient.setIamPolicy( + SetIamPolicyRequest.newBuilder().setResource(resource).build())); + } + + @Test + public void testGrpc_testIamPermissions_doesNotExist() { + String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + assertThrows( + NotFoundException.class, + () -> + grpcClient.testIamPermissions( + TestIamPermissionsRequest.newBuilder().setResource(resource).build())); + } + + @Test + public void testHttpJson_testIamPermissions_doesNotExist() { + String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + assertThrows( + NotFoundException.class, + () -> + httpjsonClient.testIamPermissions( + TestIamPermissionsRequest.newBuilder().setResource(resource).build())); + } + + @Test + public void testGrpc_testIamPermissions_missingResource() { + assertThrows( + InvalidArgumentException.class, + () -> grpcClient.testIamPermissions(TestIamPermissionsRequest.newBuilder().build())); + } + + @Test + public void testHttpJson_testIamPermissions_missingResource() { + assertThrows( + InvalidArgumentException.class, + () -> httpjsonClient.testIamPermissions(TestIamPermissionsRequest.newBuilder().build())); } } From 2fda5da4f846c00fb6ee8e3b96f0ac69f1cca323 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Tue, 20 Jun 2023 15:07:51 -0400 Subject: [PATCH 04/26] chore: Add samples --- .../getiampolicy/AsyncGetIamPolicy.java | 53 ++++++++ .../getiampolicy/SyncGetIamPolicy.java | 50 +++++++ .../setiampolicy/AsyncSetIamPolicy.java | 54 ++++++++ .../setiampolicy/SyncSetIamPolicy.java | 51 +++++++ .../AsyncTestIamPermissions.java | 54 ++++++++ .../SyncTestIamPermissions.java | 50 +++++++ .../echo/getiampolicy/AsyncGetIamPolicy.java | 53 ++++++++ .../echo/getiampolicy/SyncGetIamPolicy.java | 50 +++++++ .../echo/setiampolicy/AsyncSetIamPolicy.java | 54 ++++++++ .../echo/setiampolicy/SyncSetIamPolicy.java | 51 +++++++ .../AsyncTestIamPermissions.java | 54 ++++++++ .../SyncTestIamPermissions.java | 50 +++++++ .../getiampolicy/AsyncGetIamPolicy.java | 53 ++++++++ .../getiampolicy/SyncGetIamPolicy.java | 50 +++++++ .../setiampolicy/AsyncSetIamPolicy.java | 54 ++++++++ .../setiampolicy/SyncSetIamPolicy.java | 51 +++++++ .../AsyncTestIamPermissions.java | 54 ++++++++ .../SyncTestIamPermissions.java | 50 +++++++ .../getiampolicy/AsyncGetIamPolicy.java | 53 ++++++++ .../getiampolicy/SyncGetIamPolicy.java | 50 +++++++ .../setiampolicy/AsyncSetIamPolicy.java | 54 ++++++++ .../setiampolicy/SyncSetIamPolicy.java | 51 +++++++ .../AsyncTestIamPermissions.java | 54 ++++++++ .../SyncTestIamPermissions.java | 50 +++++++ .../getiampolicy/AsyncGetIamPolicy.java | 53 ++++++++ .../getiampolicy/SyncGetIamPolicy.java | 50 +++++++ .../setiampolicy/AsyncSetIamPolicy.java | 54 ++++++++ .../setiampolicy/SyncSetIamPolicy.java | 51 +++++++ .../AsyncTestIamPermissions.java | 54 ++++++++ .../SyncTestIamPermissions.java | 50 +++++++ .../getiampolicy/AsyncGetIamPolicy.java | 53 ++++++++ .../getiampolicy/SyncGetIamPolicy.java | 50 +++++++ .../setiampolicy/AsyncSetIamPolicy.java | 54 ++++++++ .../setiampolicy/SyncSetIamPolicy.java | 51 +++++++ .../AsyncTestIamPermissions.java | 54 ++++++++ .../SyncTestIamPermissions.java | 50 +++++++ .../showcase/v1beta1/MockIAMPolicy.java | 59 ++++++++ .../showcase/v1beta1/MockIAMPolicyImpl.java | 127 ++++++++++++++++++ 38 files changed, 2058 insertions(+) create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/getiampolicy/AsyncGetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/getiampolicy/SyncGetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/setiampolicy/AsyncSetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/setiampolicy/SyncSetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/testiampermissions/AsyncTestIamPermissions.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/testiampermissions/SyncTestIamPermissions.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/getiampolicy/AsyncGetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/getiampolicy/SyncGetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/setiampolicy/AsyncSetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/setiampolicy/SyncSetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/testiampermissions/AsyncTestIamPermissions.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/testiampermissions/SyncTestIamPermissions.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/getiampolicy/AsyncGetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/getiampolicy/SyncGetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/setiampolicy/AsyncSetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/setiampolicy/SyncSetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/testiampermissions/AsyncTestIamPermissions.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/testiampermissions/SyncTestIamPermissions.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/getiampolicy/AsyncGetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/getiampolicy/SyncGetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/setiampolicy/AsyncSetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/setiampolicy/SyncSetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/testiampermissions/AsyncTestIamPermissions.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/testiampermissions/SyncTestIamPermissions.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/getiampolicy/AsyncGetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/getiampolicy/SyncGetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/setiampolicy/AsyncSetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/setiampolicy/SyncSetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/testiampermissions/AsyncTestIamPermissions.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/testiampermissions/SyncTestIamPermissions.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/getiampolicy/AsyncGetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/getiampolicy/SyncGetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/setiampolicy/AsyncSetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/setiampolicy/SyncSetIamPolicy.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/testiampermissions/AsyncTestIamPermissions.java create mode 100644 showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/testiampermissions/SyncTestIamPermissions.java create mode 100644 showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MockIAMPolicy.java create mode 100644 showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MockIAMPolicyImpl.java diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/getiampolicy/AsyncGetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/getiampolicy/AsyncGetIamPolicy.java new file mode 100644 index 0000000000..d2d4492e96 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/getiampolicy/AsyncGetIamPolicy.java @@ -0,0 +1,53 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_GetIamPolicy_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.ComplianceClient; + +public class AsyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncGetIamPolicy(); + } + + public static void asyncGetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + ApiFuture future = complianceClient.getIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_GetIamPolicy_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/getiampolicy/SyncGetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/getiampolicy/SyncGetIamPolicy.java new file mode 100644 index 0000000000..73c78e0b63 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/getiampolicy/SyncGetIamPolicy.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_GetIamPolicy_sync] +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.ComplianceClient; + +public class SyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + syncGetIamPolicy(); + } + + public static void syncGetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + Policy response = complianceClient.getIamPolicy(request); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_GetIamPolicy_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/setiampolicy/AsyncSetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/setiampolicy/AsyncSetIamPolicy.java new file mode 100644 index 0000000000..dc689ee76b --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/setiampolicy/AsyncSetIamPolicy.java @@ -0,0 +1,54 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_SetIamPolicy_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.ComplianceClient; + +public class AsyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncSetIamPolicy(); + } + + public static void asyncSetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = complianceClient.setIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_SetIamPolicy_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/setiampolicy/SyncSetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/setiampolicy/SyncSetIamPolicy.java new file mode 100644 index 0000000000..661a8b156a --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/setiampolicy/SyncSetIamPolicy.java @@ -0,0 +1,51 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_SetIamPolicy_sync] +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.ComplianceClient; + +public class SyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + syncSetIamPolicy(); + } + + public static void syncSetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Policy response = complianceClient.setIamPolicy(request); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_SetIamPolicy_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/testiampermissions/AsyncTestIamPermissions.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/testiampermissions/AsyncTestIamPermissions.java new file mode 100644 index 0000000000..8c1d3a74fd --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/testiampermissions/AsyncTestIamPermissions.java @@ -0,0 +1,54 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_TestIamPermissions_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.ComplianceClient; +import java.util.ArrayList; + +public class AsyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + asyncTestIamPermissions(); + } + + public static void asyncTestIamPermissions() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + ApiFuture future = + complianceClient.testIamPermissionsCallable().futureCall(request); + // Do something. + TestIamPermissionsResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_TestIamPermissions_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/testiampermissions/SyncTestIamPermissions.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/testiampermissions/SyncTestIamPermissions.java new file mode 100644 index 0000000000..ade92a9a66 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/compliance/testiampermissions/SyncTestIamPermissions.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Compliance_TestIamPermissions_sync] +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.ComplianceClient; +import java.util.ArrayList; + +public class SyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + syncTestIamPermissions(); + } + + public static void syncTestIamPermissions() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (ComplianceClient complianceClient = ComplianceClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + TestIamPermissionsResponse response = complianceClient.testIamPermissions(request); + } + } +} +// [END localhost7469_v1beta1_generated_Compliance_TestIamPermissions_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/getiampolicy/AsyncGetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/getiampolicy/AsyncGetIamPolicy.java new file mode 100644 index 0000000000..e24d3628b2 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/getiampolicy/AsyncGetIamPolicy.java @@ -0,0 +1,53 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_GetIamPolicy_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.EchoClient; + +public class AsyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncGetIamPolicy(); + } + + public static void asyncGetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + ApiFuture future = echoClient.getIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_GetIamPolicy_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/getiampolicy/SyncGetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/getiampolicy/SyncGetIamPolicy.java new file mode 100644 index 0000000000..996048c045 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/getiampolicy/SyncGetIamPolicy.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_GetIamPolicy_sync] +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.EchoClient; + +public class SyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + syncGetIamPolicy(); + } + + public static void syncGetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + Policy response = echoClient.getIamPolicy(request); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_GetIamPolicy_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/setiampolicy/AsyncSetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/setiampolicy/AsyncSetIamPolicy.java new file mode 100644 index 0000000000..be2a431699 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/setiampolicy/AsyncSetIamPolicy.java @@ -0,0 +1,54 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_SetIamPolicy_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.EchoClient; + +public class AsyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncSetIamPolicy(); + } + + public static void asyncSetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = echoClient.setIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_SetIamPolicy_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/setiampolicy/SyncSetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/setiampolicy/SyncSetIamPolicy.java new file mode 100644 index 0000000000..df4aad5c6f --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/setiampolicy/SyncSetIamPolicy.java @@ -0,0 +1,51 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_SetIamPolicy_sync] +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.EchoClient; + +public class SyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + syncSetIamPolicy(); + } + + public static void syncSetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Policy response = echoClient.setIamPolicy(request); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_SetIamPolicy_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/testiampermissions/AsyncTestIamPermissions.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/testiampermissions/AsyncTestIamPermissions.java new file mode 100644 index 0000000000..b1629ef44b --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/testiampermissions/AsyncTestIamPermissions.java @@ -0,0 +1,54 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_TestIamPermissions_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.EchoClient; +import java.util.ArrayList; + +public class AsyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + asyncTestIamPermissions(); + } + + public static void asyncTestIamPermissions() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + ApiFuture future = + echoClient.testIamPermissionsCallable().futureCall(request); + // Do something. + TestIamPermissionsResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_TestIamPermissions_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/testiampermissions/SyncTestIamPermissions.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/testiampermissions/SyncTestIamPermissions.java new file mode 100644 index 0000000000..3cf53789f5 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/echo/testiampermissions/SyncTestIamPermissions.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Echo_TestIamPermissions_sync] +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.EchoClient; +import java.util.ArrayList; + +public class SyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + syncTestIamPermissions(); + } + + public static void syncTestIamPermissions() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (EchoClient echoClient = EchoClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + TestIamPermissionsResponse response = echoClient.testIamPermissions(request); + } + } +} +// [END localhost7469_v1beta1_generated_Echo_TestIamPermissions_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/getiampolicy/AsyncGetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/getiampolicy/AsyncGetIamPolicy.java new file mode 100644 index 0000000000..c65a519e58 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/getiampolicy/AsyncGetIamPolicy.java @@ -0,0 +1,53 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_GetIamPolicy_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.IdentityClient; + +public class AsyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncGetIamPolicy(); + } + + public static void asyncGetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + ApiFuture future = identityClient.getIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_GetIamPolicy_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/getiampolicy/SyncGetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/getiampolicy/SyncGetIamPolicy.java new file mode 100644 index 0000000000..9c9d03dc19 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/getiampolicy/SyncGetIamPolicy.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_GetIamPolicy_sync] +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.IdentityClient; + +public class SyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + syncGetIamPolicy(); + } + + public static void syncGetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + Policy response = identityClient.getIamPolicy(request); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_GetIamPolicy_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/setiampolicy/AsyncSetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/setiampolicy/AsyncSetIamPolicy.java new file mode 100644 index 0000000000..fd82d0947e --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/setiampolicy/AsyncSetIamPolicy.java @@ -0,0 +1,54 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_SetIamPolicy_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.IdentityClient; + +public class AsyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncSetIamPolicy(); + } + + public static void asyncSetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = identityClient.setIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_SetIamPolicy_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/setiampolicy/SyncSetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/setiampolicy/SyncSetIamPolicy.java new file mode 100644 index 0000000000..40d8c49efb --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/setiampolicy/SyncSetIamPolicy.java @@ -0,0 +1,51 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_SetIamPolicy_sync] +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.IdentityClient; + +public class SyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + syncSetIamPolicy(); + } + + public static void syncSetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Policy response = identityClient.setIamPolicy(request); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_SetIamPolicy_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/testiampermissions/AsyncTestIamPermissions.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/testiampermissions/AsyncTestIamPermissions.java new file mode 100644 index 0000000000..eabbf0662f --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/testiampermissions/AsyncTestIamPermissions.java @@ -0,0 +1,54 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_TestIamPermissions_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.IdentityClient; +import java.util.ArrayList; + +public class AsyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + asyncTestIamPermissions(); + } + + public static void asyncTestIamPermissions() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + ApiFuture future = + identityClient.testIamPermissionsCallable().futureCall(request); + // Do something. + TestIamPermissionsResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_TestIamPermissions_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/testiampermissions/SyncTestIamPermissions.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/testiampermissions/SyncTestIamPermissions.java new file mode 100644 index 0000000000..a2c40f6212 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/identity/testiampermissions/SyncTestIamPermissions.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Identity_TestIamPermissions_sync] +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.IdentityClient; +import java.util.ArrayList; + +public class SyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + syncTestIamPermissions(); + } + + public static void syncTestIamPermissions() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (IdentityClient identityClient = IdentityClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + TestIamPermissionsResponse response = identityClient.testIamPermissions(request); + } + } +} +// [END localhost7469_v1beta1_generated_Identity_TestIamPermissions_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/getiampolicy/AsyncGetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/getiampolicy/AsyncGetIamPolicy.java new file mode 100644 index 0000000000..cbd62add0e --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/getiampolicy/AsyncGetIamPolicy.java @@ -0,0 +1,53 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_GetIamPolicy_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.MessagingClient; + +public class AsyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncGetIamPolicy(); + } + + public static void asyncGetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + ApiFuture future = messagingClient.getIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_GetIamPolicy_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/getiampolicy/SyncGetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/getiampolicy/SyncGetIamPolicy.java new file mode 100644 index 0000000000..fb328a20d5 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/getiampolicy/SyncGetIamPolicy.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_GetIamPolicy_sync] +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.MessagingClient; + +public class SyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + syncGetIamPolicy(); + } + + public static void syncGetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + Policy response = messagingClient.getIamPolicy(request); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_GetIamPolicy_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/setiampolicy/AsyncSetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/setiampolicy/AsyncSetIamPolicy.java new file mode 100644 index 0000000000..496278c02e --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/setiampolicy/AsyncSetIamPolicy.java @@ -0,0 +1,54 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_SetIamPolicy_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.MessagingClient; + +public class AsyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncSetIamPolicy(); + } + + public static void asyncSetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = messagingClient.setIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_SetIamPolicy_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/setiampolicy/SyncSetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/setiampolicy/SyncSetIamPolicy.java new file mode 100644 index 0000000000..c0963808b9 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/setiampolicy/SyncSetIamPolicy.java @@ -0,0 +1,51 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_SetIamPolicy_sync] +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.MessagingClient; + +public class SyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + syncSetIamPolicy(); + } + + public static void syncSetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Policy response = messagingClient.setIamPolicy(request); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_SetIamPolicy_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/testiampermissions/AsyncTestIamPermissions.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/testiampermissions/AsyncTestIamPermissions.java new file mode 100644 index 0000000000..8fd9c8cd50 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/testiampermissions/AsyncTestIamPermissions.java @@ -0,0 +1,54 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_TestIamPermissions_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.MessagingClient; +import java.util.ArrayList; + +public class AsyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + asyncTestIamPermissions(); + } + + public static void asyncTestIamPermissions() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + ApiFuture future = + messagingClient.testIamPermissionsCallable().futureCall(request); + // Do something. + TestIamPermissionsResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_TestIamPermissions_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/testiampermissions/SyncTestIamPermissions.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/testiampermissions/SyncTestIamPermissions.java new file mode 100644 index 0000000000..b14ad4644e --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/messaging/testiampermissions/SyncTestIamPermissions.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Messaging_TestIamPermissions_sync] +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.MessagingClient; +import java.util.ArrayList; + +public class SyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + syncTestIamPermissions(); + } + + public static void syncTestIamPermissions() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (MessagingClient messagingClient = MessagingClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + TestIamPermissionsResponse response = messagingClient.testIamPermissions(request); + } + } +} +// [END localhost7469_v1beta1_generated_Messaging_TestIamPermissions_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/getiampolicy/AsyncGetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/getiampolicy/AsyncGetIamPolicy.java new file mode 100644 index 0000000000..4d486a194f --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/getiampolicy/AsyncGetIamPolicy.java @@ -0,0 +1,53 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_GetIamPolicy_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class AsyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncGetIamPolicy(); + } + + public static void asyncGetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + ApiFuture future = sequenceServiceClient.getIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_GetIamPolicy_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/getiampolicy/SyncGetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/getiampolicy/SyncGetIamPolicy.java new file mode 100644 index 0000000000..3b8516dbdf --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/getiampolicy/SyncGetIamPolicy.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_GetIamPolicy_sync] +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class SyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + syncGetIamPolicy(); + } + + public static void syncGetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + Policy response = sequenceServiceClient.getIamPolicy(request); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_GetIamPolicy_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/setiampolicy/AsyncSetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/setiampolicy/AsyncSetIamPolicy.java new file mode 100644 index 0000000000..bbc0817d26 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/setiampolicy/AsyncSetIamPolicy.java @@ -0,0 +1,54 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_SetIamPolicy_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class AsyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncSetIamPolicy(); + } + + public static void asyncSetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = sequenceServiceClient.setIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_SetIamPolicy_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/setiampolicy/SyncSetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/setiampolicy/SyncSetIamPolicy.java new file mode 100644 index 0000000000..053eaabc2f --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/setiampolicy/SyncSetIamPolicy.java @@ -0,0 +1,51 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_SetIamPolicy_sync] +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.SequenceServiceClient; + +public class SyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + syncSetIamPolicy(); + } + + public static void syncSetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Policy response = sequenceServiceClient.setIamPolicy(request); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_SetIamPolicy_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/testiampermissions/AsyncTestIamPermissions.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/testiampermissions/AsyncTestIamPermissions.java new file mode 100644 index 0000000000..a9ebd6d513 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/testiampermissions/AsyncTestIamPermissions.java @@ -0,0 +1,54 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_TestIamPermissions_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.SequenceServiceClient; +import java.util.ArrayList; + +public class AsyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + asyncTestIamPermissions(); + } + + public static void asyncTestIamPermissions() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + ApiFuture future = + sequenceServiceClient.testIamPermissionsCallable().futureCall(request); + // Do something. + TestIamPermissionsResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_TestIamPermissions_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/testiampermissions/SyncTestIamPermissions.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/testiampermissions/SyncTestIamPermissions.java new file mode 100644 index 0000000000..06a1daf50d --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/sequenceservice/testiampermissions/SyncTestIamPermissions.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_SequenceService_TestIamPermissions_sync] +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.SequenceServiceClient; +import java.util.ArrayList; + +public class SyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + syncTestIamPermissions(); + } + + public static void syncTestIamPermissions() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (SequenceServiceClient sequenceServiceClient = SequenceServiceClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + TestIamPermissionsResponse response = sequenceServiceClient.testIamPermissions(request); + } + } +} +// [END localhost7469_v1beta1_generated_SequenceService_TestIamPermissions_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/getiampolicy/AsyncGetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/getiampolicy/AsyncGetIamPolicy.java new file mode 100644 index 0000000000..4c341d5010 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/getiampolicy/AsyncGetIamPolicy.java @@ -0,0 +1,53 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_GetIamPolicy_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.TestingClient; + +public class AsyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncGetIamPolicy(); + } + + public static void asyncGetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + ApiFuture future = testingClient.getIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_GetIamPolicy_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/getiampolicy/SyncGetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/getiampolicy/SyncGetIamPolicy.java new file mode 100644 index 0000000000..438d22ccc5 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/getiampolicy/SyncGetIamPolicy.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_GetIamPolicy_sync] +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.GetPolicyOptions; +import com.google.iam.v1.Policy; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.TestingClient; + +public class SyncGetIamPolicy { + + public static void main(String[] args) throws Exception { + syncGetIamPolicy(); + } + + public static void syncGetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + GetIamPolicyRequest request = + GetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setOptions(GetPolicyOptions.newBuilder().build()) + .build(); + Policy response = testingClient.getIamPolicy(request); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_GetIamPolicy_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/setiampolicy/AsyncSetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/setiampolicy/AsyncSetIamPolicy.java new file mode 100644 index 0000000000..85f76c4c7e --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/setiampolicy/AsyncSetIamPolicy.java @@ -0,0 +1,54 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_SetIamPolicy_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.TestingClient; + +public class AsyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + asyncSetIamPolicy(); + } + + public static void asyncSetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = testingClient.setIamPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_SetIamPolicy_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/setiampolicy/SyncSetIamPolicy.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/setiampolicy/SyncSetIamPolicy.java new file mode 100644 index 0000000000..83aebdb52c --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/setiampolicy/SyncSetIamPolicy.java @@ -0,0 +1,51 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_SetIamPolicy_sync] +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.protobuf.FieldMask; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.TestingClient; + +public class SyncSetIamPolicy { + + public static void main(String[] args) throws Exception { + syncSetIamPolicy(); + } + + public static void syncSetIamPolicy() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + SetIamPolicyRequest request = + SetIamPolicyRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .setPolicy(Policy.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + Policy response = testingClient.setIamPolicy(request); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_SetIamPolicy_sync] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/testiampermissions/AsyncTestIamPermissions.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/testiampermissions/AsyncTestIamPermissions.java new file mode 100644 index 0000000000..0f52261540 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/testiampermissions/AsyncTestIamPermissions.java @@ -0,0 +1,54 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_TestIamPermissions_async] +import com.google.api.core.ApiFuture; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.TestingClient; +import java.util.ArrayList; + +public class AsyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + asyncTestIamPermissions(); + } + + public static void asyncTestIamPermissions() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + ApiFuture future = + testingClient.testIamPermissionsCallable().futureCall(request); + // Do something. + TestIamPermissionsResponse response = future.get(); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_TestIamPermissions_async] diff --git a/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/testiampermissions/SyncTestIamPermissions.java b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/testiampermissions/SyncTestIamPermissions.java new file mode 100644 index 0000000000..6d3ca7fc09 --- /dev/null +++ b/showcase/gapic-showcase/samples/snippets/generated/src/main/java/com/google/showcase/v1beta1/testing/testiampermissions/SyncTestIamPermissions.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1.samples; + +// [START localhost7469_v1beta1_generated_Testing_TestIamPermissions_sync] +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.showcase.v1beta1.BlurbName; +import com.google.showcase.v1beta1.TestingClient; +import java.util.ArrayList; + +public class SyncTestIamPermissions { + + public static void main(String[] args) throws Exception { + syncTestIamPermissions(); + } + + public static void syncTestIamPermissions() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + try (TestingClient testingClient = TestingClient.create()) { + TestIamPermissionsRequest request = + TestIamPermissionsRequest.newBuilder() + .setResource( + BlurbName.ofUserLegacyUserBlurbName("[USER]", "[LEGACY_USER]", "[BLURB]") + .toString()) + .addAllPermissions(new ArrayList()) + .build(); + TestIamPermissionsResponse response = testingClient.testIamPermissions(request); + } + } +} +// [END localhost7469_v1beta1_generated_Testing_TestIamPermissions_sync] diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MockIAMPolicy.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MockIAMPolicy.java new file mode 100644 index 0000000000..182872091c --- /dev/null +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MockIAMPolicy.java @@ -0,0 +1,59 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.AbstractMessage; +import io.grpc.ServerServiceDefinition; +import java.util.List; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockIAMPolicy implements MockGrpcService { + private final MockIAMPolicyImpl serviceImpl; + + public MockIAMPolicy() { + serviceImpl = new MockIAMPolicyImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(AbstractMessage response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MockIAMPolicyImpl.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MockIAMPolicyImpl.java new file mode 100644 index 0000000000..40abf1c36a --- /dev/null +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/MockIAMPolicyImpl.java @@ -0,0 +1,127 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.showcase.v1beta1; + +import com.google.api.core.BetaApi; +import com.google.iam.v1.GetIamPolicyRequest; +import com.google.iam.v1.IAMPolicyGrpc.IAMPolicyImplBase; +import com.google.iam.v1.Policy; +import com.google.iam.v1.SetIamPolicyRequest; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.protobuf.AbstractMessage; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockIAMPolicyImpl extends IAMPolicyImplBase { + private List requests; + private Queue responses; + + public MockIAMPolicyImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(AbstractMessage response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void testIamPermissions( + TestIamPermissionsRequest request, + StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof TestIamPermissionsResponse) { + requests.add(request); + responseObserver.onNext(((TestIamPermissionsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method TestIamPermissions, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + TestIamPermissionsResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void setIamPolicy(SetIamPolicyRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Policy) { + requests.add(request); + responseObserver.onNext(((Policy) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method SetIamPolicy, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Policy.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void getIamPolicy(GetIamPolicyRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof Policy) { + requests.add(request); + responseObserver.onNext(((Policy) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method GetIamPolicy, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + Policy.class.getName(), + Exception.class.getName()))); + } + } +} From 6c2f4ba6e075829a1d13f182738f42c1b58ae64e Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Tue, 20 Jun 2023 16:30:01 -0400 Subject: [PATCH 05/26] chore: Exclude httpjson tests --- showcase/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/showcase/pom.xml b/showcase/pom.xml index 6842b5b95f..5a0bb236c5 100644 --- a/showcase/pom.xml +++ b/showcase/pom.xml @@ -80,6 +80,11 @@ **/MessagingClientHttpJsonTest.java + **/ComplianceClientHttpJsonTest.java + **/EchoClientHttpJsonTest.java + **/IdentityClientHttpJsonTest.java + **/SequenceServiceClientHttpJsonTest.java + **/TestingClientHttpJsonTest.java sponge_log ${skipUnitTests} From db735abb7623d9b2e687413503e075938e9a398a Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Tue, 20 Jun 2023 16:38:37 -0400 Subject: [PATCH 06/26] chore: Use @Before to create the resource --- .../com/google/showcase/v1beta1/it/ITIam.java | 99 +++++++++---------- 1 file changed, 47 insertions(+), 52 deletions(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index 0ec484f770..3a66fb8711 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -33,12 +33,14 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; import org.junit.AfterClass; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; public class ITIam { private static EchoClient grpcClient; private static EchoClient httpjsonClient; + private String resource; @BeforeClass public static void createClients() throws Exception { @@ -46,6 +48,11 @@ public static void createClients() throws Exception { httpjsonClient = TestClientInitializer.createHttpJsonEchoClient(); } + @Before + public void setupTests() { + resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + } + @AfterClass public static void destroyClients() throws InterruptedException { grpcClient.close(); @@ -58,7 +65,6 @@ public static void destroyClients() throws InterruptedException { @Test public void testGrpc_setIamPolicy() { - String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); Policy expectedPolicy = Policy.newBuilder() .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) @@ -71,7 +77,6 @@ public void testGrpc_setIamPolicy() { @Test public void testHttpJson_setIamPolicy() { - String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); Policy expectedPolicy = Policy.newBuilder() .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) @@ -84,7 +89,6 @@ public void testHttpJson_setIamPolicy() { @Test public void testGrpc_getIamPolicy() { - String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); Policy expectedPolicy = Policy.newBuilder() .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) @@ -100,7 +104,6 @@ public void testGrpc_getIamPolicy() { @Test public void testHttpJson_getIamPolicy() { - String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); Policy expectedPolicy = Policy.newBuilder() .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) @@ -114,51 +117,8 @@ public void testHttpJson_getIamPolicy() { assertThat(policy).isEqualTo(expectedPolicy); } - @Test - public void testGrpc_testIamPermissions() { - String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); - Policy expectedPolicy = - Policy.newBuilder() - .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) - .build(); - SetIamPolicyRequest policyRequest = - SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); - grpcClient.setIamPolicy(policyRequest); - List permissions = ImmutableList.of("foo.create"); - TestIamPermissionsResponse testIamPermissionsResponse = - grpcClient.testIamPermissions( - TestIamPermissionsRequest.newBuilder() - .setResource(resource) - .addAllPermissions(permissions) - .build()); - assertThat(testIamPermissionsResponse.getPermissionsList()) - .containsExactlyElementsIn(permissions); - } - - @Test - public void testHttpJson_testIamPermissions() { - String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); - Policy expectedPolicy = - Policy.newBuilder() - .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) - .build(); - SetIamPolicyRequest policyRequest = - SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); - httpjsonClient.setIamPolicy(policyRequest); - List permissions = ImmutableList.of("foo.create"); - TestIamPermissionsResponse testIamPermissionsResponse = - httpjsonClient.testIamPermissions( - TestIamPermissionsRequest.newBuilder() - .setResource(resource) - .addAllPermissions(permissions) - .build()); - assertThat(testIamPermissionsResponse.getPermissionsList()) - .containsExactlyElementsIn(permissions); - } - @Test public void testGrpc_getIamPolicy_doesNotExist() { - String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); assertThrows( NotFoundException.class, () -> @@ -168,7 +128,6 @@ public void testGrpc_getIamPolicy_doesNotExist() { @Test public void testHttpJson_getIamPolicy_doesNotExist() { - String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); assertThrows( NotFoundException.class, () -> @@ -206,7 +165,6 @@ public void testHttpJson_setIamPolicy_missingResource() { @Test public void testGrpc_setIamPolicy_missingPolicy() { - String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); assertThrows( InvalidArgumentException.class, () -> @@ -216,7 +174,6 @@ public void testGrpc_setIamPolicy_missingPolicy() { @Test public void testHttpJson_setIamPolicy_missingPolicy() { - String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); assertThrows( InvalidArgumentException.class, () -> @@ -224,9 +181,48 @@ public void testHttpJson_setIamPolicy_missingPolicy() { SetIamPolicyRequest.newBuilder().setResource(resource).build())); } + @Test + public void testGrpc_testIamPermissions() { + Policy expectedPolicy = + Policy.newBuilder() + .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) + .build(); + SetIamPolicyRequest policyRequest = + SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); + grpcClient.setIamPolicy(policyRequest); + List permissions = ImmutableList.of("foo.create"); + TestIamPermissionsResponse testIamPermissionsResponse = + grpcClient.testIamPermissions( + TestIamPermissionsRequest.newBuilder() + .setResource(resource) + .addAllPermissions(permissions) + .build()); + assertThat(testIamPermissionsResponse.getPermissionsList()) + .containsExactlyElementsIn(permissions); + } + + @Test + public void testHttpJson_testIamPermissions() { + Policy expectedPolicy = + Policy.newBuilder() + .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) + .build(); + SetIamPolicyRequest policyRequest = + SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); + httpjsonClient.setIamPolicy(policyRequest); + List permissions = ImmutableList.of("foo.create"); + TestIamPermissionsResponse testIamPermissionsResponse = + httpjsonClient.testIamPermissions( + TestIamPermissionsRequest.newBuilder() + .setResource(resource) + .addAllPermissions(permissions) + .build()); + assertThat(testIamPermissionsResponse.getPermissionsList()) + .containsExactlyElementsIn(permissions); + } + @Test public void testGrpc_testIamPermissions_doesNotExist() { - String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); assertThrows( NotFoundException.class, () -> @@ -236,7 +232,6 @@ public void testGrpc_testIamPermissions_doesNotExist() { @Test public void testHttpJson_testIamPermissions_doesNotExist() { - String resource = "users/" + UUID.randomUUID().toString().substring(0, 8); assertThrows( NotFoundException.class, () -> From d51e35fdd25b9a67b9305362e7b953a7fbfad513 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 13:40:32 -0400 Subject: [PATCH 07/26] chore: Use constant for policy --- .../com/google/showcase/v1beta1/it/ITIam.java | 48 ++++++------------- 1 file changed, 14 insertions(+), 34 deletions(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index 3a66fb8711..a3d65873c0 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -38,6 +38,10 @@ import org.junit.Test; public class ITIam { + private static final Policy DEFAULT_POLICY = + Policy.newBuilder() + .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) + .build(); private static EchoClient grpcClient; private static EchoClient httpjsonClient; private String resource; @@ -65,56 +69,40 @@ public static void destroyClients() throws InterruptedException { @Test public void testGrpc_setIamPolicy() { - Policy expectedPolicy = - Policy.newBuilder() - .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) - .build(); SetIamPolicyRequest policyRequest = - SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); + SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); Policy policy = grpcClient.setIamPolicy(policyRequest); - assertThat(policy).isEqualTo(expectedPolicy); + assertThat(policy).isEqualTo(DEFAULT_POLICY); } @Test public void testHttpJson_setIamPolicy() { - Policy expectedPolicy = - Policy.newBuilder() - .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) - .build(); SetIamPolicyRequest policyRequest = - SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); + SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); Policy policy = httpjsonClient.setIamPolicy(policyRequest); - assertThat(policy).isEqualTo(expectedPolicy); + assertThat(policy).isEqualTo(DEFAULT_POLICY); } @Test public void testGrpc_getIamPolicy() { - Policy expectedPolicy = - Policy.newBuilder() - .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) - .build(); SetIamPolicyRequest policyRequest = - SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); + SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); grpcClient.setIamPolicy(policyRequest); Policy policy = grpcClient.getIamPolicy(GetIamPolicyRequest.newBuilder().setResource(resource).build()); - assertThat(policy).isEqualTo(expectedPolicy); + assertThat(policy).isEqualTo(DEFAULT_POLICY); } @Test public void testHttpJson_getIamPolicy() { - Policy expectedPolicy = - Policy.newBuilder() - .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) - .build(); SetIamPolicyRequest policyRequest = - SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); + SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); httpjsonClient.setIamPolicy(policyRequest); Policy policy = httpjsonClient.getIamPolicy(GetIamPolicyRequest.newBuilder().setResource(resource).build()); - assertThat(policy).isEqualTo(expectedPolicy); + assertThat(policy).isEqualTo(DEFAULT_POLICY); } @Test @@ -183,12 +171,8 @@ public void testHttpJson_setIamPolicy_missingPolicy() { @Test public void testGrpc_testIamPermissions() { - Policy expectedPolicy = - Policy.newBuilder() - .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) - .build(); SetIamPolicyRequest policyRequest = - SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); + SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); grpcClient.setIamPolicy(policyRequest); List permissions = ImmutableList.of("foo.create"); TestIamPermissionsResponse testIamPermissionsResponse = @@ -203,12 +187,8 @@ public void testGrpc_testIamPermissions() { @Test public void testHttpJson_testIamPermissions() { - Policy expectedPolicy = - Policy.newBuilder() - .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) - .build(); SetIamPolicyRequest policyRequest = - SetIamPolicyRequest.newBuilder().setPolicy(expectedPolicy).setResource(resource).build(); + SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); httpjsonClient.setIamPolicy(policyRequest); List permissions = ImmutableList.of("foo.create"); TestIamPermissionsResponse testIamPermissionsResponse = From 6b4255a64e47baa879e885b243aee74ec5574a23 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 14:05:38 -0400 Subject: [PATCH 08/26] chore: Log resource name --- .../com/google/showcase/v1beta1/it/ITIam.java | 65 ++++++++++--------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index a3d65873c0..adefe89449 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -55,6 +55,7 @@ public static void createClients() throws Exception { @Before public void setupTests() { resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + System.out.println(resource); } @AfterClass @@ -83,6 +84,38 @@ public void testHttpJson_setIamPolicy() { assertThat(policy).isEqualTo(DEFAULT_POLICY); } + @Test + public void testGrpc_setIamPolicy_missingResource() { + assertThrows( + InvalidArgumentException.class, + () -> grpcClient.setIamPolicy(SetIamPolicyRequest.newBuilder().build())); + } + + @Test + public void testHttpJson_setIamPolicy_missingResource() { + assertThrows( + InvalidArgumentException.class, + () -> httpjsonClient.setIamPolicy(SetIamPolicyRequest.newBuilder().build())); + } + + @Test + public void testGrpc_setIamPolicy_missingPolicy() { + assertThrows( + InvalidArgumentException.class, + () -> + grpcClient.setIamPolicy( + SetIamPolicyRequest.newBuilder().setResource(resource).build())); + } + + @Test + public void testHttpJson_setIamPolicy_missingPolicy() { + assertThrows( + InvalidArgumentException.class, + () -> + httpjsonClient.setIamPolicy( + SetIamPolicyRequest.newBuilder().setResource(resource).build())); + } + @Test public void testGrpc_getIamPolicy() { SetIamPolicyRequest policyRequest = @@ -137,38 +170,6 @@ public void testHttpJson_getIamPolicy_missingResource() { () -> httpjsonClient.getIamPolicy(GetIamPolicyRequest.newBuilder().build())); } - @Test - public void testGrpc_setIamPolicy_missingResource() { - assertThrows( - InvalidArgumentException.class, - () -> grpcClient.setIamPolicy(SetIamPolicyRequest.newBuilder().build())); - } - - @Test - public void testHttpJson_setIamPolicy_missingResource() { - assertThrows( - InvalidArgumentException.class, - () -> httpjsonClient.setIamPolicy(SetIamPolicyRequest.newBuilder().build())); - } - - @Test - public void testGrpc_setIamPolicy_missingPolicy() { - assertThrows( - InvalidArgumentException.class, - () -> - grpcClient.setIamPolicy( - SetIamPolicyRequest.newBuilder().setResource(resource).build())); - } - - @Test - public void testHttpJson_setIamPolicy_missingPolicy() { - assertThrows( - InvalidArgumentException.class, - () -> - httpjsonClient.setIamPolicy( - SetIamPolicyRequest.newBuilder().setResource(resource).build())); - } - @Test public void testGrpc_testIamPermissions() { SetIamPolicyRequest policyRequest = From 60470465229ea7d8896bf186acca14417cad5212 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 14:24:56 -0400 Subject: [PATCH 09/26] chore: Test use setPolicyRequest's resourceName --- .../src/test/java/com/google/showcase/v1beta1/it/ITIam.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index adefe89449..25369e0535 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -55,7 +55,6 @@ public static void createClients() throws Exception { @Before public void setupTests() { resource = "users/" + UUID.randomUUID().toString().substring(0, 8); - System.out.println(resource); } @AfterClass @@ -134,7 +133,8 @@ public void testHttpJson_getIamPolicy() { httpjsonClient.setIamPolicy(policyRequest); Policy policy = - httpjsonClient.getIamPolicy(GetIamPolicyRequest.newBuilder().setResource(resource).build()); + httpjsonClient.getIamPolicy( + GetIamPolicyRequest.newBuilder().setResource(policyRequest.getResource()).build()); assertThat(policy).isEqualTo(DEFAULT_POLICY); } From 6272824201204841060ece22ca37e953c978e893 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 14:54:01 -0400 Subject: [PATCH 10/26] chore: run mvn clean before showcase tests --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fccf60117f..c6711b4a73 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -178,7 +178,7 @@ jobs: - run: mvn -version - name: Install Maven modules run: | - mvn install -B -ntp -DskipTests -Dclirr.skip -Dcheckstyle.skip + mvn clean install -B -ntp -DskipTests -Dclirr.skip -Dcheckstyle.skip - name: Java Linter working-directory: showcase run: | @@ -203,7 +203,7 @@ jobs: - name: Showcase integration tests working-directory: showcase run: | - mvn verify \ + mvn clean verify \ -P enable-integration-tests \ --batch-mode \ --no-transfer-progress From 39d3fe38160d2806cbbba248dabebb907e1815d7 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 15:04:55 -0400 Subject: [PATCH 11/26] chore: Attempt again with cache deleted --- .github/workflows/ci.yaml | 4 ++-- .../src/test/java/com/google/showcase/v1beta1/it/ITIam.java | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c6711b4a73..fccf60117f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -178,7 +178,7 @@ jobs: - run: mvn -version - name: Install Maven modules run: | - mvn clean install -B -ntp -DskipTests -Dclirr.skip -Dcheckstyle.skip + mvn install -B -ntp -DskipTests -Dclirr.skip -Dcheckstyle.skip - name: Java Linter working-directory: showcase run: | @@ -203,7 +203,7 @@ jobs: - name: Showcase integration tests working-directory: showcase run: | - mvn clean verify \ + mvn verify \ -P enable-integration-tests \ --batch-mode \ --no-transfer-progress diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index 25369e0535..f07b5df21e 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -133,8 +133,7 @@ public void testHttpJson_getIamPolicy() { httpjsonClient.setIamPolicy(policyRequest); Policy policy = - httpjsonClient.getIamPolicy( - GetIamPolicyRequest.newBuilder().setResource(policyRequest.getResource()).build()); + httpjsonClient.getIamPolicy(GetIamPolicyRequest.newBuilder().setResource(resource).build()); assertThat(policy).isEqualTo(DEFAULT_POLICY); } From c02c9efdf42cdf3a86b9f248f14d661d18fafb49 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 15:26:24 -0400 Subject: [PATCH 12/26] chore: Add logging for test --- .../src/test/java/com/google/showcase/v1beta1/it/ITIam.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index f07b5df21e..03f62dd2ca 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -130,11 +130,13 @@ public void testGrpc_getIamPolicy() { public void testHttpJson_getIamPolicy() { SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); - httpjsonClient.setIamPolicy(policyRequest); + Policy setIamPolicy = httpjsonClient.setIamPolicy(policyRequest); + System.out.println(setIamPolicy.getBindingsList() + " " + resource); Policy policy = httpjsonClient.getIamPolicy(GetIamPolicyRequest.newBuilder().setResource(resource).build()); assertThat(policy).isEqualTo(DEFAULT_POLICY); + System.out.println(resource); } @Test From a1655456b832420db0f5bb16962c5222c0588fb9 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 15:56:56 -0400 Subject: [PATCH 13/26] chore: Sleep for 1s --- .../src/test/java/com/google/showcase/v1beta1/it/ITIam.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index 03f62dd2ca..19c58b25c2 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -127,12 +127,14 @@ public void testGrpc_getIamPolicy() { } @Test - public void testHttpJson_getIamPolicy() { + public void testHttpJson_getIamPolicy() throws InterruptedException { SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); Policy setIamPolicy = httpjsonClient.setIamPolicy(policyRequest); System.out.println(setIamPolicy.getBindingsList() + " " + resource); + Thread.sleep(1000); + Policy policy = httpjsonClient.getIamPolicy(GetIamPolicyRequest.newBuilder().setResource(resource).build()); assertThat(policy).isEqualTo(DEFAULT_POLICY); From c119191bc1f320eff6d58462030253166e8b75b4 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 16:14:38 -0400 Subject: [PATCH 14/26] chore: Use resource from setPolicyRequest --- .../com/google/showcase/v1beta1/it/ITIam.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index 19c58b25c2..8c2f914884 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -122,23 +122,21 @@ public void testGrpc_getIamPolicy() { grpcClient.setIamPolicy(policyRequest); Policy policy = - grpcClient.getIamPolicy(GetIamPolicyRequest.newBuilder().setResource(resource).build()); + grpcClient.getIamPolicy( + GetIamPolicyRequest.newBuilder().setResource(policyRequest.getResource()).build()); assertThat(policy).isEqualTo(DEFAULT_POLICY); } @Test - public void testHttpJson_getIamPolicy() throws InterruptedException { + public void testHttpJson_getIamPolicy() { SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); - Policy setIamPolicy = httpjsonClient.setIamPolicy(policyRequest); - System.out.println(setIamPolicy.getBindingsList() + " " + resource); - - Thread.sleep(1000); + httpjsonClient.setIamPolicy(policyRequest); Policy policy = - httpjsonClient.getIamPolicy(GetIamPolicyRequest.newBuilder().setResource(resource).build()); + httpjsonClient.getIamPolicy( + GetIamPolicyRequest.newBuilder().setResource(policyRequest.getResource()).build()); assertThat(policy).isEqualTo(DEFAULT_POLICY); - System.out.println(resource); } @Test @@ -182,7 +180,7 @@ public void testGrpc_testIamPermissions() { TestIamPermissionsResponse testIamPermissionsResponse = grpcClient.testIamPermissions( TestIamPermissionsRequest.newBuilder() - .setResource(resource) + .setResource(policyRequest.getResource()) .addAllPermissions(permissions) .build()); assertThat(testIamPermissionsResponse.getPermissionsList()) @@ -198,7 +196,7 @@ public void testHttpJson_testIamPermissions() { TestIamPermissionsResponse testIamPermissionsResponse = httpjsonClient.testIamPermissions( TestIamPermissionsRequest.newBuilder() - .setResource(resource) + .setResource(policyRequest.getResource()) .addAllPermissions(permissions) .build()); assertThat(testIamPermissionsResponse.getPermissionsList()) From d1ce001cd66580067fa94b660ee0704dfbfdd787 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 17:02:45 -0400 Subject: [PATCH 15/26] chore: Ignore failing HttpJson test for now --- .../src/test/java/com/google/showcase/v1beta1/it/ITIam.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index 8c2f914884..c2285a2151 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -35,6 +35,7 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; public class ITIam { @@ -127,6 +128,7 @@ public void testGrpc_getIamPolicy() { assertThat(policy).isEqualTo(DEFAULT_POLICY); } + @Ignore @Test public void testHttpJson_getIamPolicy() { SetIamPolicyRequest policyRequest = From 42f19562551984e8446a359ec8f6c52c2929a558 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 17:40:53 -0400 Subject: [PATCH 16/26] chore: Un-ignore test --- .../src/test/java/com/google/showcase/v1beta1/it/ITIam.java | 1 - 1 file changed, 1 deletion(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index c2285a2151..86d61e1387 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -128,7 +128,6 @@ public void testGrpc_getIamPolicy() { assertThat(policy).isEqualTo(DEFAULT_POLICY); } - @Ignore @Test public void testHttpJson_getIamPolicy() { SetIamPolicyRequest policyRequest = From 3a6c3b3e9a6a30c8c1f092e98722eeac78673b5b Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 17:43:34 -0400 Subject: [PATCH 17/26] chore: Fix lint issues --- .../src/test/java/com/google/showcase/v1beta1/it/ITIam.java | 1 - 1 file changed, 1 deletion(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index 86d61e1387..8c2f914884 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -35,7 +35,6 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; public class ITIam { From d150fdb8c4975dd072fa9e01e61611b80b935469 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 17:58:57 -0400 Subject: [PATCH 18/26] chore: Test with rooms/ prefix --- .../src/test/java/com/google/showcase/v1beta1/it/ITIam.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index 8c2f914884..428bdef4d9 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -54,7 +54,7 @@ public static void createClients() throws Exception { @Before public void setupTests() { - resource = "users/" + UUID.randomUUID().toString().substring(0, 8); + resource = "rooms/" + UUID.randomUUID().toString().substring(0, 8); } @AfterClass From 6652d000e0756cd8edb7bd50839261e1772d5be0 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 19:13:06 -0400 Subject: [PATCH 19/26] chore: Use Identity client for Users --- .../com/google/showcase/v1beta1/it/ITIam.java | 56 ++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index 428bdef4d9..0bd2be7348 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -27,7 +27,7 @@ import com.google.iam.v1.SetIamPolicyRequest; import com.google.iam.v1.TestIamPermissionsRequest; import com.google.iam.v1.TestIamPermissionsResponse; -import com.google.showcase.v1beta1.EchoClient; +import com.google.showcase.v1beta1.IdentityClient; import com.google.showcase.v1beta1.it.util.TestClientInitializer; import java.util.List; import java.util.UUID; @@ -42,19 +42,19 @@ public class ITIam { Policy.newBuilder() .addBindings(Binding.newBuilder().setRole("foo.editor").addMembers("allUsers")) .build(); - private static EchoClient grpcClient; - private static EchoClient httpjsonClient; - private String resource; + private static IdentityClient grpcClient; + private static IdentityClient httpjsonClient; + private String resourceName; @BeforeClass public static void createClients() throws Exception { - grpcClient = TestClientInitializer.createGrpcEchoClient(); - httpjsonClient = TestClientInitializer.createHttpJsonEchoClient(); + grpcClient = TestClientInitializer.createGrpcIdentityClient(); + httpjsonClient = TestClientInitializer.createHttpJsonIdentityClient(); } @Before public void setupTests() { - resource = "rooms/" + UUID.randomUUID().toString().substring(0, 8); + resourceName = "users/" + UUID.randomUUID().toString().substring(0, 8); } @AfterClass @@ -70,7 +70,10 @@ public static void destroyClients() throws InterruptedException { @Test public void testGrpc_setIamPolicy() { SetIamPolicyRequest policyRequest = - SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); + SetIamPolicyRequest.newBuilder() + .setPolicy(DEFAULT_POLICY) + .setResource(resourceName) + .build(); Policy policy = grpcClient.setIamPolicy(policyRequest); assertThat(policy).isEqualTo(DEFAULT_POLICY); } @@ -78,7 +81,10 @@ public void testGrpc_setIamPolicy() { @Test public void testHttpJson_setIamPolicy() { SetIamPolicyRequest policyRequest = - SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); + SetIamPolicyRequest.newBuilder() + .setPolicy(DEFAULT_POLICY) + .setResource(resourceName) + .build(); Policy policy = httpjsonClient.setIamPolicy(policyRequest); assertThat(policy).isEqualTo(DEFAULT_POLICY); } @@ -103,7 +109,7 @@ public void testGrpc_setIamPolicy_missingPolicy() { InvalidArgumentException.class, () -> grpcClient.setIamPolicy( - SetIamPolicyRequest.newBuilder().setResource(resource).build())); + SetIamPolicyRequest.newBuilder().setResource(resourceName).build())); } @Test @@ -112,13 +118,16 @@ public void testHttpJson_setIamPolicy_missingPolicy() { InvalidArgumentException.class, () -> httpjsonClient.setIamPolicy( - SetIamPolicyRequest.newBuilder().setResource(resource).build())); + SetIamPolicyRequest.newBuilder().setResource(resourceName).build())); } @Test public void testGrpc_getIamPolicy() { SetIamPolicyRequest policyRequest = - SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); + SetIamPolicyRequest.newBuilder() + .setPolicy(DEFAULT_POLICY) + .setResource(resourceName) + .build(); grpcClient.setIamPolicy(policyRequest); Policy policy = @@ -130,7 +139,10 @@ public void testGrpc_getIamPolicy() { @Test public void testHttpJson_getIamPolicy() { SetIamPolicyRequest policyRequest = - SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); + SetIamPolicyRequest.newBuilder() + .setPolicy(DEFAULT_POLICY) + .setResource(resourceName) + .build(); httpjsonClient.setIamPolicy(policyRequest); Policy policy = @@ -145,7 +157,7 @@ public void testGrpc_getIamPolicy_doesNotExist() { NotFoundException.class, () -> grpcClient.getIamPolicy( - GetIamPolicyRequest.newBuilder().setResource(resource).build())); + GetIamPolicyRequest.newBuilder().setResource(resourceName).build())); } @Test @@ -154,7 +166,7 @@ public void testHttpJson_getIamPolicy_doesNotExist() { NotFoundException.class, () -> httpjsonClient.getIamPolicy( - GetIamPolicyRequest.newBuilder().setResource(resource).build())); + GetIamPolicyRequest.newBuilder().setResource(resourceName).build())); } @Test @@ -174,7 +186,10 @@ public void testHttpJson_getIamPolicy_missingResource() { @Test public void testGrpc_testIamPermissions() { SetIamPolicyRequest policyRequest = - SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); + SetIamPolicyRequest.newBuilder() + .setPolicy(DEFAULT_POLICY) + .setResource(resourceName) + .build(); grpcClient.setIamPolicy(policyRequest); List permissions = ImmutableList.of("foo.create"); TestIamPermissionsResponse testIamPermissionsResponse = @@ -190,7 +205,10 @@ public void testGrpc_testIamPermissions() { @Test public void testHttpJson_testIamPermissions() { SetIamPolicyRequest policyRequest = - SetIamPolicyRequest.newBuilder().setPolicy(DEFAULT_POLICY).setResource(resource).build(); + SetIamPolicyRequest.newBuilder() + .setPolicy(DEFAULT_POLICY) + .setResource(resourceName) + .build(); httpjsonClient.setIamPolicy(policyRequest); List permissions = ImmutableList.of("foo.create"); TestIamPermissionsResponse testIamPermissionsResponse = @@ -209,7 +227,7 @@ public void testGrpc_testIamPermissions_doesNotExist() { NotFoundException.class, () -> grpcClient.testIamPermissions( - TestIamPermissionsRequest.newBuilder().setResource(resource).build())); + TestIamPermissionsRequest.newBuilder().setResource(resourceName).build())); } @Test @@ -218,7 +236,7 @@ public void testHttpJson_testIamPermissions_doesNotExist() { NotFoundException.class, () -> httpjsonClient.testIamPermissions( - TestIamPermissionsRequest.newBuilder().setResource(resource).build())); + TestIamPermissionsRequest.newBuilder().setResource(resourceName).build())); } @Test From 0c7cb469e9ce80a5daf3751f4436bdd866df1dd0 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 20:09:56 -0400 Subject: [PATCH 20/26] chore: Create user resource to assign policy to --- .../com/google/showcase/v1beta1/it/ITIam.java | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index 0bd2be7348..dcaaf026ca 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -27,7 +27,9 @@ import com.google.iam.v1.SetIamPolicyRequest; import com.google.iam.v1.TestIamPermissionsRequest; import com.google.iam.v1.TestIamPermissionsResponse; +import com.google.showcase.v1beta1.CreateUserRequest; import com.google.showcase.v1beta1.IdentityClient; +import com.google.showcase.v1beta1.User; import com.google.showcase.v1beta1.it.util.TestClientInitializer; import java.util.List; import java.util.UUID; @@ -44,6 +46,7 @@ public class ITIam { .build(); private static IdentityClient grpcClient; private static IdentityClient httpjsonClient; + private String userId; private String resourceName; @BeforeClass @@ -54,7 +57,8 @@ public static void createClients() throws Exception { @Before public void setupTests() { - resourceName = "users/" + UUID.randomUUID().toString().substring(0, 8); + userId = UUID.randomUUID().toString().substring(0, 8); + resourceName = "users/" + userId; } @AfterClass @@ -69,6 +73,14 @@ public static void destroyClients() throws InterruptedException { @Test public void testGrpc_setIamPolicy() { + grpcClient.createUser( + CreateUserRequest.newBuilder() + .setUser( + User.newBuilder() + .setName(userId) + .setDisplayName(userId) + .setEmail(userId + "@google.com")) + .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) @@ -80,6 +92,14 @@ public void testGrpc_setIamPolicy() { @Test public void testHttpJson_setIamPolicy() { + httpjsonClient.createUser( + CreateUserRequest.newBuilder() + .setUser( + User.newBuilder() + .setName(userId) + .setDisplayName(userId) + .setEmail(userId + "@google.com")) + .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) @@ -123,6 +143,14 @@ public void testHttpJson_setIamPolicy_missingPolicy() { @Test public void testGrpc_getIamPolicy() { + grpcClient.createUser( + CreateUserRequest.newBuilder() + .setUser( + User.newBuilder() + .setName(userId) + .setDisplayName(userId) + .setEmail(userId + "@google.com")) + .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) @@ -138,6 +166,14 @@ public void testGrpc_getIamPolicy() { @Test public void testHttpJson_getIamPolicy() { + httpjsonClient.createUser( + CreateUserRequest.newBuilder() + .setUser( + User.newBuilder() + .setName(userId) + .setDisplayName(userId) + .setEmail(userId + "@google.com")) + .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) @@ -185,6 +221,14 @@ public void testHttpJson_getIamPolicy_missingResource() { @Test public void testGrpc_testIamPermissions() { + grpcClient.createUser( + CreateUserRequest.newBuilder() + .setUser( + User.newBuilder() + .setName(userId) + .setDisplayName(userId) + .setEmail(userId + "@google.com")) + .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) @@ -204,6 +248,14 @@ public void testGrpc_testIamPermissions() { @Test public void testHttpJson_testIamPermissions() { + httpjsonClient.createUser( + CreateUserRequest.newBuilder() + .setUser( + User.newBuilder() + .setName(userId) + .setDisplayName(userId) + .setEmail(userId + "@google.com")) + .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) From 0c4222fbf9088f9ca0759f3b0572d9ab37601719 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 21 Jun 2023 20:23:20 -0400 Subject: [PATCH 21/26] chore: Use user's name as resource id --- .../com/google/showcase/v1beta1/it/ITIam.java | 81 +++++++------------ 1 file changed, 31 insertions(+), 50 deletions(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index dcaaf026ca..f28c85e371 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -73,18 +73,15 @@ public static void destroyClients() throws InterruptedException { @Test public void testGrpc_setIamPolicy() { - grpcClient.createUser( - CreateUserRequest.newBuilder() - .setUser( - User.newBuilder() - .setName(userId) - .setDisplayName(userId) - .setEmail(userId + "@google.com")) - .build()); + User user = + grpcClient.createUser( + CreateUserRequest.newBuilder() + .setUser(User.newBuilder().setDisplayName(userId).setEmail(userId + "@google.com")) + .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) - .setResource(resourceName) + .setResource(user.getName()) .build(); Policy policy = grpcClient.setIamPolicy(policyRequest); assertThat(policy).isEqualTo(DEFAULT_POLICY); @@ -92,18 +89,15 @@ public void testGrpc_setIamPolicy() { @Test public void testHttpJson_setIamPolicy() { - httpjsonClient.createUser( - CreateUserRequest.newBuilder() - .setUser( - User.newBuilder() - .setName(userId) - .setDisplayName(userId) - .setEmail(userId + "@google.com")) - .build()); + User user = + httpjsonClient.createUser( + CreateUserRequest.newBuilder() + .setUser(User.newBuilder().setDisplayName(userId).setEmail(userId + "@google.com")) + .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) - .setResource(resourceName) + .setResource(user.getName()) .build(); Policy policy = httpjsonClient.setIamPolicy(policyRequest); assertThat(policy).isEqualTo(DEFAULT_POLICY); @@ -143,18 +137,15 @@ public void testHttpJson_setIamPolicy_missingPolicy() { @Test public void testGrpc_getIamPolicy() { - grpcClient.createUser( - CreateUserRequest.newBuilder() - .setUser( - User.newBuilder() - .setName(userId) - .setDisplayName(userId) - .setEmail(userId + "@google.com")) - .build()); + User user = + grpcClient.createUser( + CreateUserRequest.newBuilder() + .setUser(User.newBuilder().setDisplayName(userId).setEmail(userId + "@google.com")) + .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) - .setResource(resourceName) + .setResource(user.getName()) .build(); grpcClient.setIamPolicy(policyRequest); @@ -166,18 +157,15 @@ public void testGrpc_getIamPolicy() { @Test public void testHttpJson_getIamPolicy() { - httpjsonClient.createUser( - CreateUserRequest.newBuilder() - .setUser( - User.newBuilder() - .setName(userId) - .setDisplayName(userId) - .setEmail(userId + "@google.com")) - .build()); + User user = + httpjsonClient.createUser( + CreateUserRequest.newBuilder() + .setUser(User.newBuilder().setDisplayName(userId).setEmail(userId + "@google.com")) + .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) - .setResource(resourceName) + .setResource(user.getName()) .build(); httpjsonClient.setIamPolicy(policyRequest); @@ -223,11 +211,7 @@ public void testHttpJson_getIamPolicy_missingResource() { public void testGrpc_testIamPermissions() { grpcClient.createUser( CreateUserRequest.newBuilder() - .setUser( - User.newBuilder() - .setName(userId) - .setDisplayName(userId) - .setEmail(userId + "@google.com")) + .setUser(User.newBuilder().setDisplayName(userId).setEmail(userId + "@google.com")) .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() @@ -248,18 +232,15 @@ public void testGrpc_testIamPermissions() { @Test public void testHttpJson_testIamPermissions() { - httpjsonClient.createUser( - CreateUserRequest.newBuilder() - .setUser( - User.newBuilder() - .setName(userId) - .setDisplayName(userId) - .setEmail(userId + "@google.com")) - .build()); + User user = + httpjsonClient.createUser( + CreateUserRequest.newBuilder() + .setUser(User.newBuilder().setDisplayName(userId).setEmail(userId + "@google.com")) + .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) - .setResource(resourceName) + .setResource(user.getName()) .build(); httpjsonClient.setIamPolicy(policyRequest); List permissions = ImmutableList.of("foo.create"); From adfad68e81edcd3379074fbe94b6116b3cf764f9 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Thu, 22 Jun 2023 11:27:49 -0400 Subject: [PATCH 22/26] chore: Change resource name before each test --- .../com/google/showcase/v1beta1/it/ITIam.java | 45 +++---------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index f28c85e371..0bd2be7348 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -27,9 +27,7 @@ import com.google.iam.v1.SetIamPolicyRequest; import com.google.iam.v1.TestIamPermissionsRequest; import com.google.iam.v1.TestIamPermissionsResponse; -import com.google.showcase.v1beta1.CreateUserRequest; import com.google.showcase.v1beta1.IdentityClient; -import com.google.showcase.v1beta1.User; import com.google.showcase.v1beta1.it.util.TestClientInitializer; import java.util.List; import java.util.UUID; @@ -46,7 +44,6 @@ public class ITIam { .build(); private static IdentityClient grpcClient; private static IdentityClient httpjsonClient; - private String userId; private String resourceName; @BeforeClass @@ -57,8 +54,7 @@ public static void createClients() throws Exception { @Before public void setupTests() { - userId = UUID.randomUUID().toString().substring(0, 8); - resourceName = "users/" + userId; + resourceName = "users/" + UUID.randomUUID().toString().substring(0, 8); } @AfterClass @@ -73,15 +69,10 @@ public static void destroyClients() throws InterruptedException { @Test public void testGrpc_setIamPolicy() { - User user = - grpcClient.createUser( - CreateUserRequest.newBuilder() - .setUser(User.newBuilder().setDisplayName(userId).setEmail(userId + "@google.com")) - .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) - .setResource(user.getName()) + .setResource(resourceName) .build(); Policy policy = grpcClient.setIamPolicy(policyRequest); assertThat(policy).isEqualTo(DEFAULT_POLICY); @@ -89,15 +80,10 @@ public void testGrpc_setIamPolicy() { @Test public void testHttpJson_setIamPolicy() { - User user = - httpjsonClient.createUser( - CreateUserRequest.newBuilder() - .setUser(User.newBuilder().setDisplayName(userId).setEmail(userId + "@google.com")) - .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) - .setResource(user.getName()) + .setResource(resourceName) .build(); Policy policy = httpjsonClient.setIamPolicy(policyRequest); assertThat(policy).isEqualTo(DEFAULT_POLICY); @@ -137,15 +123,10 @@ public void testHttpJson_setIamPolicy_missingPolicy() { @Test public void testGrpc_getIamPolicy() { - User user = - grpcClient.createUser( - CreateUserRequest.newBuilder() - .setUser(User.newBuilder().setDisplayName(userId).setEmail(userId + "@google.com")) - .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) - .setResource(user.getName()) + .setResource(resourceName) .build(); grpcClient.setIamPolicy(policyRequest); @@ -157,15 +138,10 @@ public void testGrpc_getIamPolicy() { @Test public void testHttpJson_getIamPolicy() { - User user = - httpjsonClient.createUser( - CreateUserRequest.newBuilder() - .setUser(User.newBuilder().setDisplayName(userId).setEmail(userId + "@google.com")) - .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) - .setResource(user.getName()) + .setResource(resourceName) .build(); httpjsonClient.setIamPolicy(policyRequest); @@ -209,10 +185,6 @@ public void testHttpJson_getIamPolicy_missingResource() { @Test public void testGrpc_testIamPermissions() { - grpcClient.createUser( - CreateUserRequest.newBuilder() - .setUser(User.newBuilder().setDisplayName(userId).setEmail(userId + "@google.com")) - .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) @@ -232,15 +204,10 @@ public void testGrpc_testIamPermissions() { @Test public void testHttpJson_testIamPermissions() { - User user = - httpjsonClient.createUser( - CreateUserRequest.newBuilder() - .setUser(User.newBuilder().setDisplayName(userId).setEmail(userId + "@google.com")) - .build()); SetIamPolicyRequest policyRequest = SetIamPolicyRequest.newBuilder() .setPolicy(DEFAULT_POLICY) - .setResource(user.getName()) + .setResource(resourceName) .build(); httpjsonClient.setIamPolicy(policyRequest); List permissions = ImmutableList.of("foo.create"); From 5346d43407775268f21cf17c26410c85c8fe8189 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 5 Jul 2023 17:08:51 -0400 Subject: [PATCH 23/26] chore: Add iam-grpc in pom --- showcase/gapic-showcase/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/showcase/gapic-showcase/pom.xml b/showcase/gapic-showcase/pom.xml index f4adf3e0c7..9fe7908f3c 100644 --- a/showcase/gapic-showcase/pom.xml +++ b/showcase/gapic-showcase/pom.xml @@ -237,5 +237,10 @@ testlib test + + com.google.api.grpc + grpc-google-iam-v1 + test + From 1682e0acbb1e477a22048dc4e171b096a41b09f8 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 5 Jul 2023 17:25:25 -0400 Subject: [PATCH 24/26] chore: Resolve sonar issues --- .../com/google/showcase/v1beta1/it/ITIam.java | 71 +++++++++---------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index 0bd2be7348..dcb338fd1a 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -91,34 +91,32 @@ public void testHttpJson_setIamPolicy() { @Test public void testGrpc_setIamPolicy_missingResource() { + SetIamPolicyRequest setIamPolicyRequest = SetIamPolicyRequest.newBuilder().build(); assertThrows( - InvalidArgumentException.class, - () -> grpcClient.setIamPolicy(SetIamPolicyRequest.newBuilder().build())); + InvalidArgumentException.class, () -> grpcClient.setIamPolicy(setIamPolicyRequest)); } @Test public void testHttpJson_setIamPolicy_missingResource() { + SetIamPolicyRequest setIamPolicyRequest = SetIamPolicyRequest.newBuilder().build(); assertThrows( - InvalidArgumentException.class, - () -> httpjsonClient.setIamPolicy(SetIamPolicyRequest.newBuilder().build())); + InvalidArgumentException.class, () -> httpjsonClient.setIamPolicy(setIamPolicyRequest)); } @Test public void testGrpc_setIamPolicy_missingPolicy() { + SetIamPolicyRequest setIamPolicyRequest = + SetIamPolicyRequest.newBuilder().setResource(resourceName).build(); assertThrows( - InvalidArgumentException.class, - () -> - grpcClient.setIamPolicy( - SetIamPolicyRequest.newBuilder().setResource(resourceName).build())); + InvalidArgumentException.class, () -> grpcClient.setIamPolicy(setIamPolicyRequest)); } @Test public void testHttpJson_setIamPolicy_missingPolicy() { + SetIamPolicyRequest setIamPolicyRequest = + SetIamPolicyRequest.newBuilder().setResource(resourceName).build(); assertThrows( - InvalidArgumentException.class, - () -> - httpjsonClient.setIamPolicy( - SetIamPolicyRequest.newBuilder().setResource(resourceName).build())); + InvalidArgumentException.class, () -> httpjsonClient.setIamPolicy(setIamPolicyRequest)); } @Test @@ -153,34 +151,30 @@ public void testHttpJson_getIamPolicy() { @Test public void testGrpc_getIamPolicy_doesNotExist() { - assertThrows( - NotFoundException.class, - () -> - grpcClient.getIamPolicy( - GetIamPolicyRequest.newBuilder().setResource(resourceName).build())); + GetIamPolicyRequest getIamPolicyRequest = + GetIamPolicyRequest.newBuilder().setResource(resourceName).build(); + assertThrows(NotFoundException.class, () -> grpcClient.getIamPolicy(getIamPolicyRequest)); } @Test public void testHttpJson_getIamPolicy_doesNotExist() { - assertThrows( - NotFoundException.class, - () -> - httpjsonClient.getIamPolicy( - GetIamPolicyRequest.newBuilder().setResource(resourceName).build())); + GetIamPolicyRequest getIamPolicyRequest = + GetIamPolicyRequest.newBuilder().setResource(resourceName).build(); + assertThrows(NotFoundException.class, () -> httpjsonClient.getIamPolicy(getIamPolicyRequest)); } @Test public void testGrpc_getIamPolicy_missingResource() { + GetIamPolicyRequest getIamPolicyRequest = GetIamPolicyRequest.newBuilder().build(); assertThrows( - InvalidArgumentException.class, - () -> grpcClient.getIamPolicy(GetIamPolicyRequest.newBuilder().build())); + InvalidArgumentException.class, () -> grpcClient.getIamPolicy(getIamPolicyRequest)); } @Test public void testHttpJson_getIamPolicy_missingResource() { + GetIamPolicyRequest getIamPolicyRequest = GetIamPolicyRequest.newBuilder().build(); assertThrows( - InvalidArgumentException.class, - () -> httpjsonClient.getIamPolicy(GetIamPolicyRequest.newBuilder().build())); + InvalidArgumentException.class, () -> httpjsonClient.getIamPolicy(getIamPolicyRequest)); } @Test @@ -191,7 +185,7 @@ public void testGrpc_testIamPermissions() { .setResource(resourceName) .build(); grpcClient.setIamPolicy(policyRequest); - List permissions = ImmutableList.of("foo.create"); + List permissions = ImmutableList.of("foo.create", "foo.write"); TestIamPermissionsResponse testIamPermissionsResponse = grpcClient.testIamPermissions( TestIamPermissionsRequest.newBuilder() @@ -210,7 +204,7 @@ public void testHttpJson_testIamPermissions() { .setResource(resourceName) .build(); httpjsonClient.setIamPolicy(policyRequest); - List permissions = ImmutableList.of("foo.create"); + List permissions = ImmutableList.of("foo.create", "foo.write"); TestIamPermissionsResponse testIamPermissionsResponse = httpjsonClient.testIamPermissions( TestIamPermissionsRequest.newBuilder() @@ -223,33 +217,36 @@ public void testHttpJson_testIamPermissions() { @Test public void testGrpc_testIamPermissions_doesNotExist() { + TestIamPermissionsRequest testIamPermissionsRequest = + TestIamPermissionsRequest.newBuilder().setResource(resourceName).build(); assertThrows( - NotFoundException.class, - () -> - grpcClient.testIamPermissions( - TestIamPermissionsRequest.newBuilder().setResource(resourceName).build())); + NotFoundException.class, () -> grpcClient.testIamPermissions(testIamPermissionsRequest)); } @Test public void testHttpJson_testIamPermissions_doesNotExist() { + TestIamPermissionsRequest testIamPermissionsRequest = + TestIamPermissionsRequest.newBuilder().setResource(resourceName).build(); assertThrows( NotFoundException.class, - () -> - httpjsonClient.testIamPermissions( - TestIamPermissionsRequest.newBuilder().setResource(resourceName).build())); + () -> httpjsonClient.testIamPermissions(testIamPermissionsRequest)); } @Test public void testGrpc_testIamPermissions_missingResource() { + TestIamPermissionsRequest testIamPermissionsRequest = + TestIamPermissionsRequest.newBuilder().build(); assertThrows( InvalidArgumentException.class, - () -> grpcClient.testIamPermissions(TestIamPermissionsRequest.newBuilder().build())); + () -> grpcClient.testIamPermissions(testIamPermissionsRequest)); } @Test public void testHttpJson_testIamPermissions_missingResource() { + TestIamPermissionsRequest testIamPermissionsRequest = + TestIamPermissionsRequest.newBuilder().build(); assertThrows( InvalidArgumentException.class, - () -> httpjsonClient.testIamPermissions(TestIamPermissionsRequest.newBuilder().build())); + () -> httpjsonClient.testIamPermissions(testIamPermissionsRequest)); } } From a3fb65ba2b4421c63f4181b0ed244467bce4b18a Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Wed, 5 Jul 2023 17:43:11 -0400 Subject: [PATCH 25/26] chore: Add comment for testIamPolicy --- .../src/test/java/com/google/showcase/v1beta1/it/ITIam.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index dcb338fd1a..9786d2a403 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -192,6 +192,8 @@ public void testGrpc_testIamPermissions() { .setResource(policyRequest.getResource()) .addAllPermissions(permissions) .build()); + // Showcase server will simply echo the request's Permissions List back + // if the resource exists and contains a policy assertThat(testIamPermissionsResponse.getPermissionsList()) .containsExactlyElementsIn(permissions); } @@ -211,6 +213,8 @@ public void testHttpJson_testIamPermissions() { .setResource(policyRequest.getResource()) .addAllPermissions(permissions) .build()); + // Showcase server will simply echo the request's Permissions List back + // if the resource exists and contains a policy assertThat(testIamPermissionsResponse.getPermissionsList()) .containsExactlyElementsIn(permissions); } From bf336276c86ba8ecc631e132847f4ff8b67a7cf9 Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Fri, 7 Jul 2023 13:28:40 -0400 Subject: [PATCH 26/26] chore: Address PR comments --- .../com/google/showcase/v1beta1/it/ITIam.java | 96 ++----------------- 1 file changed, 10 insertions(+), 86 deletions(-) diff --git a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java index 9786d2a403..181608571a 100644 --- a/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java +++ b/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITIam.java @@ -19,7 +19,6 @@ import static org.junit.Assert.assertThrows; import com.google.api.gax.rpc.InvalidArgumentException; -import com.google.api.gax.rpc.NotFoundException; import com.google.common.collect.ImmutableList; import com.google.iam.v1.Binding; import com.google.iam.v1.GetIamPolicyRequest; @@ -89,36 +88,6 @@ public void testHttpJson_setIamPolicy() { assertThat(policy).isEqualTo(DEFAULT_POLICY); } - @Test - public void testGrpc_setIamPolicy_missingResource() { - SetIamPolicyRequest setIamPolicyRequest = SetIamPolicyRequest.newBuilder().build(); - assertThrows( - InvalidArgumentException.class, () -> grpcClient.setIamPolicy(setIamPolicyRequest)); - } - - @Test - public void testHttpJson_setIamPolicy_missingResource() { - SetIamPolicyRequest setIamPolicyRequest = SetIamPolicyRequest.newBuilder().build(); - assertThrows( - InvalidArgumentException.class, () -> httpjsonClient.setIamPolicy(setIamPolicyRequest)); - } - - @Test - public void testGrpc_setIamPolicy_missingPolicy() { - SetIamPolicyRequest setIamPolicyRequest = - SetIamPolicyRequest.newBuilder().setResource(resourceName).build(); - assertThrows( - InvalidArgumentException.class, () -> grpcClient.setIamPolicy(setIamPolicyRequest)); - } - - @Test - public void testHttpJson_setIamPolicy_missingPolicy() { - SetIamPolicyRequest setIamPolicyRequest = - SetIamPolicyRequest.newBuilder().setResource(resourceName).build(); - assertThrows( - InvalidArgumentException.class, () -> httpjsonClient.setIamPolicy(setIamPolicyRequest)); - } - @Test public void testGrpc_getIamPolicy() { SetIamPolicyRequest policyRequest = @@ -149,34 +118,6 @@ public void testHttpJson_getIamPolicy() { assertThat(policy).isEqualTo(DEFAULT_POLICY); } - @Test - public void testGrpc_getIamPolicy_doesNotExist() { - GetIamPolicyRequest getIamPolicyRequest = - GetIamPolicyRequest.newBuilder().setResource(resourceName).build(); - assertThrows(NotFoundException.class, () -> grpcClient.getIamPolicy(getIamPolicyRequest)); - } - - @Test - public void testHttpJson_getIamPolicy_doesNotExist() { - GetIamPolicyRequest getIamPolicyRequest = - GetIamPolicyRequest.newBuilder().setResource(resourceName).build(); - assertThrows(NotFoundException.class, () -> httpjsonClient.getIamPolicy(getIamPolicyRequest)); - } - - @Test - public void testGrpc_getIamPolicy_missingResource() { - GetIamPolicyRequest getIamPolicyRequest = GetIamPolicyRequest.newBuilder().build(); - assertThrows( - InvalidArgumentException.class, () -> grpcClient.getIamPolicy(getIamPolicyRequest)); - } - - @Test - public void testHttpJson_getIamPolicy_missingResource() { - GetIamPolicyRequest getIamPolicyRequest = GetIamPolicyRequest.newBuilder().build(); - assertThrows( - InvalidArgumentException.class, () -> httpjsonClient.getIamPolicy(getIamPolicyRequest)); - } - @Test public void testGrpc_testIamPermissions() { SetIamPolicyRequest policyRequest = @@ -219,38 +160,21 @@ public void testHttpJson_testIamPermissions() { .containsExactlyElementsIn(permissions); } + // The tests below simply assert that an exception is being thrown for an invalid request + // in both transports. Showcase's IAM backend service will throw a few exceptions for a few + // cases, and we simply assert that an exception has been thrown for a single case with a single + // RPC (No resource in the request for SetIamPolicy's RPC). @Test - public void testGrpc_testIamPermissions_doesNotExist() { - TestIamPermissionsRequest testIamPermissionsRequest = - TestIamPermissionsRequest.newBuilder().setResource(resourceName).build(); - assertThrows( - NotFoundException.class, () -> grpcClient.testIamPermissions(testIamPermissionsRequest)); - } - - @Test - public void testHttpJson_testIamPermissions_doesNotExist() { - TestIamPermissionsRequest testIamPermissionsRequest = - TestIamPermissionsRequest.newBuilder().setResource(resourceName).build(); - assertThrows( - NotFoundException.class, - () -> httpjsonClient.testIamPermissions(testIamPermissionsRequest)); - } - - @Test - public void testGrpc_testIamPermissions_missingResource() { - TestIamPermissionsRequest testIamPermissionsRequest = - TestIamPermissionsRequest.newBuilder().build(); + public void testGrpc_iamThrowsException() { + SetIamPolicyRequest setIamPolicyRequest = SetIamPolicyRequest.newBuilder().build(); assertThrows( - InvalidArgumentException.class, - () -> grpcClient.testIamPermissions(testIamPermissionsRequest)); + InvalidArgumentException.class, () -> grpcClient.setIamPolicy(setIamPolicyRequest)); } @Test - public void testHttpJson_testIamPermissions_missingResource() { - TestIamPermissionsRequest testIamPermissionsRequest = - TestIamPermissionsRequest.newBuilder().build(); + public void testHttpJson_iamThrowsException() { + SetIamPolicyRequest setIamPolicyRequest = SetIamPolicyRequest.newBuilder().build(); assertThrows( - InvalidArgumentException.class, - () -> httpjsonClient.testIamPermissions(testIamPermissionsRequest)); + InvalidArgumentException.class, () -> httpjsonClient.setIamPolicy(setIamPolicyRequest)); } }