@Generated(value="by gapic-generator-java") public class SimulatorClient extends Object implements com.google.api.gax.core.BackgroundResource
Policy Simulator is a collection of endpoints for creating, running, and viewing a [Replay][google.cloud.policysimulator.v1.Replay]. A [Replay][google.cloud.policysimulator.v1.Replay] is a type of simulation that lets you see how your principals' access to resources might change if you changed your IAM policy.
During a [Replay][google.cloud.policysimulator.v1.Replay], Policy Simulator re-evaluates, or replays, past access attempts under both the current policy and your proposed policy, and compares those results to determine how your principals' access might change under the proposed policy.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
// 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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
ReplayName name =
ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]");
Replay response = simulatorClient.getReplay(name);
}
Note: close() needs to be called on the SimulatorClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
| Method | Description | Method Variants |
|---|---|---|
| GetReplay | Gets the specified [Replay][google.cloud.policysimulator.v1.Replay]. Each `Replay` is available for at least 7 days. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
| CreateReplay | Creates and starts a [Replay][google.cloud.policysimulator.v1.Replay] using the given [ReplayConfig][google.cloud.policysimulator.v1.ReplayConfig]. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Methods that return long-running operations have "Async" method variants that return `OperationFuture`, which is used to track polling of the service.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
| ListReplayResults | Lists the results of running a [Replay][google.cloud.policysimulator.v1.Replay]. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of SimulatorSettings to create(). For example:
To customize credentials:
// 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
SimulatorSettings simulatorSettings =
SimulatorSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
SimulatorClient simulatorClient = SimulatorClient.create(simulatorSettings);
To customize the endpoint:
// 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
SimulatorSettings simulatorSettings =
SimulatorSettings.newBuilder().setEndpoint(myEndpoint).build();
SimulatorClient simulatorClient = SimulatorClient.create(simulatorSettings);
To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:
// 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
SimulatorSettings simulatorSettings = SimulatorSettings.newHttpJsonBuilder().build();
SimulatorClient simulatorClient = SimulatorClient.create(simulatorSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
| Modifier and Type | Class and Description |
|---|---|
static class |
SimulatorClient.ListReplayResultsFixedSizeCollection |
static class |
SimulatorClient.ListReplayResultsPage |
static class |
SimulatorClient.ListReplayResultsPagedResponse |
| Modifier | Constructor and Description |
|---|---|
protected |
SimulatorClient(SimulatorSettings settings)
Constructs an instance of SimulatorClient, using the given settings.
|
protected |
SimulatorClient(SimulatorStub stub) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static SimulatorClient |
create()
Constructs an instance of SimulatorClient with default settings.
|
static SimulatorClient |
create(SimulatorSettings settings)
Constructs an instance of SimulatorClient, using the given settings.
|
static SimulatorClient |
create(SimulatorStub stub)
Constructs an instance of SimulatorClient, using the given stub for making calls.
|
com.google.api.gax.longrunning.OperationFuture<Replay,ReplayOperationMetadata> |
createReplayAsync(CreateReplayRequest request)
Creates and starts a [Replay][google.cloud.policysimulator.v1.Replay] using the given
[ReplayConfig][google.cloud.policysimulator.v1.ReplayConfig].
|
com.google.api.gax.longrunning.OperationFuture<Replay,ReplayOperationMetadata> |
createReplayAsync(String parent,
Replay replay)
Creates and starts a [Replay][google.cloud.policysimulator.v1.Replay] using the given
[ReplayConfig][google.cloud.policysimulator.v1.ReplayConfig].
|
com.google.api.gax.rpc.UnaryCallable<CreateReplayRequest,com.google.longrunning.Operation> |
createReplayCallable()
Creates and starts a [Replay][google.cloud.policysimulator.v1.Replay] using the given
[ReplayConfig][google.cloud.policysimulator.v1.ReplayConfig].
|
com.google.api.gax.rpc.OperationCallable<CreateReplayRequest,Replay,ReplayOperationMetadata> |
createReplayOperationCallable()
Creates and starts a [Replay][google.cloud.policysimulator.v1.Replay] using the given
[ReplayConfig][google.cloud.policysimulator.v1.ReplayConfig].
|
com.google.api.gax.httpjson.longrunning.OperationsClient |
getHttpJsonOperationsClient()
Returns the OperationsClient that can be used to query the status of a long-running operation
returned by another API method call.
|
com.google.longrunning.OperationsClient |
getOperationsClient()
Returns the OperationsClient that can be used to query the status of a long-running operation
returned by another API method call.
|
Replay |
getReplay(GetReplayRequest request)
Gets the specified [Replay][google.cloud.policysimulator.v1.Replay].
|
Replay |
getReplay(ReplayName name)
Gets the specified [Replay][google.cloud.policysimulator.v1.Replay].
|
Replay |
getReplay(String name)
Gets the specified [Replay][google.cloud.policysimulator.v1.Replay].
|
com.google.api.gax.rpc.UnaryCallable<GetReplayRequest,Replay> |
getReplayCallable()
Gets the specified [Replay][google.cloud.policysimulator.v1.Replay].
|
SimulatorSettings |
getSettings() |
SimulatorStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
SimulatorClient.ListReplayResultsPagedResponse |
listReplayResults(ListReplayResultsRequest request)
Lists the results of running a [Replay][google.cloud.policysimulator.v1.Replay].
|
SimulatorClient.ListReplayResultsPagedResponse |
listReplayResults(ReplayName parent)
Lists the results of running a [Replay][google.cloud.policysimulator.v1.Replay].
|
SimulatorClient.ListReplayResultsPagedResponse |
listReplayResults(String parent)
Lists the results of running a [Replay][google.cloud.policysimulator.v1.Replay].
|
com.google.api.gax.rpc.UnaryCallable<ListReplayResultsRequest,ListReplayResultsResponse> |
listReplayResultsCallable()
Lists the results of running a [Replay][google.cloud.policysimulator.v1.Replay].
|
com.google.api.gax.rpc.UnaryCallable<ListReplayResultsRequest,SimulatorClient.ListReplayResultsPagedResponse> |
listReplayResultsPagedCallable()
Lists the results of running a [Replay][google.cloud.policysimulator.v1.Replay].
|
void |
shutdown() |
void |
shutdownNow() |
protected SimulatorClient(SimulatorSettings settings) throws IOException
IOExceptionprotected SimulatorClient(SimulatorStub stub)
public static final SimulatorClient create() throws IOException
IOExceptionpublic static final SimulatorClient create(SimulatorSettings settings) throws IOException
IOExceptionpublic static final SimulatorClient create(SimulatorStub stub)
public final SimulatorSettings getSettings()
public SimulatorStub getStub()
public final com.google.longrunning.OperationsClient getOperationsClient()
@BetaApi public final com.google.api.gax.httpjson.longrunning.OperationsClient getHttpJsonOperationsClient()
public final Replay getReplay(ReplayName name)
Sample 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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
ReplayName name =
ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]");
Replay response = simulatorClient.getReplay(name);
}
name - Required. The name of the [Replay][google.cloud.policysimulator.v1.Replay] to
retrieve, in the following format:
`{projects|folders|organizations}/{resource-id}/locations/global/replays/{replay-id}`, where `{resource-id}` is the ID of the project, folder, or organization that owns the `Replay`.
Example: `projects/my-example-project/locations/global/replays/506a5f7f-38ce-4d7d-8e03-479ce1833c36`
com.google.api.gax.rpc.ApiException - if the remote call failspublic final Replay getReplay(String name)
Sample 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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
String name =
ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]").toString();
Replay response = simulatorClient.getReplay(name);
}
name - Required. The name of the [Replay][google.cloud.policysimulator.v1.Replay] to
retrieve, in the following format:
`{projects|folders|organizations}/{resource-id}/locations/global/replays/{replay-id}`, where `{resource-id}` is the ID of the project, folder, or organization that owns the `Replay`.
Example: `projects/my-example-project/locations/global/replays/506a5f7f-38ce-4d7d-8e03-479ce1833c36`
com.google.api.gax.rpc.ApiException - if the remote call failspublic final Replay getReplay(GetReplayRequest request)
Sample 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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
GetReplayRequest request =
GetReplayRequest.newBuilder()
.setName(
ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]")
.toString())
.build();
Replay response = simulatorClient.getReplay(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<GetReplayRequest,Replay> getReplayCallable()
Sample 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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
GetReplayRequest request =
GetReplayRequest.newBuilder()
.setName(
ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]")
.toString())
.build();
ApiFuture<Replay> future = simulatorClient.getReplayCallable().futureCall(request);
// Do something.
Replay response = future.get();
}
public final com.google.api.gax.longrunning.OperationFuture<Replay,ReplayOperationMetadata> createReplayAsync(String parent, Replay replay)
Sample 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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
String parent = "parent-995424086";
Replay replay = Replay.newBuilder().build();
Replay response = simulatorClient.createReplayAsync(parent, replay).get();
}
parent - Required. The parent resource where this
[Replay][google.cloud.policysimulator.v1.Replay] will be created. This resource must be a
project, folder, or organization with a location.
Example: `projects/my-example-project/locations/global`
replay - Required. The [Replay][google.cloud.policysimulator.v1.Replay] to create. Set
`Replay.ReplayConfig` to configure the replay.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.longrunning.OperationFuture<Replay,ReplayOperationMetadata> createReplayAsync(CreateReplayRequest request)
Sample 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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
CreateReplayRequest request =
CreateReplayRequest.newBuilder()
.setParent("parent-995424086")
.setReplay(Replay.newBuilder().build())
.build();
Replay response = simulatorClient.createReplayAsync(request).get();
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.OperationCallable<CreateReplayRequest,Replay,ReplayOperationMetadata> createReplayOperationCallable()
Sample 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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
CreateReplayRequest request =
CreateReplayRequest.newBuilder()
.setParent("parent-995424086")
.setReplay(Replay.newBuilder().build())
.build();
OperationFuture<Replay, ReplayOperationMetadata> future =
simulatorClient.createReplayOperationCallable().futureCall(request);
// Do something.
Replay response = future.get();
}
public final com.google.api.gax.rpc.UnaryCallable<CreateReplayRequest,com.google.longrunning.Operation> createReplayCallable()
Sample 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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
CreateReplayRequest request =
CreateReplayRequest.newBuilder()
.setParent("parent-995424086")
.setReplay(Replay.newBuilder().build())
.build();
ApiFuture<Operation> future = simulatorClient.createReplayCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
public final SimulatorClient.ListReplayResultsPagedResponse listReplayResults(ReplayName parent)
Sample 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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
ReplayName parent =
ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]");
for (ReplayResult element : simulatorClient.listReplayResults(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent - Required. The [Replay][google.cloud.policysimulator.v1.Replay] whose results are
listed, in the following format:
`{projects|folders|organizations}/{resource-id}/locations/global/replays/{replay-id}`
Example: `projects/my-project/locations/global/replays/506a5f7f-38ce-4d7d-8e03-479ce1833c36`
com.google.api.gax.rpc.ApiException - if the remote call failspublic final SimulatorClient.ListReplayResultsPagedResponse listReplayResults(String parent)
Sample 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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
String parent =
ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]").toString();
for (ReplayResult element : simulatorClient.listReplayResults(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent - Required. The [Replay][google.cloud.policysimulator.v1.Replay] whose results are
listed, in the following format:
`{projects|folders|organizations}/{resource-id}/locations/global/replays/{replay-id}`
Example: `projects/my-project/locations/global/replays/506a5f7f-38ce-4d7d-8e03-479ce1833c36`
com.google.api.gax.rpc.ApiException - if the remote call failspublic final SimulatorClient.ListReplayResultsPagedResponse listReplayResults(ListReplayResultsRequest request)
Sample 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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
ListReplayResultsRequest request =
ListReplayResultsRequest.newBuilder()
.setParent(
ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]")
.toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for (ReplayResult element : simulatorClient.listReplayResults(request).iterateAll()) {
// doThingsWith(element);
}
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<ListReplayResultsRequest,SimulatorClient.ListReplayResultsPagedResponse> listReplayResultsPagedCallable()
Sample 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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
ListReplayResultsRequest request =
ListReplayResultsRequest.newBuilder()
.setParent(
ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]")
.toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
ApiFuture<ReplayResult> future =
simulatorClient.listReplayResultsPagedCallable().futureCall(request);
// Do something.
for (ReplayResult element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.rpc.UnaryCallable<ListReplayResultsRequest,ListReplayResultsResponse> listReplayResultsCallable()
Sample 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 (SimulatorClient simulatorClient = SimulatorClient.create()) {
ListReplayResultsRequest request =
ListReplayResultsRequest.newBuilder()
.setParent(
ReplayName.ofProjectLocationReplayName("[PROJECT]", "[LOCATION]", "[REPLAY]")
.toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
while (true) {
ListReplayResultsResponse response =
simulatorClient.listReplayResultsCallable().call(request);
for (ReplayResult element : response.getReplayResultsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final void close()
close in interface AutoCloseablepublic void shutdown()
shutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isShutdown()
isShutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isTerminated()
isTerminated in interface com.google.api.gax.core.BackgroundResourcepublic void shutdownNow()
shutdownNow in interface com.google.api.gax.core.BackgroundResourcepublic boolean awaitTermination(long duration,
TimeUnit unit)
throws InterruptedException
awaitTermination in interface com.google.api.gax.core.BackgroundResourceInterruptedExceptionCopyright © 2024 Google LLC. All rights reserved.