- 1.53.0 (latest)
- 1.52.0
- 1.51.0
- 1.50.0
- 1.49.0
- 1.47.0
- 1.46.0
- 1.45.0
- 1.44.0
- 1.43.0
- 1.42.0
- 1.41.0
- 1.40.0
- 1.39.0
- 1.38.0
- 1.37.0
- 1.35.0
- 1.34.0
- 1.33.0
- 1.32.0
- 1.31.0
- 1.30.0
- 1.29.0
- 1.28.0
- 1.27.0
- 1.26.0
- 1.25.0
- 1.22.0
- 1.21.0
- 1.20.0
- 1.19.0
- 1.18.0
- 1.17.0
- 1.16.0
- 1.15.0
- 1.14.0
- 1.13.0
- 1.12.0
- 1.11.0
- 1.10.0
- 1.9.0
- 1.7.0
GitHub Repository | Product Reference |
Service Description: An interface for managing Identity and Access Management (IAM) policies.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
String name = "name3373707";
Policy response = policiesClient.getPolicy(name);
}
Note: close() needs to be called on the PoliciesClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
- A "callable" method. This type of method takes no parameters and returns 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 PoliciesSettings 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
PoliciesSettings policiesSettings =
PoliciesSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
PoliciesClient policiesClient = PoliciesClient.create(policiesSettings);
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
PoliciesSettings policiesSettings =
PoliciesSettings.newBuilder().setEndpoint(myEndpoint).build();
PoliciesClient policiesClient = PoliciesClient.create(policiesSettings);
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
PoliciesSettings policiesSettings = PoliciesSettings.newHttpJsonBuilder().build();
PoliciesClient policiesClient = PoliciesClient.create(policiesSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Static Methods
create()
public static final PoliciesClient create()
Constructs an instance of PoliciesClient with default settings.
Returns | |
---|---|
Type | Description |
PoliciesClient |
Exceptions | |
---|---|
Type | Description |
IOException |
create(PoliciesSettings settings)
public static final PoliciesClient create(PoliciesSettings settings)
Constructs an instance of PoliciesClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.
Parameter | |
---|---|
Name | Description |
settings | PoliciesSettings |
Returns | |
---|---|
Type | Description |
PoliciesClient |
Exceptions | |
---|---|
Type | Description |
IOException |
create(PoliciesStub stub)
public static final PoliciesClient create(PoliciesStub stub)
Constructs an instance of PoliciesClient, using the given stub for making calls. This is for advanced usage - prefer using create(PoliciesSettings).
Parameter | |
---|---|
Name | Description |
stub | PoliciesStub |
Returns | |
---|---|
Type | Description |
PoliciesClient |
Constructors
PoliciesClient(PoliciesSettings settings)
protected PoliciesClient(PoliciesSettings settings)
Constructs an instance of PoliciesClient, 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.
Parameter | |
---|---|
Name | Description |
settings | PoliciesSettings |
PoliciesClient(PoliciesStub stub)
protected PoliciesClient(PoliciesStub stub)
Parameter | |
---|---|
Name | Description |
stub | PoliciesStub |
Methods
awaitTermination(long duration, TimeUnit unit)
public boolean awaitTermination(long duration, TimeUnit unit)
Parameters | |
---|---|
Name | Description |
duration | long |
unit | TimeUnit |
Returns | |
---|---|
Type | Description |
boolean |
Exceptions | |
---|---|
Type | Description |
InterruptedException |
close()
public final void close()
createPolicyAsync(CreatePolicyRequest request)
public final OperationFuture<Policy,PolicyOperationMetadata> createPolicyAsync(CreatePolicyRequest request)
Creates a policy.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
CreatePolicyRequest request =
CreatePolicyRequest.newBuilder()
.setParent("parent-995424086")
.setPolicy(Policy.newBuilder().build())
.setPolicyId("policyId546908653")
.build();
Policy response = policiesClient.createPolicyAsync(request).get();
}
Parameter | |
---|---|
Name | Description |
request | CreatePolicyRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
OperationFuture<Policy,PolicyOperationMetadata> |
createPolicyAsync(String parent, Policy policy, String policyId)
public final OperationFuture<Policy,PolicyOperationMetadata> createPolicyAsync(String parent, Policy policy, String policyId)
Creates a policy.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
String parent = "parent-995424086";
Policy policy = Policy.newBuilder().build();
String policyId = "policyId546908653";
Policy response = policiesClient.createPolicyAsync(parent, policy, policyId).get();
}
Parameters | |
---|---|
Name | Description |
parent | String Required. The resource that the policy is attached to, along with the kind of
policy to create. Format: The attachment point is identified by its URL-encoded full resource name, which means
that the forward-slash character, For organizations and folders, use the numeric ID in the full resource name. For projects, you can use the alphanumeric or the numeric ID. |
policy | Policy Required. The policy to create. |
policyId | String The ID to use for this policy, which will become the final component of the
policy's resource name. The ID must contain 3 to 63 characters. It can contain lowercase
letters and numbers, as well as dashes ( |
Returns | |
---|---|
Type | Description |
OperationFuture<Policy,PolicyOperationMetadata> |
createPolicyCallable()
public final UnaryCallable<CreatePolicyRequest,Operation> createPolicyCallable()
Creates a policy.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
CreatePolicyRequest request =
CreatePolicyRequest.newBuilder()
.setParent("parent-995424086")
.setPolicy(Policy.newBuilder().build())
.setPolicyId("policyId546908653")
.build();
ApiFuture<Operation> future = policiesClient.createPolicyCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<CreatePolicyRequest,Operation> |
createPolicyOperationCallable()
public final OperationCallable<CreatePolicyRequest,Policy,PolicyOperationMetadata> createPolicyOperationCallable()
Creates a policy.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
CreatePolicyRequest request =
CreatePolicyRequest.newBuilder()
.setParent("parent-995424086")
.setPolicy(Policy.newBuilder().build())
.setPolicyId("policyId546908653")
.build();
OperationFuture<Policy, PolicyOperationMetadata> future =
policiesClient.createPolicyOperationCallable().futureCall(request);
// Do something.
Policy response = future.get();
}
Returns | |
---|---|
Type | Description |
OperationCallable<CreatePolicyRequest,Policy,PolicyOperationMetadata> |
deletePolicyAsync(DeletePolicyRequest request)
public final OperationFuture<Policy,PolicyOperationMetadata> deletePolicyAsync(DeletePolicyRequest request)
Deletes a policy. This action is permanent.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
DeletePolicyRequest request =
DeletePolicyRequest.newBuilder().setName("name3373707").setEtag("etag3123477").build();
Policy response = policiesClient.deletePolicyAsync(request).get();
}
Parameter | |
---|---|
Name | Description |
request | DeletePolicyRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
OperationFuture<Policy,PolicyOperationMetadata> |
deletePolicyAsync(String name)
public final OperationFuture<Policy,PolicyOperationMetadata> deletePolicyAsync(String name)
Deletes a policy. This action is permanent.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
String name = "name3373707";
Policy response = policiesClient.deletePolicyAsync(name).get();
}
Parameter | |
---|---|
Name | Description |
name | String Required. The resource name of the policy to delete. Format:
Use the URL-encoded full resource name, which means that the forward-slash character,
For organizations and folders, use the numeric ID in the full resource name. For projects, you can use the alphanumeric or the numeric ID. |
Returns | |
---|---|
Type | Description |
OperationFuture<Policy,PolicyOperationMetadata> |
deletePolicyCallable()
public final UnaryCallable<DeletePolicyRequest,Operation> deletePolicyCallable()
Deletes a policy. This action is permanent.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
DeletePolicyRequest request =
DeletePolicyRequest.newBuilder().setName("name3373707").setEtag("etag3123477").build();
ApiFuture<Operation> future = policiesClient.deletePolicyCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<DeletePolicyRequest,Operation> |
deletePolicyOperationCallable()
public final OperationCallable<DeletePolicyRequest,Policy,PolicyOperationMetadata> deletePolicyOperationCallable()
Deletes a policy. This action is permanent.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
DeletePolicyRequest request =
DeletePolicyRequest.newBuilder().setName("name3373707").setEtag("etag3123477").build();
OperationFuture<Policy, PolicyOperationMetadata> future =
policiesClient.deletePolicyOperationCallable().futureCall(request);
// Do something.
Policy response = future.get();
}
Returns | |
---|---|
Type | Description |
OperationCallable<DeletePolicyRequest,Policy,PolicyOperationMetadata> |
getHttpJsonOperationsClient()
public final OperationsClient getHttpJsonOperationsClient()
Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.
Returns | |
---|---|
Type | Description |
OperationsClient |
getOperationsClient()
public final OperationsClient getOperationsClient()
Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.
Returns | |
---|---|
Type | Description |
OperationsClient |
getPolicy(GetPolicyRequest request)
public final Policy getPolicy(GetPolicyRequest request)
Gets a policy.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
GetPolicyRequest request = GetPolicyRequest.newBuilder().setName("name3373707").build();
Policy response = policiesClient.getPolicy(request);
}
Parameter | |
---|---|
Name | Description |
request | GetPolicyRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
Policy |
getPolicy(String name)
public final Policy getPolicy(String name)
Gets a policy.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
String name = "name3373707";
Policy response = policiesClient.getPolicy(name);
}
Parameter | |
---|---|
Name | Description |
name | String Required. The resource name of the policy to retrieve. Format:
Use the URL-encoded full resource name, which means that the forward-slash character,
For organizations and folders, use the numeric ID in the full resource name. For projects, you can use the alphanumeric or the numeric ID. |
Returns | |
---|---|
Type | Description |
Policy |
getPolicyCallable()
public final UnaryCallable<GetPolicyRequest,Policy> getPolicyCallable()
Gets a policy.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
GetPolicyRequest request = GetPolicyRequest.newBuilder().setName("name3373707").build();
ApiFuture<Policy> future = policiesClient.getPolicyCallable().futureCall(request);
// Do something.
Policy response = future.get();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<GetPolicyRequest,Policy> |
getSettings()
public final PoliciesSettings getSettings()
Returns | |
---|---|
Type | Description |
PoliciesSettings |
getStub()
public PoliciesStub getStub()
Returns | |
---|---|
Type | Description |
PoliciesStub |
isShutdown()
public boolean isShutdown()
Returns | |
---|---|
Type | Description |
boolean |
isTerminated()
public boolean isTerminated()
Returns | |
---|---|
Type | Description |
boolean |
listPolicies(ListPoliciesRequest request)
public final PoliciesClient.ListPoliciesPagedResponse listPolicies(ListPoliciesRequest request)
Retrieves the policies of the specified kind that are attached to a resource.
The response lists only policy metadata. In particular, policy rules are omitted.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
ListPoliciesRequest request =
ListPoliciesRequest.newBuilder()
.setParent("parent-995424086")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for (Policy element : policiesClient.listPolicies(request).iterateAll()) {
// doThingsWith(element);
}
}
Parameter | |
---|---|
Name | Description |
request | ListPoliciesRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
PoliciesClient.ListPoliciesPagedResponse |
listPolicies(String parent)
public final PoliciesClient.ListPoliciesPagedResponse listPolicies(String parent)
Retrieves the policies of the specified kind that are attached to a resource.
The response lists only policy metadata. In particular, policy rules are omitted.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
String parent = "parent-995424086";
for (Policy element : policiesClient.listPolicies(parent).iterateAll()) {
// doThingsWith(element);
}
}
Parameter | |
---|---|
Name | Description |
parent | String Required. The resource that the policy is attached to, along with the kind of
policy to list. Format: The attachment point is identified by its URL-encoded full resource name, which means
that the forward-slash character, For organizations and folders, use the numeric ID in the full resource name. For projects, you can use the alphanumeric or the numeric ID. |
Returns | |
---|---|
Type | Description |
PoliciesClient.ListPoliciesPagedResponse |
listPoliciesCallable()
public final UnaryCallable<ListPoliciesRequest,ListPoliciesResponse> listPoliciesCallable()
Retrieves the policies of the specified kind that are attached to a resource.
The response lists only policy metadata. In particular, policy rules are omitted.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
ListPoliciesRequest request =
ListPoliciesRequest.newBuilder()
.setParent("parent-995424086")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
while (true) {
ListPoliciesResponse response = policiesClient.listPoliciesCallable().call(request);
for (Policy element : response.getPoliciesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
Returns | |
---|---|
Type | Description |
UnaryCallable<ListPoliciesRequest,ListPoliciesResponse> |
listPoliciesPagedCallable()
public final UnaryCallable<ListPoliciesRequest,PoliciesClient.ListPoliciesPagedResponse> listPoliciesPagedCallable()
Retrieves the policies of the specified kind that are attached to a resource.
The response lists only policy metadata. In particular, policy rules are omitted.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
ListPoliciesRequest request =
ListPoliciesRequest.newBuilder()
.setParent("parent-995424086")
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
ApiFuture<Policy> future = policiesClient.listPoliciesPagedCallable().futureCall(request);
// Do something.
for (Policy element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
Returns | |
---|---|
Type | Description |
UnaryCallable<ListPoliciesRequest,ListPoliciesPagedResponse> |
shutdown()
public void shutdown()
shutdownNow()
public void shutdownNow()
updatePolicyAsync(UpdatePolicyRequest request)
public final OperationFuture<Policy,PolicyOperationMetadata> updatePolicyAsync(UpdatePolicyRequest request)
Updates the specified policy.
You can update only the rules and the display name for the policy.
To update a policy, you should use a read-modify-write loop:
1. Use GetPolicy to read the current version of the
policy. 2. Modify the policy as needed. 3. Use UpdatePolicy
to write the updated policy.
This pattern helps prevent conflicts between concurrent updates.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
UpdatePolicyRequest request =
UpdatePolicyRequest.newBuilder().setPolicy(Policy.newBuilder().build()).build();
Policy response = policiesClient.updatePolicyAsync(request).get();
}
Parameter | |
---|---|
Name | Description |
request | UpdatePolicyRequest The request object containing all of the parameters for the API call. |
Returns | |
---|---|
Type | Description |
OperationFuture<Policy,PolicyOperationMetadata> |
updatePolicyCallable()
public final UnaryCallable<UpdatePolicyRequest,Operation> updatePolicyCallable()
Updates the specified policy.
You can update only the rules and the display name for the policy.
To update a policy, you should use a read-modify-write loop:
1. Use GetPolicy to read the current version of the
policy. 2. Modify the policy as needed. 3. Use UpdatePolicy
to write the updated policy.
This pattern helps prevent conflicts between concurrent updates.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
UpdatePolicyRequest request =
UpdatePolicyRequest.newBuilder().setPolicy(Policy.newBuilder().build()).build();
ApiFuture<Operation> future = policiesClient.updatePolicyCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
Returns | |
---|---|
Type | Description |
UnaryCallable<UpdatePolicyRequest,Operation> |
updatePolicyOperationCallable()
public final OperationCallable<UpdatePolicyRequest,Policy,PolicyOperationMetadata> updatePolicyOperationCallable()
Updates the specified policy.
You can update only the rules and the display name for the policy.
To update a policy, you should use a read-modify-write loop:
1. Use GetPolicy to read the current version of the
policy. 2. Modify the policy as needed. 3. Use UpdatePolicy
to write the updated policy.
This pattern helps prevent conflicts between concurrent updates.
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 (PoliciesClient policiesClient = PoliciesClient.create()) {
UpdatePolicyRequest request =
UpdatePolicyRequest.newBuilder().setPolicy(Policy.newBuilder().build()).build();
OperationFuture<Policy, PolicyOperationMetadata> future =
policiesClient.updatePolicyOperationCallable().futureCall(request);
// Do something.
Policy response = future.get();
}
Returns | |
---|---|
Type | Description |
OperationCallable<UpdatePolicyRequest,Policy,PolicyOperationMetadata> |