google_cloud_iam_v2/client.rs
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the Identity and Access Management (IAM) API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_iam_v2::client::Policies;
25/// let client = Policies::builder().build().await?;
26/// // use `client` to make requests to the Identity and Access Management (IAM) API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// An interface for managing Identity and Access Management (IAM) policies.
33///
34/// # Configuration
35///
36/// To configure `Policies` use the `with_*` methods in the type returned
37/// by [builder()][Policies::builder]. The default configuration should
38/// work for most applications. Common configuration changes include
39///
40/// * [with_endpoint()]: by default this client uses the global default endpoint
41/// (`https://iam.googleapis.com`). Applications using regional
42/// endpoints or running in restricted networks (e.g. a network configured
43// with [Private Google Access with VPC Service Controls]) may want to
44/// override this default.
45/// * [with_credentials()]: by default this client uses
46/// [Application Default Credentials]. Applications using custom
47/// authentication may need to override this default.
48///
49/// [with_endpoint()]: super::builder::policies::ClientBuilder::with_endpoint
50/// [with_credentials()]: super::builder::policies::ClientBuilder::credentials
51/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
52/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
53///
54/// # Pooling and Cloning
55///
56/// `Policies` holds a connection pool internally, it is advised to
57/// create one and the reuse it. You do not need to wrap `Policies` in
58/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
59/// already uses an `Arc` internally.
60#[derive(Clone, Debug)]
61pub struct Policies {
62 inner: std::sync::Arc<dyn super::stub::dynamic::Policies>,
63}
64
65impl Policies {
66 /// Returns a builder for [Policies].
67 ///
68 /// ```
69 /// # tokio_test::block_on(async {
70 /// # use google_cloud_iam_v2::client::Policies;
71 /// let client = Policies::builder().build().await?;
72 /// # gax::client_builder::Result::<()>::Ok(()) });
73 /// ```
74 pub fn builder() -> super::builder::policies::ClientBuilder {
75 gax::client_builder::internal::new_builder(super::builder::policies::client::Factory)
76 }
77
78 /// Creates a new client from the provided stub.
79 ///
80 /// The most common case for calling this function is in tests mocking the
81 /// client's behavior.
82 pub fn from_stub<T>(stub: T) -> Self
83 where
84 T: super::stub::Policies + 'static,
85 {
86 Self {
87 inner: std::sync::Arc::new(stub),
88 }
89 }
90
91 pub(crate) async fn new(
92 config: gaxi::options::ClientConfig,
93 ) -> gax::client_builder::Result<Self> {
94 let inner = Self::build_inner(config).await?;
95 Ok(Self { inner })
96 }
97
98 async fn build_inner(
99 conf: gaxi::options::ClientConfig,
100 ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::Policies>> {
101 if gaxi::options::tracing_enabled(&conf) {
102 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
103 }
104 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
105 }
106
107 async fn build_transport(
108 conf: gaxi::options::ClientConfig,
109 ) -> gax::client_builder::Result<impl super::stub::Policies> {
110 super::transport::Policies::new(conf).await
111 }
112
113 async fn build_with_tracing(
114 conf: gaxi::options::ClientConfig,
115 ) -> gax::client_builder::Result<impl super::stub::Policies> {
116 Self::build_transport(conf)
117 .await
118 .map(super::tracing::Policies::new)
119 }
120
121 /// Retrieves the policies of the specified kind that are attached to a
122 /// resource.
123 ///
124 /// The response lists only policy metadata. In particular, policy rules are
125 /// omitted.
126 pub fn list_policies(&self) -> super::builder::policies::ListPolicies {
127 super::builder::policies::ListPolicies::new(self.inner.clone())
128 }
129
130 /// Gets a policy.
131 pub fn get_policy(&self) -> super::builder::policies::GetPolicy {
132 super::builder::policies::GetPolicy::new(self.inner.clone())
133 }
134
135 /// Creates a policy.
136 ///
137 /// # Long running operations
138 ///
139 /// This method is used to start, and/or poll a [long-running Operation].
140 /// The [Working with long-running operations] chapter in the [user guide]
141 /// covers these operations in detail.
142 ///
143 /// [long-running operation]: https://google.aip.dev/151
144 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
145 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
146 pub fn create_policy(&self) -> super::builder::policies::CreatePolicy {
147 super::builder::policies::CreatePolicy::new(self.inner.clone())
148 }
149
150 /// Updates the specified policy.
151 ///
152 /// You can update only the rules and the display name for the policy.
153 ///
154 /// To update a policy, you should use a read-modify-write loop:
155 ///
156 /// 1. Use [GetPolicy][google.iam.v2.Policies.GetPolicy] to read the current version of the policy.
157 /// 1. Modify the policy as needed.
158 /// 1. Use `UpdatePolicy` to write the updated policy.
159 ///
160 /// This pattern helps prevent conflicts between concurrent updates.
161 ///
162 /// [google.iam.v2.Policies.GetPolicy]: crate::client::Policies::get_policy
163 ///
164 /// # Long running operations
165 ///
166 /// This method is used to start, and/or poll a [long-running Operation].
167 /// The [Working with long-running operations] chapter in the [user guide]
168 /// covers these operations in detail.
169 ///
170 /// [long-running operation]: https://google.aip.dev/151
171 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
172 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
173 pub fn update_policy(&self) -> super::builder::policies::UpdatePolicy {
174 super::builder::policies::UpdatePolicy::new(self.inner.clone())
175 }
176
177 /// Deletes a policy. This action is permanent.
178 ///
179 /// # Long running operations
180 ///
181 /// This method is used to start, and/or poll a [long-running Operation].
182 /// The [Working with long-running operations] chapter in the [user guide]
183 /// covers these operations in detail.
184 ///
185 /// [long-running operation]: https://google.aip.dev/151
186 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
187 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
188 pub fn delete_policy(&self) -> super::builder::policies::DeletePolicy {
189 super::builder::policies::DeletePolicy::new(self.inner.clone())
190 }
191
192 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
193 ///
194 /// [google.longrunning.Operations]: longrunning::client::Operations
195 pub fn get_operation(&self) -> super::builder::policies::GetOperation {
196 super::builder::policies::GetOperation::new(self.inner.clone())
197 }
198}