pub struct OrgPolicy { /* private fields */ }Expand description
Implements a client for the Organization Policy API.
§Example
use google_cloud_gax::paginator::ItemPaginator as _;
async fn sample(
project_id: &str,
) -> anyhow::Result<()> {
let client = OrgPolicy::builder().build().await?;
let mut list = client.list_constraints()
.set_parent(format!("projects/{project_id}"))
.by_item();
while let Some(item) = list.next().await.transpose()? {
println!("{:?}", item);
}
Ok(())
}§Service Description
An interface for managing organization policies.
The Organization Policy Service provides a simple mechanism for organizations to restrict the allowed configurations across their entire resource hierarchy.
You can use a policy to configure restrictions on resources. For example, you can enforce a policy that restricts which Google Cloud 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.
§Configuration
To configure OrgPolicy use the with_* methods in the type returned
by builder(). The default configuration should
work for most applications. Common configuration changes include
- with_endpoint(): by default this client uses the global default endpoint
(
https://orgpolicy.googleapis.com). Applications using regional endpoints or running in restricted networks (e.g. a network configured override this default. - with_credentials(): by default this client uses Application Default Credentials. Applications using custom authentication may need to override this default.
§Pooling and Cloning
OrgPolicy holds a connection pool internally, it is advised to
create one and reuse it. You do not need to wrap OrgPolicy in
an Rc or Arc to reuse it, because it
already uses an Arc internally.
Implementations§
Source§impl OrgPolicy
impl OrgPolicy
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Returns a builder for OrgPolicy.
let client = OrgPolicy::builder().build().await?;Sourcepub fn from_stub<T>(stub: impl Into<Arc<T>>) -> Selfwhere
T: OrgPolicy + 'static,
pub fn from_stub<T>(stub: impl Into<Arc<T>>) -> Selfwhere
T: OrgPolicy + 'static,
Creates a new client from the provided stub.
The most common case for calling this function is in tests mocking the client’s behavior.
Sourcepub fn list_constraints(&self) -> ListConstraints
pub fn list_constraints(&self) -> ListConstraints
Lists constraints that could be applied on the specified resource.
§Example
use google_cloud_gax::paginator::ItemPaginator as _;
use google_cloud_orgpolicy_v2::Result;
async fn sample(
client: &OrgPolicy, project_id: &str
) -> Result<()> {
let mut list = client.list_constraints()
.set_parent(format!("projects/{project_id}"))
.by_item();
while let Some(item) = list.next().await.transpose()? {
println!("{:?}", item);
}
Ok(())
}Sourcepub fn list_policies(&self) -> ListPolicies
pub fn list_policies(&self) -> ListPolicies
Retrieves all of the policies that exist on a particular resource.
§Example
use google_cloud_gax::paginator::ItemPaginator as _;
use google_cloud_orgpolicy_v2::Result;
async fn sample(
client: &OrgPolicy, project_id: &str
) -> Result<()> {
let mut list = client.list_policies()
.set_parent(format!("projects/{project_id}"))
.by_item();
while let Some(item) = list.next().await.transpose()? {
println!("{:?}", item);
}
Ok(())
}Sourcepub fn get_policy(&self) -> GetPolicy
pub fn get_policy(&self) -> GetPolicy
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.
§Example
use google_cloud_orgpolicy_v2::Result;
async fn sample(
client: &OrgPolicy, project_id: &str, policy_id: &str
) -> Result<()> {
let response = client.get_policy()
.set_name(format!("projects/{project_id}/policies/{policy_id}"))
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn get_effective_policy(&self) -> GetEffectivePolicy
pub fn get_effective_policy(&self) -> GetEffectivePolicy
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
an evaluated policy across multiple resources.
Subtrees of Resource Manager resource hierarchy with ‘under:’ prefix will
not be expanded.
§Example
use google_cloud_orgpolicy_v2::Result;
async fn sample(
client: &OrgPolicy, project_id: &str, policy_id: &str
) -> Result<()> {
let response = client.get_effective_policy()
.set_name(format!("projects/{project_id}/policies/{policy_id}"))
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn create_policy(&self) -> CreatePolicy
pub fn create_policy(&self) -> CreatePolicy
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 Google Cloud resource.
§Example
use google_cloud_orgpolicy_v2::model::Policy;
use google_cloud_orgpolicy_v2::Result;
async fn sample(
client: &OrgPolicy, project_id: &str
) -> Result<()> {
let response = client.create_policy()
.set_parent(format!("projects/{project_id}"))
.set_policy(
Policy::new()/* set fields */
)
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn update_policy(&self) -> UpdatePolicy
pub fn update_policy(&self) -> UpdatePolicy
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.
§Example
use google_cloud_wkt::FieldMask;
use google_cloud_orgpolicy_v2::model::Policy;
use google_cloud_orgpolicy_v2::Result;
async fn sample(
client: &OrgPolicy, project_id: &str, policy_id: &str
) -> Result<()> {
let response = client.update_policy()
.set_policy(
Policy::new().set_name(format!("projects/{project_id}/policies/{policy_id}"))/* set fields */
)
.set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn delete_policy(&self) -> DeletePolicy
pub fn delete_policy(&self) -> DeletePolicy
Deletes a policy.
Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the
constraint or organization policy does not exist.
§Example
use google_cloud_orgpolicy_v2::Result;
async fn sample(
client: &OrgPolicy, project_id: &str, policy_id: &str
) -> Result<()> {
client.delete_policy()
.set_name(format!("projects/{project_id}/policies/{policy_id}"))
.send().await?;
Ok(())
}Sourcepub fn create_custom_constraint(&self) -> CreateCustomConstraint
pub fn create_custom_constraint(&self) -> CreateCustomConstraint
Creates a custom constraint.
Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the
organization does not exist.
Returns a google.rpc.Status with google.rpc.Code.ALREADY_EXISTS if the
constraint already exists on the given organization.
§Example
use google_cloud_orgpolicy_v2::model::CustomConstraint;
use google_cloud_orgpolicy_v2::Result;
async fn sample(
client: &OrgPolicy, organization_id: &str
) -> Result<()> {
let response = client.create_custom_constraint()
.set_parent(format!("organizations/{organization_id}"))
.set_custom_constraint(
CustomConstraint::new()/* set fields */
)
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn update_custom_constraint(&self) -> UpdateCustomConstraint
pub fn update_custom_constraint(&self) -> UpdateCustomConstraint
Updates a custom constraint.
Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the
constraint does not exist.
Note: the supplied policy will perform a full overwrite of all fields.
§Example
use google_cloud_orgpolicy_v2::model::CustomConstraint;
use google_cloud_orgpolicy_v2::Result;
async fn sample(
client: &OrgPolicy, organization_id: &str, custom_constraint_id: &str
) -> Result<()> {
let response = client.update_custom_constraint()
.set_custom_constraint(
CustomConstraint::new().set_name(format!("organizations/{organization_id}/customConstraints/{custom_constraint_id}"))/* set fields */
)
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn get_custom_constraint(&self) -> GetCustomConstraint
pub fn get_custom_constraint(&self) -> GetCustomConstraint
Gets a custom or managed constraint.
Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the
custom or managed constraint does not exist.
§Example
use google_cloud_orgpolicy_v2::Result;
async fn sample(
client: &OrgPolicy, organization_id: &str, custom_constraint_id: &str
) -> Result<()> {
let response = client.get_custom_constraint()
.set_name(format!("organizations/{organization_id}/customConstraints/{custom_constraint_id}"))
.send().await?;
println!("response {:?}", response);
Ok(())
}Sourcepub fn list_custom_constraints(&self) -> ListCustomConstraints
pub fn list_custom_constraints(&self) -> ListCustomConstraints
Retrieves all of the custom constraints that exist on a particular organization resource.
§Example
use google_cloud_gax::paginator::ItemPaginator as _;
use google_cloud_orgpolicy_v2::Result;
async fn sample(
client: &OrgPolicy, organization_id: &str
) -> Result<()> {
let mut list = client.list_custom_constraints()
.set_parent(format!("organizations/{organization_id}"))
.by_item();
while let Some(item) = list.next().await.transpose()? {
println!("{:?}", item);
}
Ok(())
}Sourcepub fn delete_custom_constraint(&self) -> DeleteCustomConstraint
pub fn delete_custom_constraint(&self) -> DeleteCustomConstraint
Deletes a custom constraint.
Returns a google.rpc.Status with google.rpc.Code.NOT_FOUND if the
constraint does not exist.
§Example
use google_cloud_orgpolicy_v2::Result;
async fn sample(
client: &OrgPolicy, organization_id: &str, custom_constraint_id: &str
) -> Result<()> {
client.delete_custom_constraint()
.set_name(format!("organizations/{organization_id}/customConstraints/{custom_constraint_id}"))
.send().await?;
Ok(())
}