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