@Generated(value="by gapic-generator-java") public class OrgPolicyClient extends Object implements BackgroundResource
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:
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:
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:
OrgPolicySettings orgPolicySettings =
OrgPolicySettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
OrgPolicyClient orgPolicyClient = OrgPolicyClient.create(orgPolicySettings);
To customize the endpoint:
OrgPolicySettings orgPolicySettings =
OrgPolicySettings.newBuilder().setEndpoint(myEndpoint).build();
OrgPolicyClient orgPolicyClient = OrgPolicyClient.create(orgPolicySettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Modifier and Type | Class and Description |
---|---|
static class |
OrgPolicyClient.ListConstraintsFixedSizeCollection |
static class |
OrgPolicyClient.ListConstraintsPage |
static class |
OrgPolicyClient.ListConstraintsPagedResponse |
static class |
OrgPolicyClient.ListPoliciesFixedSizeCollection |
static class |
OrgPolicyClient.ListPoliciesPage |
static class |
OrgPolicyClient.ListPoliciesPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
OrgPolicyClient(OrgPolicySettings settings)
Constructs an instance of OrgPolicyClient, using the given settings.
|
protected |
OrgPolicyClient(OrgPolicyStub stub) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static OrgPolicyClient |
create()
Constructs an instance of OrgPolicyClient with default settings.
|
static OrgPolicyClient |
create(OrgPolicySettings settings)
Constructs an instance of OrgPolicyClient, using the given settings.
|
static OrgPolicyClient |
create(OrgPolicyStub stub)
Constructs an instance of OrgPolicyClient, using the given stub for making calls.
|
Policy |
createPolicy(CreatePolicyRequest request)
Creates a Policy.
|
Policy |
createPolicy(FolderName parent,
Policy policy)
Creates a Policy.
|
Policy |
createPolicy(OrganizationName parent,
Policy policy)
Creates a Policy.
|
Policy |
createPolicy(ProjectName parent,
Policy policy)
Creates a Policy.
|
Policy |
createPolicy(String parent,
Policy policy)
Creates a Policy.
|
UnaryCallable<CreatePolicyRequest,Policy> |
createPolicyCallable()
Creates a Policy.
|
void |
deletePolicy(DeletePolicyRequest request)
Deletes a Policy.
|
void |
deletePolicy(PolicyName name)
Deletes a Policy.
|
void |
deletePolicy(String name)
Deletes a Policy.
|
UnaryCallable<DeletePolicyRequest,Empty> |
deletePolicyCallable()
Deletes a Policy.
|
Policy |
getEffectivePolicy(GetEffectivePolicyRequest request)
Gets the effective `Policy` on a resource.
|
Policy |
getEffectivePolicy(PolicyName name)
Gets the effective `Policy` on a resource.
|
Policy |
getEffectivePolicy(String name)
Gets the effective `Policy` on a resource.
|
UnaryCallable<GetEffectivePolicyRequest,Policy> |
getEffectivePolicyCallable()
Gets the effective `Policy` on a resource.
|
Policy |
getPolicy(GetPolicyRequest request)
Gets a `Policy` on a resource.
|
Policy |
getPolicy(PolicyName name)
Gets a `Policy` on a resource.
|
Policy |
getPolicy(String name)
Gets a `Policy` on a resource.
|
UnaryCallable<GetPolicyRequest,Policy> |
getPolicyCallable()
Gets a `Policy` on a resource.
|
OrgPolicySettings |
getSettings() |
OrgPolicyStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
OrgPolicyClient.ListConstraintsPagedResponse |
listConstraints(FolderName parent)
Lists `Constraints` that could be applied on the specified resource.
|
OrgPolicyClient.ListConstraintsPagedResponse |
listConstraints(ListConstraintsRequest request)
Lists `Constraints` that could be applied on the specified resource.
|
OrgPolicyClient.ListConstraintsPagedResponse |
listConstraints(OrganizationName parent)
Lists `Constraints` that could be applied on the specified resource.
|
OrgPolicyClient.ListConstraintsPagedResponse |
listConstraints(ProjectName parent)
Lists `Constraints` that could be applied on the specified resource.
|
OrgPolicyClient.ListConstraintsPagedResponse |
listConstraints(String parent)
Lists `Constraints` that could be applied on the specified resource.
|
UnaryCallable<ListConstraintsRequest,ListConstraintsResponse> |
listConstraintsCallable()
Lists `Constraints` that could be applied on the specified resource.
|
UnaryCallable<ListConstraintsRequest,OrgPolicyClient.ListConstraintsPagedResponse> |
listConstraintsPagedCallable()
Lists `Constraints` that could be applied on the specified resource.
|
OrgPolicyClient.ListPoliciesPagedResponse |
listPolicies(FolderName parent)
Retrieves all of the `Policies` that exist on a particular resource.
|
OrgPolicyClient.ListPoliciesPagedResponse |
listPolicies(ListPoliciesRequest request)
Retrieves all of the `Policies` that exist on a particular resource.
|
OrgPolicyClient.ListPoliciesPagedResponse |
listPolicies(OrganizationName parent)
Retrieves all of the `Policies` that exist on a particular resource.
|
OrgPolicyClient.ListPoliciesPagedResponse |
listPolicies(ProjectName parent)
Retrieves all of the `Policies` that exist on a particular resource.
|
OrgPolicyClient.ListPoliciesPagedResponse |
listPolicies(String parent)
Retrieves all of the `Policies` that exist on a particular resource.
|
UnaryCallable<ListPoliciesRequest,ListPoliciesResponse> |
listPoliciesCallable()
Retrieves all of the `Policies` that exist on a particular resource.
|
UnaryCallable<ListPoliciesRequest,OrgPolicyClient.ListPoliciesPagedResponse> |
listPoliciesPagedCallable()
Retrieves all of the `Policies` that exist on a particular resource.
|
void |
shutdown() |
void |
shutdownNow() |
Policy |
updatePolicy(Policy policy)
Updates a Policy.
|
Policy |
updatePolicy(UpdatePolicyRequest request)
Updates a Policy.
|
UnaryCallable<UpdatePolicyRequest,Policy> |
updatePolicyCallable()
Updates a Policy.
|
protected OrgPolicyClient(OrgPolicySettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected OrgPolicyClient(OrgPolicyStub stub)
public static final OrgPolicyClient create() throws IOException
IOException
public static final OrgPolicyClient create(OrgPolicySettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final OrgPolicyClient create(OrgPolicyStub stub)
public final OrgPolicySettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public OrgPolicyStub getStub()
public final OrgPolicyClient.ListConstraintsPagedResponse listConstraints(FolderName parent)
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
FolderName parent = FolderName.of("[FOLDER]");
for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The Cloud resource that parents the constraint. Must be in one of the
following forms:
ApiException
- if the remote call failspublic final OrgPolicyClient.ListConstraintsPagedResponse listConstraints(OrganizationName parent)
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The Cloud resource that parents the constraint. Must be in one of the
following forms:
ApiException
- if the remote call failspublic final OrgPolicyClient.ListConstraintsPagedResponse listConstraints(ProjectName parent)
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The Cloud resource that parents the constraint. Must be in one of the
following forms:
ApiException
- if the remote call failspublic final OrgPolicyClient.ListConstraintsPagedResponse listConstraints(String parent)
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
String parent =
ConstraintName.ofProjectConstraintName("[PROJECT]", "[CONSTRAINT]").toString();
for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The Cloud resource that parents the constraint. Must be in one of the
following forms:
ApiException
- if the remote call failspublic final OrgPolicyClient.ListConstraintsPagedResponse listConstraints(ListConstraintsRequest request)
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
ListConstraintsRequest request =
ListConstraintsRequest.newBuilder()
.setParent(
ConstraintName.ofProjectConstraintName("[PROJECT]", "[CONSTRAINT]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for (Constraint element : orgPolicyClient.listConstraints(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<ListConstraintsRequest,OrgPolicyClient.ListConstraintsPagedResponse> listConstraintsPagedCallable()
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
ListConstraintsRequest request =
ListConstraintsRequest.newBuilder()
.setParent(
ConstraintName.ofProjectConstraintName("[PROJECT]", "[CONSTRAINT]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
ApiFuture<Constraint> future =
orgPolicyClient.listConstraintsPagedCallable().futureCall(request);
// Do something.
for (Constraint element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<ListConstraintsRequest,ListConstraintsResponse> listConstraintsCallable()
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
ListConstraintsRequest request =
ListConstraintsRequest.newBuilder()
.setParent(
ConstraintName.ofProjectConstraintName("[PROJECT]", "[CONSTRAINT]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
while (true) {
ListConstraintsResponse response = orgPolicyClient.listConstraintsCallable().call(request);
for (Constraint element : response.getResponsesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final OrgPolicyClient.ListPoliciesPagedResponse listPolicies(FolderName parent)
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
FolderName parent = FolderName.of("[FOLDER]");
for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- 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:
ApiException
- if the remote call failspublic final OrgPolicyClient.ListPoliciesPagedResponse listPolicies(OrganizationName parent)
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- 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:
ApiException
- if the remote call failspublic final OrgPolicyClient.ListPoliciesPagedResponse listPolicies(ProjectName parent)
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- 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:
ApiException
- if the remote call failspublic final OrgPolicyClient.ListPoliciesPagedResponse listPolicies(String parent)
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
String parent = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString();
for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- 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:
ApiException
- if the remote call failspublic final OrgPolicyClient.ListPoliciesPagedResponse listPolicies(ListPoliciesRequest request)
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
ListPoliciesRequest request =
ListPoliciesRequest.newBuilder()
.setParent(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for (Policy element : orgPolicyClient.listPolicies(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<ListPoliciesRequest,OrgPolicyClient.ListPoliciesPagedResponse> listPoliciesPagedCallable()
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
ListPoliciesRequest request =
ListPoliciesRequest.newBuilder()
.setParent(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
ApiFuture<Policy> future = orgPolicyClient.listPoliciesPagedCallable().futureCall(request);
// Do something.
for (Policy element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<ListPoliciesRequest,ListPoliciesResponse> listPoliciesCallable()
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
ListPoliciesRequest request =
ListPoliciesRequest.newBuilder()
.setParent(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
while (true) {
ListPoliciesResponse response = orgPolicyClient.listPoliciesCallable().call(request);
for (Policy element : response.getResponsesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final Policy getPolicy(PolicyName name)
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:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]");
Policy response = orgPolicyClient.getPolicy(name);
}
name
- Required. Resource name of the policy. See `Policy` for naming requirements.ApiException
- if the remote call failspublic final Policy getPolicy(String name)
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:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
String name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString();
Policy response = orgPolicyClient.getPolicy(name);
}
name
- Required. Resource name of the policy. See `Policy` for naming requirements.ApiException
- if the remote call failspublic final Policy getPolicy(GetPolicyRequest request)
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:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
GetPolicyRequest request =
GetPolicyRequest.newBuilder()
.setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString())
.build();
Policy response = orgPolicyClient.getPolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<GetPolicyRequest,Policy> getPolicyCallable()
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:
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();
}
public final Policy getEffectivePolicy(PolicyName name)
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]");
Policy response = orgPolicyClient.getEffectivePolicy(name);
}
name
- Required. The effective policy to compute. See `Policy` for naming rules.ApiException
- if the remote call failspublic final Policy getEffectivePolicy(String name)
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
String name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString();
Policy response = orgPolicyClient.getEffectivePolicy(name);
}
name
- Required. The effective policy to compute. See `Policy` for naming rules.ApiException
- if the remote call failspublic final Policy getEffectivePolicy(GetEffectivePolicyRequest request)
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
GetEffectivePolicyRequest request =
GetEffectivePolicyRequest.newBuilder()
.setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString())
.build();
Policy response = orgPolicyClient.getEffectivePolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<GetEffectivePolicyRequest,Policy> getEffectivePolicyCallable()
Sample code:
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();
}
public final Policy createPolicy(FolderName parent, Policy 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:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
FolderName parent = FolderName.of("[FOLDER]");
Policy policy = Policy.newBuilder().build();
Policy response = orgPolicyClient.createPolicy(parent, policy);
}
parent
- Required. The Cloud resource that will parent the new Policy. Must be in one of
the following forms:
policy
- Required. `Policy` to create.ApiException
- if the remote call failspublic final Policy createPolicy(OrganizationName parent, Policy 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:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
OrganizationName parent = OrganizationName.of("[ORGANIZATION]");
Policy policy = Policy.newBuilder().build();
Policy response = orgPolicyClient.createPolicy(parent, policy);
}
parent
- Required. The Cloud resource that will parent the new Policy. Must be in one of
the following forms:
policy
- Required. `Policy` to create.ApiException
- if the remote call failspublic final Policy createPolicy(ProjectName parent, Policy 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:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
Policy policy = Policy.newBuilder().build();
Policy response = orgPolicyClient.createPolicy(parent, policy);
}
parent
- Required. The Cloud resource that will parent the new Policy. Must be in one of
the following forms:
policy
- Required. `Policy` to create.ApiException
- if the remote call failspublic final Policy createPolicy(String parent, Policy 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:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
String parent = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString();
Policy policy = Policy.newBuilder().build();
Policy response = orgPolicyClient.createPolicy(parent, policy);
}
parent
- Required. The Cloud resource that will parent the new Policy. Must be in one of
the following forms:
policy
- Required. `Policy` to create.ApiException
- if the remote call failspublic final Policy createPolicy(CreatePolicyRequest request)
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:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
CreatePolicyRequest request =
CreatePolicyRequest.newBuilder()
.setParent(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString())
.setPolicy(Policy.newBuilder().build())
.build();
Policy response = orgPolicyClient.createPolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<CreatePolicyRequest,Policy> createPolicyCallable()
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:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
CreatePolicyRequest request =
CreatePolicyRequest.newBuilder()
.setParent(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString())
.setPolicy(Policy.newBuilder().build())
.build();
ApiFuture<Policy> future = orgPolicyClient.createPolicyCallable().futureCall(request);
// Do something.
Policy response = future.get();
}
public final Policy updatePolicy(Policy 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:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
Policy policy = Policy.newBuilder().build();
Policy response = orgPolicyClient.updatePolicy(policy);
}
policy
- Required. `Policy` to update.ApiException
- if the remote call failspublic final Policy updatePolicy(UpdatePolicyRequest request)
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:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
UpdatePolicyRequest request =
UpdatePolicyRequest.newBuilder().setPolicy(Policy.newBuilder().build()).build();
Policy response = orgPolicyClient.updatePolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<UpdatePolicyRequest,Policy> updatePolicyCallable()
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:
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();
}
public final void deletePolicy(PolicyName name)
Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or Org Policy does not exist.
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]");
orgPolicyClient.deletePolicy(name);
}
name
- Required. Name of the policy to delete. See `Policy` for naming rules.ApiException
- if the remote call failspublic final void deletePolicy(String name)
Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or Org Policy does not exist.
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
String name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString();
orgPolicyClient.deletePolicy(name);
}
name
- Required. Name of the policy to delete. See `Policy` for naming rules.ApiException
- if the remote call failspublic final void deletePolicy(DeletePolicyRequest request)
Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or Org Policy does not exist.
Sample code:
try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) {
DeletePolicyRequest request =
DeletePolicyRequest.newBuilder()
.setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString())
.build();
orgPolicyClient.deletePolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<DeletePolicyRequest,Empty> deletePolicyCallable()
Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or Org Policy does not exist.
Sample code:
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();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2021 Google LLC. All rights reserved.