Class OrgPolicyClient (2.3.0)

public class OrgPolicyClient implements BackgroundResource

Service Description: An interface for managing organization policies.

The Cloud Org Policy service provides a simple mechanism for organizations to restrict the allowed configurations across their entire Cloud Resource hierarchy.

You can use a policy to configure restrictions in Cloud resources. For example, you can enforce a policy that restricts which Google Cloud Platform APIs can be activated in a certain part of your resource hierarchy, or prevents serial port access to VM instances in a particular folder.

Policies are inherited down through the resource hierarchy. A policy applied to a parent resource automatically applies to all its child resources unless overridden with a policy lower in the hierarchy.

A constraint defines an aspect of a resource's configuration that can be controlled by an organization's policy administrator. Policies are a collection of constraints that defines their allowable configuration on a particular resource and its child resources.

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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]");
   Policy response = orgPolicyClient.getPolicy(name);
 }
 

Note: close() needs to be called on the OrgPolicyClient 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:

  1. 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.
  2. 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.
  3. 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 OrgPolicySettings to create(). For example:

To customize credentials:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 OrgPolicySettings orgPolicySettings =
     OrgPolicySettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 OrgPolicyClient orgPolicyClient = OrgPolicyClient.create(orgPolicySettings);
 

To customize the endpoint:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 OrgPolicySettings orgPolicySettings =
     OrgPolicySettings.newBuilder().setEndpoint(myEndpoint).build();
 OrgPolicyClient orgPolicyClient = OrgPolicyClient.create(orgPolicySettings);
 

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 OrgPolicySettings orgPolicySettings =
     OrgPolicySettings.newBuilder()
         .setTransportChannelProvider(
             OrgPolicySettings.defaultHttpJsonTransportProviderBuilder().build())
         .build();
 OrgPolicyClient orgPolicyClient = OrgPolicyClient.create(orgPolicySettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > OrgPolicyClient

Implements

BackgroundResource

Static Methods

create()

public static final OrgPolicyClient create()

Constructs an instance of OrgPolicyClient with default settings.

Returns
TypeDescription
OrgPolicyClient
Exceptions
TypeDescription
IOException

create(OrgPolicySettings settings)

public static final OrgPolicyClient create(OrgPolicySettings settings)

Constructs an instance of OrgPolicyClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
NameDescription
settingsOrgPolicySettings
Returns
TypeDescription
OrgPolicyClient
Exceptions
TypeDescription
IOException

create(OrgPolicyStub stub)

public static final OrgPolicyClient create(OrgPolicyStub stub)

Constructs an instance of OrgPolicyClient, using the given stub for making calls. This is for advanced usage - prefer using create(OrgPolicySettings).

Parameter
NameDescription
stubOrgPolicyStub
Returns
TypeDescription
OrgPolicyClient

Constructors

OrgPolicyClient(OrgPolicySettings settings)

protected OrgPolicyClient(OrgPolicySettings settings)

Constructs an instance of OrgPolicyClient, 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
NameDescription
settingsOrgPolicySettings

OrgPolicyClient(OrgPolicyStub stub)

protected OrgPolicyClient(OrgPolicyStub stub)
Parameter
NameDescription
stubOrgPolicyStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
NameDescription
durationlong
unitTimeUnit
Returns
TypeDescription
boolean
Exceptions
TypeDescription
InterruptedException

close()

public final void close()

createPolicy(CreatePolicyRequest request)

public final Policy createPolicy(CreatePolicyRequest request)

Creates a Policy.

Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint does not exist. Returns a google.rpc.Status with google.rpc.Code.ALREADY_EXISTS if the policy already exists on the given Cloud resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   CreatePolicyRequest request =
       CreatePolicyRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPolicy(Policy.newBuilder().build())
           .build();
   Policy response = orgPolicyClient.createPolicy(request);
 }
 
Parameter
NameDescription
requestCreatePolicyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Policy

createPolicy(FolderName parent, Policy policy)

public final Policy createPolicy(FolderName parent, Policy policy)

Creates a Policy.

Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint does not exist. Returns a google.rpc.Status with google.rpc.Code.ALREADY_EXISTS if the policy already exists on the given Cloud resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   FolderName parent = FolderName.of("[FOLDER]");
   Policy policy = Policy.newBuilder().build();
   Policy response = orgPolicyClient.createPolicy(parent, policy);
 }
 
Parameters
NameDescription
parentFolderName

Required. The Cloud resource that will parent the new Policy. Must be in one of the following forms:

  • projects/{project_number}
  • projects/{project_id}
  • folders/{folder_id}
  • organizations/{organization_id}

policyPolicy

Required. Policy to create.

Returns
TypeDescription
Policy

createPolicy(OrganizationName parent, Policy policy)

public final Policy createPolicy(OrganizationName parent, Policy policy)

Creates a Policy.

Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint does not exist. Returns a google.rpc.Status with google.rpc.Code.ALREADY_EXISTS if the policy already exists on the given Cloud resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
   Policy policy = Policy.newBuilder().build();
   Policy response = orgPolicyClient.createPolicy(parent, policy);
 }
 
Parameters
NameDescription
parentOrganizationName

Required. The Cloud resource that will parent the new Policy. Must be in one of the following forms:

  • projects/{project_number}
  • projects/{project_id}
  • folders/{folder_id}
  • organizations/{organization_id}

policyPolicy

Required. Policy to create.

Returns
TypeDescription
Policy

createPolicy(ProjectName parent, Policy policy)

public final Policy createPolicy(ProjectName parent, Policy policy)

Creates a Policy.

Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint does not exist. Returns a google.rpc.Status with google.rpc.Code.ALREADY_EXISTS if the policy already exists on the given Cloud resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   ProjectName parent = ProjectName.of("[PROJECT]");
   Policy policy = Policy.newBuilder().build();
   Policy response = orgPolicyClient.createPolicy(parent, policy);
 }
 
Parameters
NameDescription
parentProjectName

Required. The Cloud resource that will parent the new Policy. Must be in one of the following forms:

  • projects/{project_number}
  • projects/{project_id}
  • folders/{folder_id}
  • organizations/{organization_id}

policyPolicy

Required. Policy to create.

Returns
TypeDescription
Policy

createPolicy(String parent, Policy policy)

public final Policy createPolicy(String parent, Policy policy)

Creates a Policy.

Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint does not exist. Returns a google.rpc.Status with google.rpc.Code.ALREADY_EXISTS if the policy already exists on the given Cloud resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   String parent = ProjectName.of("[PROJECT]").toString();
   Policy policy = Policy.newBuilder().build();
   Policy response = orgPolicyClient.createPolicy(parent, policy);
 }
 
Parameters
NameDescription
parentString

Required. The Cloud resource that will parent the new Policy. Must be in one of the following forms:

  • projects/{project_number}
  • projects/{project_id}
  • folders/{folder_id}
  • organizations/{organization_id}

policyPolicy

Required. Policy to create.

Returns
TypeDescription
Policy

createPolicyCallable()

public final UnaryCallable<CreatePolicyRequest,Policy> createPolicyCallable()

Creates a Policy.

Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint does not exist. Returns a google.rpc.Status with google.rpc.Code.ALREADY_EXISTS if the policy already exists on the given Cloud resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   CreatePolicyRequest request =
       CreatePolicyRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPolicy(Policy.newBuilder().build())
           .build();
   ApiFuture<Policy> future = orgPolicyClient.createPolicyCallable().futureCall(request);
   // Do something.
   Policy response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<CreatePolicyRequest,Policy>

deletePolicy(DeletePolicyRequest request)

public final void deletePolicy(DeletePolicyRequest request)

Deletes a Policy.

Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint or Org Policy does not exist.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   DeletePolicyRequest request =
       DeletePolicyRequest.newBuilder()
           .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString())
           .build();
   orgPolicyClient.deletePolicy(request);
 }
 
Parameter
NameDescription
requestDeletePolicyRequest

The request object containing all of the parameters for the API call.

deletePolicy(PolicyName name)

public final void deletePolicy(PolicyName name)

Deletes a Policy.

Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint or Org Policy does not exist.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]");
   orgPolicyClient.deletePolicy(name);
 }
 
Parameter
NameDescription
namePolicyName

Required. Name of the policy to delete. See Policy for naming rules.

deletePolicy(String name)

public final void deletePolicy(String name)

Deletes a Policy.

Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint or Org Policy does not exist.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   String name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString();
   orgPolicyClient.deletePolicy(name);
 }
 
Parameter
NameDescription
nameString

Required. Name of the policy to delete. See Policy for naming rules.

deletePolicyCallable()

public final UnaryCallable<DeletePolicyRequest,Empty> deletePolicyCallable()

Deletes a Policy.

Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint or Org Policy does not exist.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   DeletePolicyRequest request =
       DeletePolicyRequest.newBuilder()
           .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString())
           .build();
   ApiFuture<Empty> future = orgPolicyClient.deletePolicyCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
UnaryCallable<DeletePolicyRequest,Empty>

getEffectivePolicy(GetEffectivePolicyRequest request)

public final Policy getEffectivePolicy(GetEffectivePolicyRequest request)

Gets the effective Policy on a resource. This is the result of merging Policies in the resource hierarchy and evaluating conditions. The returned Policy will not have an etag or condition set because it is a computed Policy across multiple resources. Subtrees of Resource Manager resource hierarchy with 'under:' prefix will not be expanded.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   GetEffectivePolicyRequest request =
       GetEffectivePolicyRequest.newBuilder()
           .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString())
           .build();
   Policy response = orgPolicyClient.getEffectivePolicy(request);
 }
 
Parameter
NameDescription
requestGetEffectivePolicyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Policy

getEffectivePolicy(PolicyName name)

public final Policy getEffectivePolicy(PolicyName name)

Gets the effective Policy on a resource. This is the result of merging Policies in the resource hierarchy and evaluating conditions. The returned Policy will not have an etag or condition set because it is a computed Policy across multiple resources. Subtrees of Resource Manager resource hierarchy with 'under:' prefix will not be expanded.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]");
   Policy response = orgPolicyClient.getEffectivePolicy(name);
 }
 
Parameter
NameDescription
namePolicyName

Required. The effective policy to compute. See Policy for naming rules.

Returns
TypeDescription
Policy

getEffectivePolicy(String name)

public final Policy getEffectivePolicy(String name)

Gets the effective Policy on a resource. This is the result of merging Policies in the resource hierarchy and evaluating conditions. The returned Policy will not have an etag or condition set because it is a computed Policy across multiple resources. Subtrees of Resource Manager resource hierarchy with 'under:' prefix will not be expanded.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   String name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString();
   Policy response = orgPolicyClient.getEffectivePolicy(name);
 }
 
Parameter
NameDescription
nameString

Required. The effective policy to compute. See Policy for naming rules.

Returns
TypeDescription
Policy

getEffectivePolicyCallable()

public final UnaryCallable<GetEffectivePolicyRequest,Policy> getEffectivePolicyCallable()

Gets the effective Policy on a resource. This is the result of merging Policies in the resource hierarchy and evaluating conditions. The returned Policy will not have an etag or condition set because it is a computed Policy across multiple resources. Subtrees of Resource Manager resource hierarchy with 'under:' prefix will not be expanded.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   GetEffectivePolicyRequest request =
       GetEffectivePolicyRequest.newBuilder()
           .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString())
           .build();
   ApiFuture<Policy> future = orgPolicyClient.getEffectivePolicyCallable().futureCall(request);
   // Do something.
   Policy response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<GetEffectivePolicyRequest,Policy>

getPolicy(GetPolicyRequest request)

public final Policy getPolicy(GetPolicyRequest request)

Gets a Policy on a resource.

If no Policy is set on the resource, NOT_FOUND is returned. The etag value can be used with UpdatePolicy() to update a Policy during read-modify-write.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   GetPolicyRequest request =
       GetPolicyRequest.newBuilder()
           .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString())
           .build();
   Policy response = orgPolicyClient.getPolicy(request);
 }
 
Parameter
NameDescription
requestGetPolicyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Policy

getPolicy(PolicyName name)

public final Policy getPolicy(PolicyName name)

Gets a Policy on a resource.

If no Policy is set on the resource, NOT_FOUND is returned. The etag value can be used with UpdatePolicy() to update a Policy during read-modify-write.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]");
   Policy response = orgPolicyClient.getPolicy(name);
 }
 
Parameter
NameDescription
namePolicyName

Required. Resource name of the policy. See Policy for naming requirements.

Returns
TypeDescription
Policy

getPolicy(String name)

public final Policy getPolicy(String name)

Gets a Policy on a resource.

If no Policy is set on the resource, NOT_FOUND is returned. The etag value can be used with UpdatePolicy() to update a Policy during read-modify-write.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   String name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString();
   Policy response = orgPolicyClient.getPolicy(name);
 }
 
Parameter
NameDescription
nameString

Required. Resource name of the policy. See Policy for naming requirements.

Returns
TypeDescription
Policy

getPolicyCallable()

public final UnaryCallable<GetPolicyRequest,Policy> getPolicyCallable()

Gets a Policy on a resource.

If no Policy is set on the resource, NOT_FOUND is returned. The etag value can be used with UpdatePolicy() to update a Policy during read-modify-write.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   GetPolicyRequest request =
       GetPolicyRequest.newBuilder()
           .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString())
           .build();
   ApiFuture<Policy> future = orgPolicyClient.getPolicyCallable().futureCall(request);
   // Do something.
   Policy response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<GetPolicyRequest,Policy>

getSettings()

public final OrgPolicySettings getSettings()
Returns
TypeDescription
OrgPolicySettings

getStub()

public OrgPolicyStub getStub()
Returns
TypeDescription
OrgPolicyStub

isShutdown()

public boolean isShutdown()
Returns
TypeDescription
boolean

isTerminated()

public boolean isTerminated()
Returns
TypeDescription
boolean

listConstraints(FolderName parent)

public final OrgPolicyClient.ListConstraintsPagedResponse listConstraints(FolderName parent)

Lists Constraints that could be applied on the specified resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   FolderName parent = FolderName.of("[FOLDER]");
   for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentFolderName

Required. The Cloud resource that parents the constraint. Must be in one of the following forms:

  • projects/{project_number}
  • projects/{project_id}
  • folders/{folder_id}
  • organizations/{organization_id}

Returns
TypeDescription
OrgPolicyClient.ListConstraintsPagedResponse

listConstraints(ListConstraintsRequest request)

public final OrgPolicyClient.ListConstraintsPagedResponse listConstraints(ListConstraintsRequest request)

Lists Constraints that could be applied on the specified resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   ListConstraintsRequest request =
       ListConstraintsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   for (Constraint element : orgPolicyClient.listConstraints(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
requestListConstraintsRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
OrgPolicyClient.ListConstraintsPagedResponse

listConstraints(OrganizationName parent)

public final OrgPolicyClient.ListConstraintsPagedResponse listConstraints(OrganizationName parent)

Lists Constraints that could be applied on the specified resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
   for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentOrganizationName

Required. The Cloud resource that parents the constraint. Must be in one of the following forms:

  • projects/{project_number}
  • projects/{project_id}
  • folders/{folder_id}
  • organizations/{organization_id}

Returns
TypeDescription
OrgPolicyClient.ListConstraintsPagedResponse

listConstraints(ProjectName parent)

public final OrgPolicyClient.ListConstraintsPagedResponse listConstraints(ProjectName parent)

Lists Constraints that could be applied on the specified resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   ProjectName parent = ProjectName.of("[PROJECT]");
   for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentProjectName

Required. The Cloud resource that parents the constraint. Must be in one of the following forms:

  • projects/{project_number}
  • projects/{project_id}
  • folders/{folder_id}
  • organizations/{organization_id}

Returns
TypeDescription
OrgPolicyClient.ListConstraintsPagedResponse

listConstraints(String parent)

public final OrgPolicyClient.ListConstraintsPagedResponse listConstraints(String parent)

Lists Constraints that could be applied on the specified resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   String parent = ProjectName.of("[PROJECT]").toString();
   for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentString

Required. The Cloud resource that parents the constraint. Must be in one of the following forms:

  • projects/{project_number}
  • projects/{project_id}
  • folders/{folder_id}
  • organizations/{organization_id}

Returns
TypeDescription
OrgPolicyClient.ListConstraintsPagedResponse

listConstraintsCallable()

public final UnaryCallable<ListConstraintsRequest,ListConstraintsResponse> listConstraintsCallable()

Lists Constraints that could be applied on the specified resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   ListConstraintsRequest request =
       ListConstraintsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   while (true) {
     ListConstraintsResponse response = orgPolicyClient.listConstraintsCallable().call(request);
     for (Constraint element : response.getConstraintsList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListConstraintsRequest,ListConstraintsResponse>

listConstraintsPagedCallable()

public final UnaryCallable<ListConstraintsRequest,OrgPolicyClient.ListConstraintsPagedResponse> listConstraintsPagedCallable()

Lists Constraints that could be applied on the specified resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   ListConstraintsRequest request =
       ListConstraintsRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   ApiFuture<Constraint> future =
       orgPolicyClient.listConstraintsPagedCallable().futureCall(request);
   // Do something.
   for (Constraint element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListConstraintsRequest,ListConstraintsPagedResponse>

listPolicies(FolderName parent)

public final OrgPolicyClient.ListPoliciesPagedResponse listPolicies(FolderName parent)

Retrieves all of the Policies that exist on a particular resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   FolderName parent = FolderName.of("[FOLDER]");
   for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentFolderName

Required. The target Cloud resource that parents the set of constraints and policies that will be returned from this call. Must be in one of the following forms:

  • projects/{project_number}
  • projects/{project_id}
  • folders/{folder_id}
  • organizations/{organization_id}

Returns
TypeDescription
OrgPolicyClient.ListPoliciesPagedResponse

listPolicies(ListPoliciesRequest request)

public final OrgPolicyClient.ListPoliciesPagedResponse listPolicies(ListPoliciesRequest request)

Retrieves all of the Policies that exist on a particular resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   ListPoliciesRequest request =
       ListPoliciesRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   for (Policy element : orgPolicyClient.listPolicies(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
requestListPoliciesRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
OrgPolicyClient.ListPoliciesPagedResponse

listPolicies(OrganizationName parent)

public final OrgPolicyClient.ListPoliciesPagedResponse listPolicies(OrganizationName parent)

Retrieves all of the Policies that exist on a particular resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
   for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentOrganizationName

Required. The target Cloud resource that parents the set of constraints and policies that will be returned from this call. Must be in one of the following forms:

  • projects/{project_number}
  • projects/{project_id}
  • folders/{folder_id}
  • organizations/{organization_id}

Returns
TypeDescription
OrgPolicyClient.ListPoliciesPagedResponse

listPolicies(ProjectName parent)

public final OrgPolicyClient.ListPoliciesPagedResponse listPolicies(ProjectName parent)

Retrieves all of the Policies that exist on a particular resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   ProjectName parent = ProjectName.of("[PROJECT]");
   for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentProjectName

Required. The target Cloud resource that parents the set of constraints and policies that will be returned from this call. Must be in one of the following forms:

  • projects/{project_number}
  • projects/{project_id}
  • folders/{folder_id}
  • organizations/{organization_id}

Returns
TypeDescription
OrgPolicyClient.ListPoliciesPagedResponse

listPolicies(String parent)

public final OrgPolicyClient.ListPoliciesPagedResponse listPolicies(String parent)

Retrieves all of the Policies that exist on a particular resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   String parent = ProjectName.of("[PROJECT]").toString();
   for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentString

Required. The target Cloud resource that parents the set of constraints and policies that will be returned from this call. Must be in one of the following forms:

  • projects/{project_number}
  • projects/{project_id}
  • folders/{folder_id}
  • organizations/{organization_id}

Returns
TypeDescription
OrgPolicyClient.ListPoliciesPagedResponse

listPoliciesCallable()

public final UnaryCallable<ListPoliciesRequest,ListPoliciesResponse> listPoliciesCallable()

Retrieves all of the Policies that exist on a particular resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   ListPoliciesRequest request =
       ListPoliciesRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   while (true) {
     ListPoliciesResponse response = orgPolicyClient.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
TypeDescription
UnaryCallable<ListPoliciesRequest,ListPoliciesResponse>

listPoliciesPagedCallable()

public final UnaryCallable<ListPoliciesRequest,OrgPolicyClient.ListPoliciesPagedResponse> listPoliciesPagedCallable()

Retrieves all of the Policies that exist on a particular resource.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   ListPoliciesRequest request =
       ListPoliciesRequest.newBuilder()
           .setParent(ProjectName.of("[PROJECT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   ApiFuture<Policy> future = orgPolicyClient.listPoliciesPagedCallable().futureCall(request);
   // Do something.
   for (Policy element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListPoliciesRequest,ListPoliciesPagedResponse>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()

updatePolicy(Policy policy)

public final Policy updatePolicy(Policy policy)

Updates a Policy.

Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint or the policy do not exist. Returns a google.rpc.Status with google.rpc.Code.ABORTED if the etag supplied in the request does not match the persisted etag of the policy

Note: the supplied policy will perform a full overwrite of all fields.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   Policy policy = Policy.newBuilder().build();
   Policy response = orgPolicyClient.updatePolicy(policy);
 }
 
Parameter
NameDescription
policyPolicy

Required. Policy to update.

Returns
TypeDescription
Policy

updatePolicy(UpdatePolicyRequest request)

public final Policy updatePolicy(UpdatePolicyRequest request)

Updates a Policy.

Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint or the policy do not exist. Returns a google.rpc.Status with google.rpc.Code.ABORTED if the etag supplied in the request does not match the persisted etag of the policy

Note: the supplied policy will perform a full overwrite of all fields.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   UpdatePolicyRequest request =
       UpdatePolicyRequest.newBuilder().setPolicy(Policy.newBuilder().build()).build();
   Policy response = orgPolicyClient.updatePolicy(request);
 }
 
Parameter
NameDescription
requestUpdatePolicyRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Policy

updatePolicyCallable()

public final UnaryCallable<UpdatePolicyRequest,Policy> updatePolicyCallable()

Updates a Policy.

Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the constraint or the policy do not exist. Returns a google.rpc.Status with google.rpc.Code.ABORTED if the etag supplied in the request does not match the persisted etag of the policy

Note: the supplied policy will perform a full overwrite of all fields.

Sample code:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
   UpdatePolicyRequest request =
       UpdatePolicyRequest.newBuilder().setPolicy(Policy.newBuilder().build()).build();
   ApiFuture<Policy> future = orgPolicyClient.updatePolicyCallable().futureCall(request);
   // Do something.
   Policy response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<UpdatePolicyRequest,Policy>