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/// # tokio_test::block_on(async {
24/// # use google_cloud_kms_inventory_v1::client::KeyDashboardService;
25/// let client = KeyDashboardService::builder().build().await?;
26/// // use `client` to make requests to the KMS Inventory API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Provides a cross-region view of all Cloud KMS keys in a given Cloud project.
33///
34/// # Configuration
35///
36/// To configure `KeyDashboardService` use the `with_*` methods in the type returned
37/// by [builder()][KeyDashboardService::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://kmsinventory.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::key_dashboard_service::ClientBuilder::with_endpoint
50/// [with_credentials()]: super::builder::key_dashboard_service::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/// `KeyDashboardService` holds a connection pool internally, it is advised to
57/// create one and the reuse it.  You do not need to wrap `KeyDashboardService` 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 KeyDashboardService {
62    inner: std::sync::Arc<dyn super::stub::dynamic::KeyDashboardService>,
63}
64
65impl KeyDashboardService {
66    /// Returns a builder for [KeyDashboardService].
67    ///
68    /// ```
69    /// # tokio_test::block_on(async {
70    /// # use google_cloud_kms_inventory_v1::client::KeyDashboardService;
71    /// let client = KeyDashboardService::builder().build().await?;
72    /// # gax::client_builder::Result::<()>::Ok(()) });
73    /// ```
74    pub fn builder() -> super::builder::key_dashboard_service::ClientBuilder {
75        gax::client_builder::internal::new_builder(
76            super::builder::key_dashboard_service::client::Factory,
77        )
78    }
79
80    /// Creates a new client from the provided stub.
81    ///
82    /// The most common case for calling this function is in tests mocking the
83    /// client's behavior.
84    pub fn from_stub<T>(stub: T) -> Self
85    where
86        T: super::stub::KeyDashboardService + 'static,
87    {
88        Self {
89            inner: std::sync::Arc::new(stub),
90        }
91    }
92
93    pub(crate) async fn new(
94        config: gaxi::options::ClientConfig,
95    ) -> gax::client_builder::Result<Self> {
96        let inner = Self::build_inner(config).await?;
97        Ok(Self { inner })
98    }
99
100    async fn build_inner(
101        conf: gaxi::options::ClientConfig,
102    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::KeyDashboardService>>
103    {
104        if gaxi::options::tracing_enabled(&conf) {
105            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
106        }
107        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
108    }
109
110    async fn build_transport(
111        conf: gaxi::options::ClientConfig,
112    ) -> gax::client_builder::Result<impl super::stub::KeyDashboardService> {
113        super::transport::KeyDashboardService::new(conf).await
114    }
115
116    async fn build_with_tracing(
117        conf: gaxi::options::ClientConfig,
118    ) -> gax::client_builder::Result<impl super::stub::KeyDashboardService> {
119        Self::build_transport(conf)
120            .await
121            .map(super::tracing::KeyDashboardService::new)
122    }
123
124    /// Returns cryptographic keys managed by Cloud KMS in a given Cloud project.
125    /// Note that this data is sourced from snapshots, meaning it may not
126    /// completely reflect the actual state of key metadata at call time.
127    pub fn list_crypto_keys(&self) -> super::builder::key_dashboard_service::ListCryptoKeys {
128        super::builder::key_dashboard_service::ListCryptoKeys::new(self.inner.clone())
129    }
130}
131
132/// Implements a client for the KMS Inventory API.
133///
134/// # Example
135/// ```
136/// # tokio_test::block_on(async {
137/// # use google_cloud_kms_inventory_v1::client::KeyTrackingService;
138/// let client = KeyTrackingService::builder().build().await?;
139/// // use `client` to make requests to the KMS Inventory API.
140/// # gax::client_builder::Result::<()>::Ok(()) });
141/// ```
142///
143/// # Service Description
144///
145/// Returns information about the resources in an org that are protected by a
146/// given Cloud KMS key via CMEK.
147///
148/// # Configuration
149///
150/// To configure `KeyTrackingService` use the `with_*` methods in the type returned
151/// by [builder()][KeyTrackingService::builder]. The default configuration should
152/// work for most applications. Common configuration changes include
153///
154/// * [with_endpoint()]: by default this client uses the global default endpoint
155///   (`https://kmsinventory.googleapis.com`). Applications using regional
156///   endpoints or running in restricted networks (e.g. a network configured
157//    with [Private Google Access with VPC Service Controls]) may want to
158///   override this default.
159/// * [with_credentials()]: by default this client uses
160///   [Application Default Credentials]. Applications using custom
161///   authentication may need to override this default.
162///
163/// [with_endpoint()]: super::builder::key_tracking_service::ClientBuilder::with_endpoint
164/// [with_credentials()]: super::builder::key_tracking_service::ClientBuilder::credentials
165/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
166/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
167///
168/// # Pooling and Cloning
169///
170/// `KeyTrackingService` holds a connection pool internally, it is advised to
171/// create one and the reuse it.  You do not need to wrap `KeyTrackingService` in
172/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
173/// already uses an `Arc` internally.
174#[derive(Clone, Debug)]
175pub struct KeyTrackingService {
176    inner: std::sync::Arc<dyn super::stub::dynamic::KeyTrackingService>,
177}
178
179impl KeyTrackingService {
180    /// Returns a builder for [KeyTrackingService].
181    ///
182    /// ```
183    /// # tokio_test::block_on(async {
184    /// # use google_cloud_kms_inventory_v1::client::KeyTrackingService;
185    /// let client = KeyTrackingService::builder().build().await?;
186    /// # gax::client_builder::Result::<()>::Ok(()) });
187    /// ```
188    pub fn builder() -> super::builder::key_tracking_service::ClientBuilder {
189        gax::client_builder::internal::new_builder(
190            super::builder::key_tracking_service::client::Factory,
191        )
192    }
193
194    /// Creates a new client from the provided stub.
195    ///
196    /// The most common case for calling this function is in tests mocking the
197    /// client's behavior.
198    pub fn from_stub<T>(stub: T) -> Self
199    where
200        T: super::stub::KeyTrackingService + 'static,
201    {
202        Self {
203            inner: std::sync::Arc::new(stub),
204        }
205    }
206
207    pub(crate) async fn new(
208        config: gaxi::options::ClientConfig,
209    ) -> gax::client_builder::Result<Self> {
210        let inner = Self::build_inner(config).await?;
211        Ok(Self { inner })
212    }
213
214    async fn build_inner(
215        conf: gaxi::options::ClientConfig,
216    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::KeyTrackingService>>
217    {
218        if gaxi::options::tracing_enabled(&conf) {
219            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
220        }
221        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
222    }
223
224    async fn build_transport(
225        conf: gaxi::options::ClientConfig,
226    ) -> gax::client_builder::Result<impl super::stub::KeyTrackingService> {
227        super::transport::KeyTrackingService::new(conf).await
228    }
229
230    async fn build_with_tracing(
231        conf: gaxi::options::ClientConfig,
232    ) -> gax::client_builder::Result<impl super::stub::KeyTrackingService> {
233        Self::build_transport(conf)
234            .await
235            .map(super::tracing::KeyTrackingService::new)
236    }
237
238    /// Returns aggregate information about the resources protected by the given
239    /// Cloud KMS [CryptoKey][google.cloud.kms.v1.CryptoKey]. Only resources within
240    /// the same Cloud organization as the key will be returned. The project that
241    /// holds the key must be part of an organization in order for this call to
242    /// succeed.
243    ///
244    /// [google.cloud.kms.v1.CryptoKey]: kms::model::CryptoKey
245    pub fn get_protected_resources_summary(
246        &self,
247    ) -> super::builder::key_tracking_service::GetProtectedResourcesSummary {
248        super::builder::key_tracking_service::GetProtectedResourcesSummary::new(self.inner.clone())
249    }
250
251    /// Returns metadata about the resources protected by the given Cloud KMS
252    /// [CryptoKey][google.cloud.kms.v1.CryptoKey] in the given Cloud organization.
253    ///
254    /// [google.cloud.kms.v1.CryptoKey]: kms::model::CryptoKey
255    pub fn search_protected_resources(
256        &self,
257    ) -> super::builder::key_tracking_service::SearchProtectedResources {
258        super::builder::key_tracking_service::SearchProtectedResources::new(self.inner.clone())
259    }
260}