Skip to main content

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/// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
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/// # 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    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
89    /// # use google_cloud_privilegedaccessmanager_v1::client::PrivilegedAccessManager;
90    /// let client = PrivilegedAccessManager::builder().build().await?;
91    /// # Ok(()) }
92    /// ```
93    pub fn builder() -> super::builder::privileged_access_manager::ClientBuilder {
94        crate::new_client_builder(super::builder::privileged_access_manager::client::Factory)
95    }
96
97    /// Creates a new client from the provided stub.
98    ///
99    /// The most common case for calling this function is in tests mocking the
100    /// client's behavior.
101    pub fn from_stub<T>(stub: T) -> Self
102    where
103        T: super::stub::PrivilegedAccessManager + 'static,
104    {
105        Self {
106            inner: std::sync::Arc::new(stub),
107        }
108    }
109
110    pub(crate) async fn new(
111        config: gaxi::options::ClientConfig,
112    ) -> crate::ClientBuilderResult<Self> {
113        let inner = Self::build_inner(config).await?;
114        Ok(Self { inner })
115    }
116
117    async fn build_inner(
118        conf: gaxi::options::ClientConfig,
119    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::PrivilegedAccessManager>>
120    {
121        if gaxi::options::tracing_enabled(&conf) {
122            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
123        }
124        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
125    }
126
127    async fn build_transport(
128        conf: gaxi::options::ClientConfig,
129    ) -> crate::ClientBuilderResult<impl super::stub::PrivilegedAccessManager> {
130        super::transport::PrivilegedAccessManager::new(conf).await
131    }
132
133    async fn build_with_tracing(
134        conf: gaxi::options::ClientConfig,
135    ) -> crate::ClientBuilderResult<impl super::stub::PrivilegedAccessManager> {
136        Self::build_transport(conf)
137            .await
138            .map(super::tracing::PrivilegedAccessManager::new)
139    }
140
141    /// `CheckOnboardingStatus` reports the onboarding status for a
142    /// project/folder/organization. Any findings reported by this API need to be
143    /// fixed before PAM can be used on the resource.
144    pub fn check_onboarding_status(
145        &self,
146    ) -> super::builder::privileged_access_manager::CheckOnboardingStatus {
147        super::builder::privileged_access_manager::CheckOnboardingStatus::new(self.inner.clone())
148    }
149
150    /// Lists entitlements in a given project/folder/organization and location.
151    pub fn list_entitlements(&self) -> super::builder::privileged_access_manager::ListEntitlements {
152        super::builder::privileged_access_manager::ListEntitlements::new(self.inner.clone())
153    }
154
155    /// `SearchEntitlements` returns entitlements on which the caller has the
156    /// specified access.
157    pub fn search_entitlements(
158        &self,
159    ) -> super::builder::privileged_access_manager::SearchEntitlements {
160        super::builder::privileged_access_manager::SearchEntitlements::new(self.inner.clone())
161    }
162
163    /// Gets details of a single entitlement.
164    pub fn get_entitlement(&self) -> super::builder::privileged_access_manager::GetEntitlement {
165        super::builder::privileged_access_manager::GetEntitlement::new(self.inner.clone())
166    }
167
168    /// Creates a new entitlement in a given project/folder/organization and
169    /// location.
170    ///
171    /// # Long running operations
172    ///
173    /// This method is used to start, and/or poll a [long-running Operation].
174    /// The [Working with long-running operations] chapter in the [user guide]
175    /// covers these operations in detail.
176    ///
177    /// [long-running operation]: https://google.aip.dev/151
178    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
179    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
180    pub fn create_entitlement(
181        &self,
182    ) -> super::builder::privileged_access_manager::CreateEntitlement {
183        super::builder::privileged_access_manager::CreateEntitlement::new(self.inner.clone())
184    }
185
186    /// Deletes a single entitlement. This method can only be called when there
187    /// are no in-progress (`ACTIVE`/`ACTIVATING`/`REVOKING`) grants under the
188    /// entitlement.
189    ///
190    /// # Long running operations
191    ///
192    /// This method is used to start, and/or poll a [long-running Operation].
193    /// The [Working with long-running operations] chapter in the [user guide]
194    /// covers these operations in detail.
195    ///
196    /// [long-running operation]: https://google.aip.dev/151
197    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
198    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
199    pub fn delete_entitlement(
200        &self,
201    ) -> super::builder::privileged_access_manager::DeleteEntitlement {
202        super::builder::privileged_access_manager::DeleteEntitlement::new(self.inner.clone())
203    }
204
205    /// Updates the entitlement specified in the request. Updated fields in the
206    /// entitlement need to be specified in an update mask. The changes made to an
207    /// entitlement are applicable only on future grants of the entitlement.
208    /// However, if new approvers are added or existing approvers are removed from
209    /// the approval workflow, the changes are effective on existing grants.
210    ///
211    /// The following fields are not supported for updates:
212    ///
213    /// * All immutable fields
214    /// * Entitlement name
215    /// * Resource name
216    /// * Resource type
217    /// * Adding an approval workflow in an entitlement which previously had no
218    ///   approval workflow.
219    /// * Deleting the approval workflow from an entitlement.
220    /// * Adding or deleting a step in the approval workflow (only one step is
221    ///   supported)
222    ///
223    /// Note that updates are allowed on the list of approvers in an approval
224    /// workflow step.
225    ///
226    /// # Long running operations
227    ///
228    /// This method is used to start, and/or poll a [long-running Operation].
229    /// The [Working with long-running operations] chapter in the [user guide]
230    /// covers these operations in detail.
231    ///
232    /// [long-running operation]: https://google.aip.dev/151
233    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
234    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
235    pub fn update_entitlement(
236        &self,
237    ) -> super::builder::privileged_access_manager::UpdateEntitlement {
238        super::builder::privileged_access_manager::UpdateEntitlement::new(self.inner.clone())
239    }
240
241    /// Lists grants for a given entitlement.
242    pub fn list_grants(&self) -> super::builder::privileged_access_manager::ListGrants {
243        super::builder::privileged_access_manager::ListGrants::new(self.inner.clone())
244    }
245
246    /// `SearchGrants` returns grants that are related to the calling user in the
247    /// specified way.
248    pub fn search_grants(&self) -> super::builder::privileged_access_manager::SearchGrants {
249        super::builder::privileged_access_manager::SearchGrants::new(self.inner.clone())
250    }
251
252    /// Get details of a single grant.
253    pub fn get_grant(&self) -> super::builder::privileged_access_manager::GetGrant {
254        super::builder::privileged_access_manager::GetGrant::new(self.inner.clone())
255    }
256
257    /// Creates a new grant in a given project/folder/organization and
258    /// location.
259    pub fn create_grant(&self) -> super::builder::privileged_access_manager::CreateGrant {
260        super::builder::privileged_access_manager::CreateGrant::new(self.inner.clone())
261    }
262
263    /// `ApproveGrant` is used to approve a grant. This method can only be called
264    /// on a grant when it's in the `APPROVAL_AWAITED` state. This operation can't
265    /// be undone.
266    pub fn approve_grant(&self) -> super::builder::privileged_access_manager::ApproveGrant {
267        super::builder::privileged_access_manager::ApproveGrant::new(self.inner.clone())
268    }
269
270    /// `DenyGrant` is used to deny a grant. This method can only be called on a
271    /// grant when it's in the `APPROVAL_AWAITED` state. This operation can't be
272    /// undone.
273    pub fn deny_grant(&self) -> super::builder::privileged_access_manager::DenyGrant {
274        super::builder::privileged_access_manager::DenyGrant::new(self.inner.clone())
275    }
276
277    /// `RevokeGrant` is used to immediately revoke access for a grant. This method
278    /// can be called when the grant is in a non-terminal state.
279    ///
280    /// # Long running operations
281    ///
282    /// This method is used to start, and/or poll a [long-running Operation].
283    /// The [Working with long-running operations] chapter in the [user guide]
284    /// covers these operations in detail.
285    ///
286    /// [long-running operation]: https://google.aip.dev/151
287    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
288    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
289    pub fn revoke_grant(&self) -> super::builder::privileged_access_manager::RevokeGrant {
290        super::builder::privileged_access_manager::RevokeGrant::new(self.inner.clone())
291    }
292
293    /// Lists information about the supported locations for this service.
294    pub fn list_locations(&self) -> super::builder::privileged_access_manager::ListLocations {
295        super::builder::privileged_access_manager::ListLocations::new(self.inner.clone())
296    }
297
298    /// Gets information about a location.
299    pub fn get_location(&self) -> super::builder::privileged_access_manager::GetLocation {
300        super::builder::privileged_access_manager::GetLocation::new(self.inner.clone())
301    }
302
303    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
304    ///
305    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
306    pub fn list_operations(&self) -> super::builder::privileged_access_manager::ListOperations {
307        super::builder::privileged_access_manager::ListOperations::new(self.inner.clone())
308    }
309
310    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
311    ///
312    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
313    pub fn get_operation(&self) -> super::builder::privileged_access_manager::GetOperation {
314        super::builder::privileged_access_manager::GetOperation::new(self.inner.clone())
315    }
316
317    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
318    ///
319    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
320    pub fn delete_operation(&self) -> super::builder::privileged_access_manager::DeleteOperation {
321        super::builder::privileged_access_manager::DeleteOperation::new(self.inner.clone())
322    }
323}