diff --git a/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/IamCheckerClient.java b/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/IamCheckerClient.java
index ecd49ee9c482..059d02b4cf91 100644
--- a/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/IamCheckerClient.java
+++ b/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/IamCheckerClient.java
@@ -93,6 +93,20 @@
* IamCheckerClient iamCheckerClient = IamCheckerClient.create(iamCheckerSettings);
* }
*
+ * To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
+ * the wire:
+ *
+ *
{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * IamCheckerSettings iamCheckerSettings =
+ * IamCheckerSettings.newBuilder()
+ * .setTransportChannelProvider(
+ * IamCheckerSettings.defaultHttpJsonTransportProviderBuilder().build())
+ * .build();
+ * IamCheckerClient iamCheckerClient = IamCheckerClient.create(iamCheckerSettings);
+ * }
+ *
* Please refer to the GitHub repository's samples for more quickstart code snippets.
*/
@Generated("by gapic-generator-java")
diff --git a/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/IamCheckerSettings.java b/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/IamCheckerSettings.java
index 009a24fc8102..b81dd366cb38 100644
--- a/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/IamCheckerSettings.java
+++ b/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/IamCheckerSettings.java
@@ -21,6 +21,7 @@
import com.google.api.gax.core.GoogleCredentialsProvider;
import com.google.api.gax.core.InstantiatingExecutorProvider;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
+import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.ClientSettings;
@@ -98,11 +99,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
return IamCheckerStubSettings.defaultCredentialsProviderBuilder();
}
- /** Returns a builder for the default ChannelProvider for this service. */
+ /** Returns a builder for the default gRPC ChannelProvider for this service. */
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
return IamCheckerStubSettings.defaultGrpcTransportProviderBuilder();
}
+ /** Returns a builder for the default REST ChannelProvider for this service. */
+ @BetaApi
+ public static InstantiatingHttpJsonChannelProvider.Builder
+ defaultHttpJsonTransportProviderBuilder() {
+ return IamCheckerStubSettings.defaultHttpJsonTransportProviderBuilder();
+ }
+
public static TransportChannelProvider defaultTransportChannelProvider() {
return IamCheckerStubSettings.defaultTransportChannelProvider();
}
@@ -112,11 +120,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
return IamCheckerStubSettings.defaultApiClientHeaderProviderBuilder();
}
- /** Returns a new builder for this class. */
+ /** Returns a new gRPC builder for this class. */
public static Builder newBuilder() {
return Builder.createDefault();
}
+ /** Returns a new REST builder for this class. */
+ @BetaApi
+ public static Builder newHttpJsonBuilder() {
+ return Builder.createHttpJsonDefault();
+ }
+
/** Returns a new builder for this class. */
public static Builder newBuilder(ClientContext clientContext) {
return new Builder(clientContext);
@@ -154,6 +168,11 @@ private static Builder createDefault() {
return new Builder(IamCheckerStubSettings.newBuilder());
}
+ @BetaApi
+ private static Builder createHttpJsonDefault() {
+ return new Builder(IamCheckerStubSettings.newHttpJsonBuilder());
+ }
+
public IamCheckerStubSettings.Builder getStubSettingsBuilder() {
return ((IamCheckerStubSettings.Builder) getStubSettings());
}
diff --git a/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/stub/HttpJsonIamCheckerCallableFactory.java b/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/stub/HttpJsonIamCheckerCallableFactory.java
new file mode 100644
index 000000000000..e4102d2b879d
--- /dev/null
+++ b/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/stub/HttpJsonIamCheckerCallableFactory.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2022 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.cloud.policytroubleshooter.v1.stub;
+
+import com.google.api.core.BetaApi;
+import com.google.api.gax.httpjson.HttpJsonCallSettings;
+import com.google.api.gax.httpjson.HttpJsonCallableFactory;
+import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable;
+import com.google.api.gax.httpjson.HttpJsonStubCallableFactory;
+import com.google.api.gax.httpjson.longrunning.stub.OperationsStub;
+import com.google.api.gax.rpc.BatchingCallSettings;
+import com.google.api.gax.rpc.ClientContext;
+import com.google.api.gax.rpc.OperationCallSettings;
+import com.google.api.gax.rpc.OperationCallable;
+import com.google.api.gax.rpc.PagedCallSettings;
+import com.google.api.gax.rpc.ServerStreamingCallSettings;
+import com.google.api.gax.rpc.ServerStreamingCallable;
+import com.google.api.gax.rpc.UnaryCallSettings;
+import com.google.api.gax.rpc.UnaryCallable;
+import com.google.longrunning.Operation;
+import javax.annotation.Generated;
+
+// AUTO-GENERATED DOCUMENTATION AND CLASS.
+/**
+ * REST callable factory implementation for the IamChecker service API.
+ *
+ *
This class is for advanced usage.
+ */
+@Generated("by gapic-generator-java")
+@BetaApi
+public class HttpJsonIamCheckerCallableFactory
+ implements HttpJsonStubCallableFactory {
+
+ @Override
+ public UnaryCallable createUnaryCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ UnaryCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createUnaryCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+
+ @Override
+ public
+ UnaryCallable createPagedCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ PagedCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createPagedCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+
+ @Override
+ public UnaryCallable createBatchingCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ BatchingCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createBatchingCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+
+ @BetaApi(
+ "The surface for long-running operations is not stable yet and may change in the future.")
+ @Override
+ public
+ OperationCallable createOperationCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ OperationCallSettings callSettings,
+ ClientContext clientContext,
+ OperationsStub operationsStub) {
+ UnaryCallable innerCallable =
+ HttpJsonCallableFactory.createBaseUnaryCallable(
+ httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext);
+ HttpJsonOperationSnapshotCallable initialCallable =
+ new HttpJsonOperationSnapshotCallable(
+ innerCallable,
+ httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory());
+ return HttpJsonCallableFactory.createOperationCallable(
+ callSettings, clientContext, operationsStub.longRunningClient(), initialCallable);
+ }
+
+ @Override
+ public
+ ServerStreamingCallable createServerStreamingCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ ServerStreamingCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createServerStreamingCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+}
diff --git a/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/stub/HttpJsonIamCheckerStub.java b/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/stub/HttpJsonIamCheckerStub.java
new file mode 100644
index 000000000000..71939d46e38c
--- /dev/null
+++ b/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/stub/HttpJsonIamCheckerStub.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright 2022 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.cloud.policytroubleshooter.v1.stub;
+
+import com.google.api.core.BetaApi;
+import com.google.api.core.InternalApi;
+import com.google.api.gax.core.BackgroundResource;
+import com.google.api.gax.core.BackgroundResourceAggregation;
+import com.google.api.gax.httpjson.ApiMethodDescriptor;
+import com.google.api.gax.httpjson.HttpJsonCallSettings;
+import com.google.api.gax.httpjson.HttpJsonStubCallableFactory;
+import com.google.api.gax.httpjson.ProtoMessageRequestFormatter;
+import com.google.api.gax.httpjson.ProtoMessageResponseParser;
+import com.google.api.gax.httpjson.ProtoRestSerializer;
+import com.google.api.gax.rpc.ClientContext;
+import com.google.api.gax.rpc.UnaryCallable;
+import com.google.cloud.policytroubleshooter.v1.TroubleshootIamPolicyRequest;
+import com.google.cloud.policytroubleshooter.v1.TroubleshootIamPolicyResponse;
+import com.google.protobuf.TypeRegistry;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import javax.annotation.Generated;
+
+// AUTO-GENERATED DOCUMENTATION AND CLASS.
+/**
+ * REST stub implementation for the IamChecker service API.
+ *
+ * This class is for advanced usage and reflects the underlying API directly.
+ */
+@Generated("by gapic-generator-java")
+@BetaApi
+public class HttpJsonIamCheckerStub extends IamCheckerStub {
+ private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build();
+
+ private static final ApiMethodDescriptor<
+ TroubleshootIamPolicyRequest, TroubleshootIamPolicyResponse>
+ troubleshootIamPolicyMethodDescriptor =
+ ApiMethodDescriptor
+ .newBuilder()
+ .setFullMethodName(
+ "google.cloud.policytroubleshooter.v1.IamChecker/TroubleshootIamPolicy")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/iam:troubleshoot",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create().toBody("*", request.toBuilder().build()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(TroubleshootIamPolicyResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private final UnaryCallable
+ troubleshootIamPolicyCallable;
+
+ private final BackgroundResource backgroundResources;
+ private final HttpJsonStubCallableFactory callableFactory;
+
+ public static final HttpJsonIamCheckerStub create(IamCheckerStubSettings settings)
+ throws IOException {
+ return new HttpJsonIamCheckerStub(settings, ClientContext.create(settings));
+ }
+
+ public static final HttpJsonIamCheckerStub create(ClientContext clientContext)
+ throws IOException {
+ return new HttpJsonIamCheckerStub(
+ IamCheckerStubSettings.newHttpJsonBuilder().build(), clientContext);
+ }
+
+ public static final HttpJsonIamCheckerStub create(
+ ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException {
+ return new HttpJsonIamCheckerStub(
+ IamCheckerStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory);
+ }
+
+ /**
+ * Constructs an instance of HttpJsonIamCheckerStub, using the given settings. This is protected
+ * so that it is easy to make a subclass, but otherwise, the static factory methods should be
+ * preferred.
+ */
+ protected HttpJsonIamCheckerStub(IamCheckerStubSettings settings, ClientContext clientContext)
+ throws IOException {
+ this(settings, clientContext, new HttpJsonIamCheckerCallableFactory());
+ }
+
+ /**
+ * Constructs an instance of HttpJsonIamCheckerStub, using the given settings. This is protected
+ * so that it is easy to make a subclass, but otherwise, the static factory methods should be
+ * preferred.
+ */
+ protected HttpJsonIamCheckerStub(
+ IamCheckerStubSettings settings,
+ ClientContext clientContext,
+ HttpJsonStubCallableFactory callableFactory)
+ throws IOException {
+ this.callableFactory = callableFactory;
+
+ HttpJsonCallSettings
+ troubleshootIamPolicyTransportSettings =
+ HttpJsonCallSettings
+ .newBuilder()
+ .setMethodDescriptor(troubleshootIamPolicyMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+
+ this.troubleshootIamPolicyCallable =
+ callableFactory.createUnaryCallable(
+ troubleshootIamPolicyTransportSettings,
+ settings.troubleshootIamPolicySettings(),
+ clientContext);
+
+ this.backgroundResources =
+ new BackgroundResourceAggregation(clientContext.getBackgroundResources());
+ }
+
+ @InternalApi
+ public static List getMethodDescriptors() {
+ List methodDescriptors = new ArrayList<>();
+ methodDescriptors.add(troubleshootIamPolicyMethodDescriptor);
+ return methodDescriptors;
+ }
+
+ @Override
+ public UnaryCallable
+ troubleshootIamPolicyCallable() {
+ return troubleshootIamPolicyCallable;
+ }
+
+ @Override
+ public final void close() {
+ try {
+ backgroundResources.close();
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new IllegalStateException("Failed to close resource", e);
+ }
+ }
+
+ @Override
+ public void shutdown() {
+ backgroundResources.shutdown();
+ }
+
+ @Override
+ public boolean isShutdown() {
+ return backgroundResources.isShutdown();
+ }
+
+ @Override
+ public boolean isTerminated() {
+ return backgroundResources.isTerminated();
+ }
+
+ @Override
+ public void shutdownNow() {
+ backgroundResources.shutdownNow();
+ }
+
+ @Override
+ public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
+ return backgroundResources.awaitTermination(duration, unit);
+ }
+}
diff --git a/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/stub/IamCheckerStubSettings.java b/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/stub/IamCheckerStubSettings.java
index ec9b4da8c66d..b8fd4350aeb6 100644
--- a/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/stub/IamCheckerStubSettings.java
+++ b/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/main/java/com/google/cloud/policytroubleshooter/v1/stub/IamCheckerStubSettings.java
@@ -24,6 +24,9 @@
import com.google.api.gax.grpc.GaxGrpcProperties;
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
+import com.google.api.gax.httpjson.GaxHttpJsonProperties;
+import com.google.api.gax.httpjson.HttpJsonTransportChannel;
+import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.ClientContext;
@@ -97,6 +100,11 @@ public IamCheckerStub createStub() throws IOException {
.equals(GrpcTransportChannel.getGrpcTransportName())) {
return GrpcIamCheckerStub.create(this);
}
+ if (getTransportChannelProvider()
+ .getTransportName()
+ .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) {
+ return HttpJsonIamCheckerStub.create(this);
+ }
throw new UnsupportedOperationException(
String.format(
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
@@ -129,18 +137,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
.setUseJwtAccessWithScope(true);
}
- /** Returns a builder for the default ChannelProvider for this service. */
+ /** Returns a builder for the default gRPC ChannelProvider for this service. */
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
return InstantiatingGrpcChannelProvider.newBuilder()
.setMaxInboundMessageSize(Integer.MAX_VALUE);
}
+ /** Returns a builder for the default REST ChannelProvider for this service. */
+ @BetaApi
+ public static InstantiatingHttpJsonChannelProvider.Builder
+ defaultHttpJsonTransportProviderBuilder() {
+ return InstantiatingHttpJsonChannelProvider.newBuilder();
+ }
+
public static TransportChannelProvider defaultTransportChannelProvider() {
return defaultGrpcTransportProviderBuilder().build();
}
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
- public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
+ public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() {
return ApiClientHeaderProvider.newBuilder()
.setGeneratedLibToken(
"gapic", GaxProperties.getLibraryVersion(IamCheckerStubSettings.class))
@@ -148,11 +163,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion());
}
- /** Returns a new builder for this class. */
+ @BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
+ public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() {
+ return ApiClientHeaderProvider.newBuilder()
+ .setGeneratedLibToken(
+ "gapic", GaxProperties.getLibraryVersion(IamCheckerStubSettings.class))
+ .setTransportToken(
+ GaxHttpJsonProperties.getHttpJsonTokenName(),
+ GaxHttpJsonProperties.getHttpJsonVersion());
+ }
+
+ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
+ return IamCheckerStubSettings.defaultGrpcApiClientHeaderProviderBuilder();
+ }
+
+ /** Returns a new gRPC builder for this class. */
public static Builder newBuilder() {
return Builder.createDefault();
}
+ /** Returns a new REST builder for this class. */
+ public static Builder newHttpJsonBuilder() {
+ return Builder.createHttpJsonDefault();
+ }
+
/** Returns a new builder for this class. */
public static Builder newBuilder(ClientContext clientContext) {
return new Builder(clientContext);
@@ -238,6 +272,19 @@ private static Builder createDefault() {
return initDefaults(builder);
}
+ private static Builder createHttpJsonDefault() {
+ Builder builder = new Builder(((ClientContext) null));
+
+ builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build());
+ builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
+ builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build());
+ builder.setEndpoint(getDefaultEndpoint());
+ builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
+ builder.setSwitchToMtlsEndpointAllowed(true);
+
+ return initDefaults(builder);
+ }
+
private static Builder initDefaults(Builder builder) {
builder
.troubleshootIamPolicySettings()
diff --git a/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/test/java/com/google/cloud/policytroubleshooter/v1/IamCheckerClientHttpJsonTest.java b/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/test/java/com/google/cloud/policytroubleshooter/v1/IamCheckerClientHttpJsonTest.java
new file mode 100644
index 000000000000..d604ebdf24dc
--- /dev/null
+++ b/java-policy-troubleshooter/google-cloud-policy-troubleshooter/src/test/java/com/google/cloud/policytroubleshooter/v1/IamCheckerClientHttpJsonTest.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2022 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.cloud.policytroubleshooter.v1;
+
+import com.google.api.gax.core.NoCredentialsProvider;
+import com.google.api.gax.httpjson.GaxHttpJsonProperties;
+import com.google.api.gax.httpjson.testing.MockHttpService;
+import com.google.api.gax.rpc.ApiClientHeaderProvider;
+import com.google.api.gax.rpc.ApiException;
+import com.google.api.gax.rpc.ApiExceptionFactory;
+import com.google.api.gax.rpc.InvalidArgumentException;
+import com.google.api.gax.rpc.StatusCode;
+import com.google.api.gax.rpc.testing.FakeStatusCode;
+import com.google.cloud.policytroubleshooter.v1.stub.HttpJsonIamCheckerStub;
+import google.cloud.policytroubleshooter.v1.Explanations;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Generated;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+@Generated("by gapic-generator-java")
+public class IamCheckerClientHttpJsonTest {
+ private static MockHttpService mockService;
+ private static IamCheckerClient client;
+
+ @BeforeClass
+ public static void startStaticServer() throws IOException {
+ mockService =
+ new MockHttpService(
+ HttpJsonIamCheckerStub.getMethodDescriptors(), IamCheckerSettings.getDefaultEndpoint());
+ IamCheckerSettings settings =
+ IamCheckerSettings.newHttpJsonBuilder()
+ .setTransportChannelProvider(
+ IamCheckerSettings.defaultHttpJsonTransportProviderBuilder()
+ .setHttpTransport(mockService)
+ .build())
+ .setCredentialsProvider(NoCredentialsProvider.create())
+ .build();
+ client = IamCheckerClient.create(settings);
+ }
+
+ @AfterClass
+ public static void stopServer() {
+ client.close();
+ }
+
+ @Before
+ public void setUp() {}
+
+ @After
+ public void tearDown() throws Exception {
+ mockService.reset();
+ }
+
+ @Test
+ public void troubleshootIamPolicyTest() throws Exception {
+ TroubleshootIamPolicyResponse expectedResponse =
+ TroubleshootIamPolicyResponse.newBuilder()
+ .setAccess(Explanations.AccessState.forNumber(0))
+ .addAllExplainedPolicies(new ArrayList())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ TroubleshootIamPolicyRequest request =
+ TroubleshootIamPolicyRequest.newBuilder()
+ .setAccessTuple(Explanations.AccessTuple.newBuilder().build())
+ .build();
+
+ TroubleshootIamPolicyResponse actualResponse = client.troubleshootIamPolicy(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 troubleshootIamPolicyExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ TroubleshootIamPolicyRequest request =
+ TroubleshootIamPolicyRequest.newBuilder()
+ .setAccessTuple(Explanations.AccessTuple.newBuilder().build())
+ .build();
+ client.troubleshootIamPolicy(request);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+}
diff --git a/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/create/SyncCreateSetCredentialsProvider.java b/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/create/SyncCreateSetCredentialsProvider.java
new file mode 100644
index 000000000000..0ee65c0237fb
--- /dev/null
+++ b/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/create/SyncCreateSetCredentialsProvider.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2022 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.cloud.policytroubleshooter.v1.samples;
+
+// [START policytroubleshooter_v1_generated_iamcheckerclient_create_setcredentialsprovider_sync]
+import com.google.api.gax.core.FixedCredentialsProvider;
+import com.google.cloud.policytroubleshooter.v1.IamCheckerClient;
+import com.google.cloud.policytroubleshooter.v1.IamCheckerSettings;
+import com.google.cloud.policytroubleshooter.v1.myCredentials;
+
+public class SyncCreateSetCredentialsProvider {
+
+ public static void main(String[] args) throws Exception {
+ syncCreateSetCredentialsProvider();
+ }
+
+ public static void syncCreateSetCredentialsProvider() throws Exception {
+ // This snippet has been automatically generated for illustrative purposes only.
+ // It may require modifications to work in your environment.
+ IamCheckerSettings iamCheckerSettings =
+ IamCheckerSettings.newBuilder()
+ .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ .build();
+ IamCheckerClient iamCheckerClient = IamCheckerClient.create(iamCheckerSettings);
+ }
+}
+// [END policytroubleshooter_v1_generated_iamcheckerclient_create_setcredentialsprovider_sync]
diff --git a/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/create/SyncCreateSetCredentialsProvider1.java b/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/create/SyncCreateSetCredentialsProvider1.java
new file mode 100644
index 000000000000..b5509adc5116
--- /dev/null
+++ b/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/create/SyncCreateSetCredentialsProvider1.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2022 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.cloud.policytroubleshooter.v1.samples;
+
+// [START policytroubleshooter_v1_generated_iamcheckerclient_create_setcredentialsprovider1_sync]
+import com.google.cloud.policytroubleshooter.v1.IamCheckerClient;
+import com.google.cloud.policytroubleshooter.v1.IamCheckerSettings;
+
+public class SyncCreateSetCredentialsProvider1 {
+
+ public static void main(String[] args) throws Exception {
+ syncCreateSetCredentialsProvider1();
+ }
+
+ public static void syncCreateSetCredentialsProvider1() throws Exception {
+ // This snippet has been automatically generated for illustrative purposes only.
+ // It may require modifications to work in your environment.
+ IamCheckerSettings iamCheckerSettings =
+ IamCheckerSettings.newBuilder()
+ .setTransportChannelProvider(
+ IamCheckerSettings.defaultHttpJsonTransportProviderBuilder().build())
+ .build();
+ IamCheckerClient iamCheckerClient = IamCheckerClient.create(iamCheckerSettings);
+ }
+}
+// [END policytroubleshooter_v1_generated_iamcheckerclient_create_setcredentialsprovider1_sync]
diff --git a/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/create/SyncCreateSetEndpoint.java b/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/create/SyncCreateSetEndpoint.java
new file mode 100644
index 000000000000..93a1c5feb8f5
--- /dev/null
+++ b/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/create/SyncCreateSetEndpoint.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2022 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.cloud.policytroubleshooter.v1.samples;
+
+// [START policytroubleshooter_v1_generated_iamcheckerclient_create_setendpoint_sync]
+import com.google.cloud.policytroubleshooter.v1.IamCheckerClient;
+import com.google.cloud.policytroubleshooter.v1.IamCheckerSettings;
+import com.google.cloud.policytroubleshooter.v1.myEndpoint;
+
+public class SyncCreateSetEndpoint {
+
+ public static void main(String[] args) throws Exception {
+ syncCreateSetEndpoint();
+ }
+
+ public static void syncCreateSetEndpoint() throws Exception {
+ // This snippet has been automatically generated for illustrative purposes only.
+ // It may require modifications to work in your environment.
+ IamCheckerSettings iamCheckerSettings =
+ IamCheckerSettings.newBuilder().setEndpoint(myEndpoint).build();
+ IamCheckerClient iamCheckerClient = IamCheckerClient.create(iamCheckerSettings);
+ }
+}
+// [END policytroubleshooter_v1_generated_iamcheckerclient_create_setendpoint_sync]
diff --git a/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/troubleshootiampolicy/AsyncTroubleshootIamPolicy.java b/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/troubleshootiampolicy/AsyncTroubleshootIamPolicy.java
new file mode 100644
index 000000000000..a3c15356fb27
--- /dev/null
+++ b/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/troubleshootiampolicy/AsyncTroubleshootIamPolicy.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2022 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.cloud.policytroubleshooter.v1.samples;
+
+// [START policytroubleshooter_v1_generated_iamcheckerclient_troubleshootiampolicy_async]
+import com.google.api.core.ApiFuture;
+import com.google.cloud.policytroubleshooter.v1.IamCheckerClient;
+import com.google.cloud.policytroubleshooter.v1.TroubleshootIamPolicyRequest;
+import com.google.cloud.policytroubleshooter.v1.TroubleshootIamPolicyResponse;
+import google.cloud.policytroubleshooter.v1.Explanations;
+
+public class AsyncTroubleshootIamPolicy {
+
+ public static void main(String[] args) throws Exception {
+ asyncTroubleshootIamPolicy();
+ }
+
+ public static void asyncTroubleshootIamPolicy() throws Exception {
+ // This snippet has been automatically generated for illustrative purposes only.
+ // It may require modifications to work in your environment.
+ try (IamCheckerClient iamCheckerClient = IamCheckerClient.create()) {
+ TroubleshootIamPolicyRequest request =
+ TroubleshootIamPolicyRequest.newBuilder()
+ .setAccessTuple(Explanations.AccessTuple.newBuilder().build())
+ .build();
+ ApiFuture future =
+ iamCheckerClient.troubleshootIamPolicyCallable().futureCall(request);
+ // Do something.
+ TroubleshootIamPolicyResponse response = future.get();
+ }
+ }
+}
+// [END policytroubleshooter_v1_generated_iamcheckerclient_troubleshootiampolicy_async]
diff --git a/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/troubleshootiampolicy/SyncTroubleshootIamPolicy.java b/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/troubleshootiampolicy/SyncTroubleshootIamPolicy.java
new file mode 100644
index 000000000000..c7e6ccfeb2d5
--- /dev/null
+++ b/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckerclient/troubleshootiampolicy/SyncTroubleshootIamPolicy.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2022 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.cloud.policytroubleshooter.v1.samples;
+
+// [START policytroubleshooter_v1_generated_iamcheckerclient_troubleshootiampolicy_sync]
+import com.google.cloud.policytroubleshooter.v1.IamCheckerClient;
+import com.google.cloud.policytroubleshooter.v1.TroubleshootIamPolicyRequest;
+import com.google.cloud.policytroubleshooter.v1.TroubleshootIamPolicyResponse;
+import google.cloud.policytroubleshooter.v1.Explanations;
+
+public class SyncTroubleshootIamPolicy {
+
+ public static void main(String[] args) throws Exception {
+ syncTroubleshootIamPolicy();
+ }
+
+ public static void syncTroubleshootIamPolicy() throws Exception {
+ // This snippet has been automatically generated for illustrative purposes only.
+ // It may require modifications to work in your environment.
+ try (IamCheckerClient iamCheckerClient = IamCheckerClient.create()) {
+ TroubleshootIamPolicyRequest request =
+ TroubleshootIamPolicyRequest.newBuilder()
+ .setAccessTuple(Explanations.AccessTuple.newBuilder().build())
+ .build();
+ TroubleshootIamPolicyResponse response = iamCheckerClient.troubleshootIamPolicy(request);
+ }
+ }
+}
+// [END policytroubleshooter_v1_generated_iamcheckerclient_troubleshootiampolicy_sync]
diff --git a/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckersettings/troubleshootiampolicy/SyncTroubleshootIamPolicy.java b/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckersettings/troubleshootiampolicy/SyncTroubleshootIamPolicy.java
new file mode 100644
index 000000000000..cc76c8099174
--- /dev/null
+++ b/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/iamcheckersettings/troubleshootiampolicy/SyncTroubleshootIamPolicy.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2022 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.cloud.policytroubleshooter.v1.samples;
+
+// [START policytroubleshooter_v1_generated_iamcheckersettings_troubleshootiampolicy_sync]
+import com.google.cloud.policytroubleshooter.v1.IamCheckerSettings;
+import java.time.Duration;
+
+public class SyncTroubleshootIamPolicy {
+
+ public static void main(String[] args) throws Exception {
+ syncTroubleshootIamPolicy();
+ }
+
+ public static void syncTroubleshootIamPolicy() throws Exception {
+ // This snippet has been automatically generated for illustrative purposes only.
+ // It may require modifications to work in your environment.
+ IamCheckerSettings.Builder iamCheckerSettingsBuilder = IamCheckerSettings.newBuilder();
+ iamCheckerSettingsBuilder
+ .troubleshootIamPolicySettings()
+ .setRetrySettings(
+ iamCheckerSettingsBuilder
+ .troubleshootIamPolicySettings()
+ .getRetrySettings()
+ .toBuilder()
+ .setTotalTimeout(Duration.ofSeconds(30))
+ .build());
+ IamCheckerSettings iamCheckerSettings = iamCheckerSettingsBuilder.build();
+ }
+}
+// [END policytroubleshooter_v1_generated_iamcheckersettings_troubleshootiampolicy_sync]
diff --git a/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/stub/iamcheckerstubsettings/troubleshootiampolicy/SyncTroubleshootIamPolicy.java b/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/stub/iamcheckerstubsettings/troubleshootiampolicy/SyncTroubleshootIamPolicy.java
new file mode 100644
index 000000000000..0bea0ca5c8c7
--- /dev/null
+++ b/java-policy-troubleshooter/samples/snippets/generated/com/google/cloud/policytroubleshooter/v1/stub/iamcheckerstubsettings/troubleshootiampolicy/SyncTroubleshootIamPolicy.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2022 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.cloud.policytroubleshooter.v1.stub.samples;
+
+// [START policytroubleshooter_v1_generated_iamcheckerstubsettings_troubleshootiampolicy_sync]
+import com.google.cloud.policytroubleshooter.v1.stub.IamCheckerStubSettings;
+import java.time.Duration;
+
+public class SyncTroubleshootIamPolicy {
+
+ public static void main(String[] args) throws Exception {
+ syncTroubleshootIamPolicy();
+ }
+
+ public static void syncTroubleshootIamPolicy() throws Exception {
+ // This snippet has been automatically generated for illustrative purposes only.
+ // It may require modifications to work in your environment.
+ IamCheckerStubSettings.Builder iamCheckerSettingsBuilder = IamCheckerStubSettings.newBuilder();
+ iamCheckerSettingsBuilder
+ .troubleshootIamPolicySettings()
+ .setRetrySettings(
+ iamCheckerSettingsBuilder
+ .troubleshootIamPolicySettings()
+ .getRetrySettings()
+ .toBuilder()
+ .setTotalTimeout(Duration.ofSeconds(30))
+ .build());
+ IamCheckerStubSettings iamCheckerSettings = iamCheckerSettingsBuilder.build();
+ }
+}
+// [END policytroubleshooter_v1_generated_iamcheckerstubsettings_troubleshootiampolicy_sync]