Skip to main content

google_cloud_kms_inventory_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 KMS Inventory API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_kms_inventory_v1::client::KeyDashboardService;
24/// use google_cloud_gax::paginator::ItemPaginator as _;
25/// async fn sample(
26///    parent: &str,
27/// ) -> anyhow::Result<()> {
28///     let client = KeyDashboardService::builder().build().await?;
29///     let mut list = client.list_crypto_keys()
30///         .set_parent(parent)
31///         .by_item();
32///     while let Some(item) = list.next().await.transpose()? {
33///         println!("{:?}", item);
34///     }
35///     Ok(())
36/// }
37/// ```
38///
39/// # Service Description
40///
41/// Provides a cross-region view of all Cloud KMS keys in a given Cloud project.
42///
43/// # Configuration
44///
45/// To configure `KeyDashboardService` use the `with_*` methods in the type returned
46/// by [builder()][KeyDashboardService::builder]. The default configuration should
47/// work for most applications. Common configuration changes include
48///
49/// * [with_endpoint()]: by default this client uses the global default endpoint
50///   (`https://kmsinventory.googleapis.com`). Applications using regional
51///   endpoints or running in restricted networks (e.g. a network configured
52///   with [Private Google Access with VPC Service Controls]) may want to
53///   override this default.
54/// * [with_credentials()]: by default this client uses
55///   [Application Default Credentials]. Applications using custom
56///   authentication may need to override this default.
57///
58/// [with_endpoint()]: super::builder::key_dashboard_service::ClientBuilder::with_endpoint
59/// [with_credentials()]: super::builder::key_dashboard_service::ClientBuilder::with_credentials
60/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
61/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
62///
63/// # Pooling and Cloning
64///
65/// `KeyDashboardService` holds a connection pool internally, it is advised to
66/// create one and reuse it. You do not need to wrap `KeyDashboardService` in
67/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
68/// already uses an `Arc` internally.
69#[derive(Clone, Debug)]
70pub struct KeyDashboardService {
71    inner: std::sync::Arc<dyn super::stub::dynamic::KeyDashboardService>,
72}
73
74impl KeyDashboardService {
75    /// Returns a builder for [KeyDashboardService].
76    ///
77    /// ```
78    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
79    /// # use google_cloud_kms_inventory_v1::client::KeyDashboardService;
80    /// let client = KeyDashboardService::builder().build().await?;
81    /// # Ok(()) }
82    /// ```
83    pub fn builder() -> super::builder::key_dashboard_service::ClientBuilder {
84        crate::new_client_builder(super::builder::key_dashboard_service::client::Factory)
85    }
86
87    /// Creates a new client from the provided stub.
88    ///
89    /// The most common case for calling this function is in tests mocking the
90    /// client's behavior.
91    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
92    where
93        T: super::stub::KeyDashboardService + 'static,
94    {
95        Self { inner: stub.into() }
96    }
97
98    pub(crate) async fn new(
99        config: gaxi::options::ClientConfig,
100    ) -> crate::ClientBuilderResult<Self> {
101        let inner = Self::build_inner(config).await?;
102        Ok(Self { inner })
103    }
104
105    async fn build_inner(
106        conf: gaxi::options::ClientConfig,
107    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::KeyDashboardService>>
108    {
109        if gaxi::options::tracing_enabled(&conf) {
110            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
111        }
112        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
113    }
114
115    async fn build_transport(
116        conf: gaxi::options::ClientConfig,
117    ) -> crate::ClientBuilderResult<impl super::stub::KeyDashboardService> {
118        super::transport::KeyDashboardService::new(conf).await
119    }
120
121    async fn build_with_tracing(
122        conf: gaxi::options::ClientConfig,
123    ) -> crate::ClientBuilderResult<impl super::stub::KeyDashboardService> {
124        Self::build_transport(conf)
125            .await
126            .map(super::tracing::KeyDashboardService::new)
127    }
128
129    /// Returns cryptographic keys managed by Cloud KMS in a given Cloud project.
130    /// Note that this data is sourced from snapshots, meaning it may not
131    /// completely reflect the actual state of key metadata at call time.
132    ///
133    /// # Example
134    /// ```
135    /// # use google_cloud_kms_inventory_v1::client::KeyDashboardService;
136    /// use google_cloud_gax::paginator::ItemPaginator as _;
137    /// use google_cloud_kms_inventory_v1::Result;
138    /// async fn sample(
139    ///    client: &KeyDashboardService, parent: &str
140    /// ) -> Result<()> {
141    ///     let mut list = client.list_crypto_keys()
142    ///         .set_parent(parent)
143    ///         .by_item();
144    ///     while let Some(item) = list.next().await.transpose()? {
145    ///         println!("{:?}", item);
146    ///     }
147    ///     Ok(())
148    /// }
149    /// ```
150    pub fn list_crypto_keys(&self) -> super::builder::key_dashboard_service::ListCryptoKeys {
151        super::builder::key_dashboard_service::ListCryptoKeys::new(self.inner.clone())
152    }
153}
154
155/// Implements a client for the KMS Inventory API.
156///
157/// # Example
158/// ```
159/// # use google_cloud_kms_inventory_v1::client::KeyTrackingService;
160/// async fn sample(
161///    project_id: &str,
162///    location_id: &str,
163///    key_ring_id: &str,
164///    crypto_key_id: &str,
165/// ) -> anyhow::Result<()> {
166///     let client = KeyTrackingService::builder().build().await?;
167///     let response = client.get_protected_resources_summary()
168///         .set_name(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}/cryptoKeys/{crypto_key_id}/protectedResourcesSummary"))
169///         .send().await?;
170///     println!("response {:?}", response);
171///     Ok(())
172/// }
173/// ```
174///
175/// # Service Description
176///
177/// Returns information about the resources in an org that are protected by a
178/// given Cloud KMS key via CMEK.
179///
180/// # Configuration
181///
182/// To configure `KeyTrackingService` use the `with_*` methods in the type returned
183/// by [builder()][KeyTrackingService::builder]. The default configuration should
184/// work for most applications. Common configuration changes include
185///
186/// * [with_endpoint()]: by default this client uses the global default endpoint
187///   (`https://kmsinventory.googleapis.com`). Applications using regional
188///   endpoints or running in restricted networks (e.g. a network configured
189///   with [Private Google Access with VPC Service Controls]) may want to
190///   override this default.
191/// * [with_credentials()]: by default this client uses
192///   [Application Default Credentials]. Applications using custom
193///   authentication may need to override this default.
194///
195/// [with_endpoint()]: super::builder::key_tracking_service::ClientBuilder::with_endpoint
196/// [with_credentials()]: super::builder::key_tracking_service::ClientBuilder::with_credentials
197/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
198/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
199///
200/// # Pooling and Cloning
201///
202/// `KeyTrackingService` holds a connection pool internally, it is advised to
203/// create one and reuse it. You do not need to wrap `KeyTrackingService` in
204/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
205/// already uses an `Arc` internally.
206#[derive(Clone, Debug)]
207pub struct KeyTrackingService {
208    inner: std::sync::Arc<dyn super::stub::dynamic::KeyTrackingService>,
209}
210
211impl KeyTrackingService {
212    /// Returns a builder for [KeyTrackingService].
213    ///
214    /// ```
215    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
216    /// # use google_cloud_kms_inventory_v1::client::KeyTrackingService;
217    /// let client = KeyTrackingService::builder().build().await?;
218    /// # Ok(()) }
219    /// ```
220    pub fn builder() -> super::builder::key_tracking_service::ClientBuilder {
221        crate::new_client_builder(super::builder::key_tracking_service::client::Factory)
222    }
223
224    /// Creates a new client from the provided stub.
225    ///
226    /// The most common case for calling this function is in tests mocking the
227    /// client's behavior.
228    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
229    where
230        T: super::stub::KeyTrackingService + 'static,
231    {
232        Self { inner: stub.into() }
233    }
234
235    pub(crate) async fn new(
236        config: gaxi::options::ClientConfig,
237    ) -> crate::ClientBuilderResult<Self> {
238        let inner = Self::build_inner(config).await?;
239        Ok(Self { inner })
240    }
241
242    async fn build_inner(
243        conf: gaxi::options::ClientConfig,
244    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::KeyTrackingService>>
245    {
246        if gaxi::options::tracing_enabled(&conf) {
247            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
248        }
249        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
250    }
251
252    async fn build_transport(
253        conf: gaxi::options::ClientConfig,
254    ) -> crate::ClientBuilderResult<impl super::stub::KeyTrackingService> {
255        super::transport::KeyTrackingService::new(conf).await
256    }
257
258    async fn build_with_tracing(
259        conf: gaxi::options::ClientConfig,
260    ) -> crate::ClientBuilderResult<impl super::stub::KeyTrackingService> {
261        Self::build_transport(conf)
262            .await
263            .map(super::tracing::KeyTrackingService::new)
264    }
265
266    /// Returns aggregate information about the resources protected by the given
267    /// Cloud KMS [CryptoKey][google.cloud.kms.v1.CryptoKey]. By default,
268    /// summary of resources within the same Cloud organization as the key will be
269    /// returned, which requires the KMS organization service account to be
270    /// configured(refer
271    /// <https://docs.cloud.google.com/kms/docs/view-key-usage#required-roles>).
272    /// If the KMS organization service account is not configured or key's project
273    /// is not part of an organization, set
274    /// [fallback_scope][google.cloud.kms.inventory.v1.GetProtectedResourcesSummaryRequest.fallback_scope]
275    /// to `FALLBACK_SCOPE_PROJECT` to retrieve a summary of protected resources
276    /// within the key's project.
277    ///
278    /// [google.cloud.kms.inventory.v1.GetProtectedResourcesSummaryRequest.fallback_scope]: crate::model::GetProtectedResourcesSummaryRequest::fallback_scope
279    /// [google.cloud.kms.v1.CryptoKey]: google_cloud_kms_v1::model::CryptoKey
280    ///
281    /// # Example
282    /// ```
283    /// # use google_cloud_kms_inventory_v1::client::KeyTrackingService;
284    /// use google_cloud_kms_inventory_v1::Result;
285    /// async fn sample(
286    ///    client: &KeyTrackingService, project_id: &str, location_id: &str, key_ring_id: &str, crypto_key_id: &str
287    /// ) -> Result<()> {
288    ///     let response = client.get_protected_resources_summary()
289    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}/cryptoKeys/{crypto_key_id}/protectedResourcesSummary"))
290    ///         .send().await?;
291    ///     println!("response {:?}", response);
292    ///     Ok(())
293    /// }
294    /// ```
295    pub fn get_protected_resources_summary(
296        &self,
297    ) -> super::builder::key_tracking_service::GetProtectedResourcesSummary {
298        super::builder::key_tracking_service::GetProtectedResourcesSummary::new(self.inner.clone())
299    }
300
301    /// Returns metadata about the resources protected by the given Cloud KMS
302    /// [CryptoKey][google.cloud.kms.v1.CryptoKey] in the given Cloud
303    /// organization/project.
304    ///
305    /// [google.cloud.kms.v1.CryptoKey]: google_cloud_kms_v1::model::CryptoKey
306    ///
307    /// # Example
308    /// ```
309    /// # use google_cloud_kms_inventory_v1::client::KeyTrackingService;
310    /// use google_cloud_gax::paginator::ItemPaginator as _;
311    /// use google_cloud_kms_inventory_v1::Result;
312    /// async fn sample(
313    ///    client: &KeyTrackingService
314    /// ) -> Result<()> {
315    ///     let mut list = client.search_protected_resources()
316    ///         /* set fields */
317    ///         .by_item();
318    ///     while let Some(item) = list.next().await.transpose()? {
319    ///         println!("{:?}", item);
320    ///     }
321    ///     Ok(())
322    /// }
323    /// ```
324    pub fn search_protected_resources(
325        &self,
326    ) -> super::builder::key_tracking_service::SearchProtectedResources {
327        super::builder::key_tracking_service::SearchProtectedResources::new(self.inner.clone())
328    }
329}