google_cloud_privilegedaccessmanager_v1/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 Privileged Access Manager API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_privilegedaccessmanager_v1::client::PrivilegedAccessManager;
25/// let client = PrivilegedAccessManager::builder().build().await?;
26/// // use `client` to make requests to the Privileged Access Manager API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// This API allows customers to manage temporary, request based privileged
33/// access to their resources.
34///
35/// It defines the following resource model:
36///
37/// * A collection of `Entitlement` resources. An entitlement allows configuring
38/// (among other things):
39///
40/// * Some kind of privileged access that users can request.
41/// * A set of users called _requesters_ who can request this access.
42/// * A maximum duration for which the access can be requested.
43/// * An optional approval workflow which must be satisfied before access is
44/// granted.
45/// * A collection of `Grant` resources. A grant is a request by a requester to
46/// get the privileged access specified in an entitlement for some duration.
47///
48/// After the approval workflow as specified in the entitlement is satisfied,
49/// the specified access is given to the requester. The access is automatically
50/// taken back after the requested duration is over.
51///
52///
53/// # Configuration
54///
55/// To configure `PrivilegedAccessManager` use the `with_*` methods in the type returned
56/// by [builder()][PrivilegedAccessManager::builder]. The default configuration should
57/// work for most applications. Common configuration changes include
58///
59/// * [with_endpoint()]: by default this client uses the global default endpoint
60/// (`https://privilegedaccessmanager.googleapis.com`). Applications using regional
61/// endpoints or running in restricted networks (e.g. a network configured
62// with [Private Google Access with VPC Service Controls]) may want to
63/// override this default.
64/// * [with_credentials()]: by default this client uses
65/// [Application Default Credentials]. Applications using custom
66/// authentication may need to override this default.
67///
68/// [with_endpoint()]: super::builder::privileged_access_manager::ClientBuilder::with_endpoint
69/// [with_credentials()]: super::builder::privileged_access_manager::ClientBuilder::credentials
70/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
71/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
72///
73/// # Pooling and Cloning
74///
75/// `PrivilegedAccessManager` holds a connection pool internally, it is advised to
76/// create one and the reuse it. You do not need to wrap `PrivilegedAccessManager` in
77/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
78/// already uses an `Arc` internally.
79#[derive(Clone, Debug)]
80pub struct PrivilegedAccessManager {
81 inner: std::sync::Arc<dyn super::stub::dynamic::PrivilegedAccessManager>,
82}
83
84impl PrivilegedAccessManager {
85 /// Returns a builder for [PrivilegedAccessManager].
86 ///
87 /// ```
88 /// # tokio_test::block_on(async {
89 /// # use google_cloud_privilegedaccessmanager_v1::client::PrivilegedAccessManager;
90 /// let client = PrivilegedAccessManager::builder().build().await?;
91 /// # gax::client_builder::Result::<()>::Ok(()) });
92 /// ```
93 pub fn builder() -> super::builder::privileged_access_manager::ClientBuilder {
94 gax::client_builder::internal::new_builder(
95 super::builder::privileged_access_manager::client::Factory,
96 )
97 }
98
99 /// Creates a new client from the provided stub.
100 ///
101 /// The most common case for calling this function is in tests mocking the
102 /// client's behavior.
103 pub fn from_stub<T>(stub: T) -> Self
104 where
105 T: super::stub::PrivilegedAccessManager + 'static,
106 {
107 Self {
108 inner: std::sync::Arc::new(stub),
109 }
110 }
111
112 pub(crate) async fn new(
113 config: gaxi::options::ClientConfig,
114 ) -> gax::client_builder::Result<Self> {
115 let inner = Self::build_inner(config).await?;
116 Ok(Self { inner })
117 }
118
119 async fn build_inner(
120 conf: gaxi::options::ClientConfig,
121 ) -> gax::client_builder::Result<
122 std::sync::Arc<dyn super::stub::dynamic::PrivilegedAccessManager>,
123 > {
124 if gaxi::options::tracing_enabled(&conf) {
125 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
126 }
127 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
128 }
129
130 async fn build_transport(
131 conf: gaxi::options::ClientConfig,
132 ) -> gax::client_builder::Result<impl super::stub::PrivilegedAccessManager> {
133 super::transport::PrivilegedAccessManager::new(conf).await
134 }
135
136 async fn build_with_tracing(
137 conf: gaxi::options::ClientConfig,
138 ) -> gax::client_builder::Result<impl super::stub::PrivilegedAccessManager> {
139 Self::build_transport(conf)
140 .await
141 .map(super::tracing::PrivilegedAccessManager::new)
142 }
143
144 /// `CheckOnboardingStatus` reports the onboarding status for a
145 /// project/folder/organization. Any findings reported by this API need to be
146 /// fixed before PAM can be used on the resource.
147 pub fn check_onboarding_status(
148 &self,
149 ) -> super::builder::privileged_access_manager::CheckOnboardingStatus {
150 super::builder::privileged_access_manager::CheckOnboardingStatus::new(self.inner.clone())
151 }
152
153 /// Lists entitlements in a given project/folder/organization and location.
154 pub fn list_entitlements(&self) -> super::builder::privileged_access_manager::ListEntitlements {
155 super::builder::privileged_access_manager::ListEntitlements::new(self.inner.clone())
156 }
157
158 /// `SearchEntitlements` returns entitlements on which the caller has the
159 /// specified access.
160 pub fn search_entitlements(
161 &self,
162 ) -> super::builder::privileged_access_manager::SearchEntitlements {
163 super::builder::privileged_access_manager::SearchEntitlements::new(self.inner.clone())
164 }
165
166 /// Gets details of a single entitlement.
167 pub fn get_entitlement(&self) -> super::builder::privileged_access_manager::GetEntitlement {
168 super::builder::privileged_access_manager::GetEntitlement::new(self.inner.clone())
169 }
170
171 /// Creates a new entitlement in a given project/folder/organization and
172 /// location.
173 ///
174 /// # Long running operations
175 ///
176 /// This method is used to start, and/or poll a [long-running Operation].
177 /// The [Working with long-running operations] chapter in the [user guide]
178 /// covers these operations in detail.
179 ///
180 /// [long-running operation]: https://google.aip.dev/151
181 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
182 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
183 pub fn create_entitlement(
184 &self,
185 ) -> super::builder::privileged_access_manager::CreateEntitlement {
186 super::builder::privileged_access_manager::CreateEntitlement::new(self.inner.clone())
187 }
188
189 /// Deletes a single entitlement. This method can only be called when there
190 /// are no in-progress (`ACTIVE`/`ACTIVATING`/`REVOKING`) grants under the
191 /// entitlement.
192 ///
193 /// # Long running operations
194 ///
195 /// This method is used to start, and/or poll a [long-running Operation].
196 /// The [Working with long-running operations] chapter in the [user guide]
197 /// covers these operations in detail.
198 ///
199 /// [long-running operation]: https://google.aip.dev/151
200 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
201 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
202 pub fn delete_entitlement(
203 &self,
204 ) -> super::builder::privileged_access_manager::DeleteEntitlement {
205 super::builder::privileged_access_manager::DeleteEntitlement::new(self.inner.clone())
206 }
207
208 /// Updates the entitlement specified in the request. Updated fields in the
209 /// entitlement need to be specified in an update mask. The changes made to an
210 /// entitlement are applicable only on future grants of the entitlement.
211 /// However, if new approvers are added or existing approvers are removed from
212 /// the approval workflow, the changes are effective on existing grants.
213 ///
214 /// The following fields are not supported for updates:
215 ///
216 /// * All immutable fields
217 /// * Entitlement name
218 /// * Resource name
219 /// * Resource type
220 /// * Adding an approval workflow in an entitlement which previously had no
221 /// approval workflow.
222 /// * Deleting the approval workflow from an entitlement.
223 /// * Adding or deleting a step in the approval workflow (only one step is
224 /// supported)
225 ///
226 /// Note that updates are allowed on the list of approvers in an approval
227 /// workflow step.
228 ///
229 /// # Long running operations
230 ///
231 /// This method is used to start, and/or poll a [long-running Operation].
232 /// The [Working with long-running operations] chapter in the [user guide]
233 /// covers these operations in detail.
234 ///
235 /// [long-running operation]: https://google.aip.dev/151
236 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
237 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
238 pub fn update_entitlement(
239 &self,
240 ) -> super::builder::privileged_access_manager::UpdateEntitlement {
241 super::builder::privileged_access_manager::UpdateEntitlement::new(self.inner.clone())
242 }
243
244 /// Lists grants for a given entitlement.
245 pub fn list_grants(&self) -> super::builder::privileged_access_manager::ListGrants {
246 super::builder::privileged_access_manager::ListGrants::new(self.inner.clone())
247 }
248
249 /// `SearchGrants` returns grants that are related to the calling user in the
250 /// specified way.
251 pub fn search_grants(&self) -> super::builder::privileged_access_manager::SearchGrants {
252 super::builder::privileged_access_manager::SearchGrants::new(self.inner.clone())
253 }
254
255 /// Get details of a single grant.
256 pub fn get_grant(&self) -> super::builder::privileged_access_manager::GetGrant {
257 super::builder::privileged_access_manager::GetGrant::new(self.inner.clone())
258 }
259
260 /// Creates a new grant in a given project/folder/organization and
261 /// location.
262 pub fn create_grant(&self) -> super::builder::privileged_access_manager::CreateGrant {
263 super::builder::privileged_access_manager::CreateGrant::new(self.inner.clone())
264 }
265
266 /// `ApproveGrant` is used to approve a grant. This method can only be called
267 /// on a grant when it's in the `APPROVAL_AWAITED` state. This operation can't
268 /// be undone.
269 pub fn approve_grant(&self) -> super::builder::privileged_access_manager::ApproveGrant {
270 super::builder::privileged_access_manager::ApproveGrant::new(self.inner.clone())
271 }
272
273 /// `DenyGrant` is used to deny a grant. This method can only be called on a
274 /// grant when it's in the `APPROVAL_AWAITED` state. This operation can't be
275 /// undone.
276 pub fn deny_grant(&self) -> super::builder::privileged_access_manager::DenyGrant {
277 super::builder::privileged_access_manager::DenyGrant::new(self.inner.clone())
278 }
279
280 /// `RevokeGrant` is used to immediately revoke access for a grant. This method
281 /// can be called when the grant is in a non-terminal state.
282 ///
283 /// # Long running operations
284 ///
285 /// This method is used to start, and/or poll a [long-running Operation].
286 /// The [Working with long-running operations] chapter in the [user guide]
287 /// covers these operations in detail.
288 ///
289 /// [long-running operation]: https://google.aip.dev/151
290 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
291 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
292 pub fn revoke_grant(&self) -> super::builder::privileged_access_manager::RevokeGrant {
293 super::builder::privileged_access_manager::RevokeGrant::new(self.inner.clone())
294 }
295
296 /// Lists information about the supported locations for this service.
297 pub fn list_locations(&self) -> super::builder::privileged_access_manager::ListLocations {
298 super::builder::privileged_access_manager::ListLocations::new(self.inner.clone())
299 }
300
301 /// Gets information about a location.
302 pub fn get_location(&self) -> super::builder::privileged_access_manager::GetLocation {
303 super::builder::privileged_access_manager::GetLocation::new(self.inner.clone())
304 }
305
306 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
307 ///
308 /// [google.longrunning.Operations]: longrunning::client::Operations
309 pub fn list_operations(&self) -> super::builder::privileged_access_manager::ListOperations {
310 super::builder::privileged_access_manager::ListOperations::new(self.inner.clone())
311 }
312
313 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
314 ///
315 /// [google.longrunning.Operations]: longrunning::client::Operations
316 pub fn get_operation(&self) -> super::builder::privileged_access_manager::GetOperation {
317 super::builder::privileged_access_manager::GetOperation::new(self.inner.clone())
318 }
319
320 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
321 ///
322 /// [google.longrunning.Operations]: longrunning::client::Operations
323 pub fn delete_operation(&self) -> super::builder::privileged_access_manager::DeleteOperation {
324 super::builder::privileged_access_manager::DeleteOperation::new(self.inner.clone())
325 }
326}