Skip to main content

google_cloud_kms_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 Cloud Key Management Service (KMS) API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_kms_v1::client::Autokey;
24/// use google_cloud_gax::paginator::ItemPaginator as _;
25/// async fn sample(
26///    parent: &str,
27/// ) -> anyhow::Result<()> {
28///     let client = Autokey::builder().build().await?;
29///     let mut list = client.list_key_handles()
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 interfaces for using [Cloud KMS
42/// Autokey](https://cloud.google.com/kms/help/autokey) to provision new
43/// [CryptoKeys][google.cloud.kms.v1.CryptoKey], ready for Customer Managed
44/// Encryption Key (CMEK) use, on-demand. To support certain client tooling, this
45/// feature is modeled around a [KeyHandle][google.cloud.kms.v1.KeyHandle]
46/// resource: creating a [KeyHandle][google.cloud.kms.v1.KeyHandle] in a resource
47/// project and given location triggers Cloud KMS Autokey to provision a
48/// [CryptoKey][google.cloud.kms.v1.CryptoKey] in the configured key project and
49/// the same location.
50///
51/// Prior to use in a given resource project,
52/// [UpdateAutokeyConfig][google.cloud.kms.v1.AutokeyAdmin.UpdateAutokeyConfig]
53/// should have been called on an ancestor folder, setting the key project where
54/// Cloud KMS Autokey should create new
55/// [CryptoKeys][google.cloud.kms.v1.CryptoKey]. See documentation for additional
56/// prerequisites. To check what key project, if any, is currently configured on
57/// a resource project's ancestor folder, see
58/// [ShowEffectiveAutokeyConfig][google.cloud.kms.v1.AutokeyAdmin.ShowEffectiveAutokeyConfig].
59///
60/// [google.cloud.kms.v1.AutokeyAdmin.ShowEffectiveAutokeyConfig]: crate::client::AutokeyAdmin::show_effective_autokey_config
61/// [google.cloud.kms.v1.AutokeyAdmin.UpdateAutokeyConfig]: crate::client::AutokeyAdmin::update_autokey_config
62/// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
63/// [google.cloud.kms.v1.KeyHandle]: crate::model::KeyHandle
64///
65/// # Configuration
66///
67/// To configure `Autokey` use the `with_*` methods in the type returned
68/// by [builder()][Autokey::builder]. The default configuration should
69/// work for most applications. Common configuration changes include
70///
71/// * [with_endpoint()]: by default this client uses the global default endpoint
72///   (`https://cloudkms.googleapis.com`). Applications using regional
73///   endpoints or running in restricted networks (e.g. a network configured
74//    with [Private Google Access with VPC Service Controls]) may want to
75///   override this default.
76/// * [with_credentials()]: by default this client uses
77///   [Application Default Credentials]. Applications using custom
78///   authentication may need to override this default.
79///
80/// [with_endpoint()]: super::builder::autokey::ClientBuilder::with_endpoint
81/// [with_credentials()]: super::builder::autokey::ClientBuilder::with_credentials
82/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
83/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
84///
85/// # Pooling and Cloning
86///
87/// `Autokey` holds a connection pool internally, it is advised to
88/// create one and reuse it. You do not need to wrap `Autokey` in
89/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
90/// already uses an `Arc` internally.
91#[derive(Clone, Debug)]
92pub struct Autokey {
93    inner: std::sync::Arc<dyn super::stub::dynamic::Autokey>,
94}
95
96impl Autokey {
97    /// Returns a builder for [Autokey].
98    ///
99    /// ```
100    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
101    /// # use google_cloud_kms_v1::client::Autokey;
102    /// let client = Autokey::builder().build().await?;
103    /// # Ok(()) }
104    /// ```
105    pub fn builder() -> super::builder::autokey::ClientBuilder {
106        crate::new_client_builder(super::builder::autokey::client::Factory)
107    }
108
109    /// Creates a new client from the provided stub.
110    ///
111    /// The most common case for calling this function is in tests mocking the
112    /// client's behavior.
113    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
114    where
115        T: super::stub::Autokey + 'static,
116    {
117        Self { inner: stub.into() }
118    }
119
120    pub(crate) async fn new(
121        config: gaxi::options::ClientConfig,
122    ) -> crate::ClientBuilderResult<Self> {
123        let inner = Self::build_inner(config).await?;
124        Ok(Self { inner })
125    }
126
127    async fn build_inner(
128        conf: gaxi::options::ClientConfig,
129    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::Autokey>> {
130        if gaxi::options::tracing_enabled(&conf) {
131            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
132        }
133        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
134    }
135
136    async fn build_transport(
137        conf: gaxi::options::ClientConfig,
138    ) -> crate::ClientBuilderResult<impl super::stub::Autokey> {
139        super::transport::Autokey::new(conf).await
140    }
141
142    async fn build_with_tracing(
143        conf: gaxi::options::ClientConfig,
144    ) -> crate::ClientBuilderResult<impl super::stub::Autokey> {
145        Self::build_transport(conf)
146            .await
147            .map(super::tracing::Autokey::new)
148    }
149
150    /// Creates a new [KeyHandle][google.cloud.kms.v1.KeyHandle], triggering the
151    /// provisioning of a new [CryptoKey][google.cloud.kms.v1.CryptoKey] for CMEK
152    /// use with the given resource type in the configured key project and the same
153    /// location. [GetOperation][google.longrunning.Operations.GetOperation] should
154    /// be used to resolve the resulting long-running operation and get the
155    /// resulting [KeyHandle][google.cloud.kms.v1.KeyHandle] and
156    /// [CryptoKey][google.cloud.kms.v1.CryptoKey].
157    ///
158    /// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
159    /// [google.cloud.kms.v1.KeyHandle]: crate::model::KeyHandle
160    ///
161    /// # Long running operations
162    ///
163    /// This method is used to start, and/or poll a [long-running Operation].
164    /// The [Working with long-running operations] chapter in the [user guide]
165    /// covers these operations in detail.
166    ///
167    /// [long-running operation]: https://google.aip.dev/151
168    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
169    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
170    ///
171    /// # Example
172    /// ```
173    /// # use google_cloud_kms_v1::client::Autokey;
174    /// use google_cloud_lro::Poller;
175    /// use google_cloud_kms_v1::model::KeyHandle;
176    /// use google_cloud_kms_v1::Result;
177    /// async fn sample(
178    ///    client: &Autokey, parent: &str
179    /// ) -> Result<()> {
180    ///     let response = client.create_key_handle()
181    ///         .set_parent(parent)
182    ///         .set_key_handle(
183    ///             KeyHandle::new()/* set fields */
184    ///         )
185    ///         .poller().until_done().await?;
186    ///     println!("response {:?}", response);
187    ///     Ok(())
188    /// }
189    /// ```
190    pub fn create_key_handle(&self) -> super::builder::autokey::CreateKeyHandle {
191        super::builder::autokey::CreateKeyHandle::new(self.inner.clone())
192    }
193
194    /// Returns the [KeyHandle][google.cloud.kms.v1.KeyHandle].
195    ///
196    /// [google.cloud.kms.v1.KeyHandle]: crate::model::KeyHandle
197    ///
198    /// # Example
199    /// ```
200    /// # use google_cloud_kms_v1::client::Autokey;
201    /// use google_cloud_kms_v1::Result;
202    /// async fn sample(
203    ///    client: &Autokey, project_id: &str, location_id: &str, key_handle_id: &str
204    /// ) -> Result<()> {
205    ///     let response = client.get_key_handle()
206    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/keyHandles/{key_handle_id}"))
207    ///         .send().await?;
208    ///     println!("response {:?}", response);
209    ///     Ok(())
210    /// }
211    /// ```
212    pub fn get_key_handle(&self) -> super::builder::autokey::GetKeyHandle {
213        super::builder::autokey::GetKeyHandle::new(self.inner.clone())
214    }
215
216    /// Lists [KeyHandles][google.cloud.kms.v1.KeyHandle].
217    ///
218    /// [google.cloud.kms.v1.KeyHandle]: crate::model::KeyHandle
219    ///
220    /// # Example
221    /// ```
222    /// # use google_cloud_kms_v1::client::Autokey;
223    /// use google_cloud_gax::paginator::ItemPaginator as _;
224    /// use google_cloud_kms_v1::Result;
225    /// async fn sample(
226    ///    client: &Autokey, parent: &str
227    /// ) -> Result<()> {
228    ///     let mut list = client.list_key_handles()
229    ///         .set_parent(parent)
230    ///         .by_item();
231    ///     while let Some(item) = list.next().await.transpose()? {
232    ///         println!("{:?}", item);
233    ///     }
234    ///     Ok(())
235    /// }
236    /// ```
237    pub fn list_key_handles(&self) -> super::builder::autokey::ListKeyHandles {
238        super::builder::autokey::ListKeyHandles::new(self.inner.clone())
239    }
240
241    /// Lists information about the supported locations for this service.
242    ///
243    /// This method lists locations based on the resource scope provided in
244    /// the [ListLocationsRequest.name] field:
245    ///
246    /// * **Global locations**: If `name` is empty, the method lists the
247    ///   public locations available to all projects. * **Project-specific
248    ///   locations**: If `name` follows the format
249    ///   `projects/{project}`, the method lists locations visible to that
250    ///   specific project. This includes public, private, or other
251    ///   project-specific locations enabled for the project.
252    ///
253    /// For gRPC and client library implementations, the resource name is
254    /// passed as the `name` field. For direct service calls, the resource
255    /// name is
256    /// incorporated into the request path based on the specific service
257    /// implementation and version.
258    ///
259    /// # Example
260    /// ```
261    /// # use google_cloud_kms_v1::client::Autokey;
262    /// use google_cloud_gax::paginator::ItemPaginator as _;
263    /// use google_cloud_kms_v1::Result;
264    /// async fn sample(
265    ///    client: &Autokey
266    /// ) -> Result<()> {
267    ///     let mut list = client.list_locations()
268    ///         /* set fields */
269    ///         .by_item();
270    ///     while let Some(item) = list.next().await.transpose()? {
271    ///         println!("{:?}", item);
272    ///     }
273    ///     Ok(())
274    /// }
275    /// ```
276    pub fn list_locations(&self) -> super::builder::autokey::ListLocations {
277        super::builder::autokey::ListLocations::new(self.inner.clone())
278    }
279
280    /// Gets information about a location.
281    ///
282    /// # Example
283    /// ```
284    /// # use google_cloud_kms_v1::client::Autokey;
285    /// use google_cloud_kms_v1::Result;
286    /// async fn sample(
287    ///    client: &Autokey
288    /// ) -> Result<()> {
289    ///     let response = client.get_location()
290    ///         /* set fields */
291    ///         .send().await?;
292    ///     println!("response {:?}", response);
293    ///     Ok(())
294    /// }
295    /// ```
296    pub fn get_location(&self) -> super::builder::autokey::GetLocation {
297        super::builder::autokey::GetLocation::new(self.inner.clone())
298    }
299
300    /// Sets the access control policy on the specified resource. Replaces
301    /// any existing policy.
302    ///
303    /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
304    /// errors.
305    ///
306    /// # Example
307    /// ```
308    /// # use google_cloud_kms_v1::client::Autokey;
309    /// use google_cloud_kms_v1::Result;
310    /// async fn sample(
311    ///    client: &Autokey
312    /// ) -> Result<()> {
313    ///     let response = client.set_iam_policy()
314    ///         /* set fields */
315    ///         .send().await?;
316    ///     println!("response {:?}", response);
317    ///     Ok(())
318    /// }
319    /// ```
320    pub fn set_iam_policy(&self) -> super::builder::autokey::SetIamPolicy {
321        super::builder::autokey::SetIamPolicy::new(self.inner.clone())
322    }
323
324    /// Gets the access control policy for a resource. Returns an empty policy
325    /// if the resource exists and does not have a policy set.
326    ///
327    /// # Example
328    /// ```
329    /// # use google_cloud_kms_v1::client::Autokey;
330    /// use google_cloud_kms_v1::Result;
331    /// async fn sample(
332    ///    client: &Autokey
333    /// ) -> Result<()> {
334    ///     let response = client.get_iam_policy()
335    ///         /* set fields */
336    ///         .send().await?;
337    ///     println!("response {:?}", response);
338    ///     Ok(())
339    /// }
340    /// ```
341    pub fn get_iam_policy(&self) -> super::builder::autokey::GetIamPolicy {
342        super::builder::autokey::GetIamPolicy::new(self.inner.clone())
343    }
344
345    /// Returns permissions that a caller has on the specified resource. If the
346    /// resource does not exist, this will return an empty set of
347    /// permissions, not a `NOT_FOUND` error.
348    ///
349    /// Note: This operation is designed to be used for building
350    /// permission-aware UIs and command-line tools, not for authorization
351    /// checking. This operation may "fail open" without warning.
352    ///
353    /// # Example
354    /// ```
355    /// # use google_cloud_kms_v1::client::Autokey;
356    /// use google_cloud_kms_v1::Result;
357    /// async fn sample(
358    ///    client: &Autokey
359    /// ) -> Result<()> {
360    ///     let response = client.test_iam_permissions()
361    ///         /* set fields */
362    ///         .send().await?;
363    ///     println!("response {:?}", response);
364    ///     Ok(())
365    /// }
366    /// ```
367    pub fn test_iam_permissions(&self) -> super::builder::autokey::TestIamPermissions {
368        super::builder::autokey::TestIamPermissions::new(self.inner.clone())
369    }
370
371    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
372    ///
373    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
374    ///
375    /// # Example
376    /// ```
377    /// # use google_cloud_kms_v1::client::Autokey;
378    /// use google_cloud_kms_v1::Result;
379    /// async fn sample(
380    ///    client: &Autokey
381    /// ) -> Result<()> {
382    ///     let response = client.get_operation()
383    ///         /* set fields */
384    ///         .send().await?;
385    ///     println!("response {:?}", response);
386    ///     Ok(())
387    /// }
388    /// ```
389    pub fn get_operation(&self) -> super::builder::autokey::GetOperation {
390        super::builder::autokey::GetOperation::new(self.inner.clone())
391    }
392}
393
394/// Implements a client for the Cloud Key Management Service (KMS) API.
395///
396/// # Example
397/// ```
398/// # use google_cloud_kms_v1::client::AutokeyAdmin;
399/// async fn sample(
400///    folder_id: &str,
401/// ) -> anyhow::Result<()> {
402///     let client = AutokeyAdmin::builder().build().await?;
403///     let response = client.get_autokey_config()
404///         .set_name(format!("folders/{folder_id}/autokeyConfig"))
405///         .send().await?;
406///     println!("response {:?}", response);
407///     Ok(())
408/// }
409/// ```
410///
411/// # Service Description
412///
413/// Provides interfaces for managing [Cloud KMS
414/// Autokey](https://cloud.google.com/kms/help/autokey) folder-level or
415/// project-level configurations. A configuration is inherited by all descendent
416/// folders and projects. A configuration at a folder or project overrides any
417/// other configurations in its ancestry. Setting a configuration on a folder is
418/// a prerequisite for Cloud KMS Autokey, so that users working in a descendant
419/// project can request provisioned [CryptoKeys][google.cloud.kms.v1.CryptoKey],
420/// ready for Customer Managed Encryption Key (CMEK) use, on-demand when using
421/// the dedicated key project mode. This is not required when using the delegated
422/// key management mode for same-project keys.
423///
424/// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
425///
426/// # Configuration
427///
428/// To configure `AutokeyAdmin` use the `with_*` methods in the type returned
429/// by [builder()][AutokeyAdmin::builder]. The default configuration should
430/// work for most applications. Common configuration changes include
431///
432/// * [with_endpoint()]: by default this client uses the global default endpoint
433///   (`https://cloudkms.googleapis.com`). Applications using regional
434///   endpoints or running in restricted networks (e.g. a network configured
435//    with [Private Google Access with VPC Service Controls]) may want to
436///   override this default.
437/// * [with_credentials()]: by default this client uses
438///   [Application Default Credentials]. Applications using custom
439///   authentication may need to override this default.
440///
441/// [with_endpoint()]: super::builder::autokey_admin::ClientBuilder::with_endpoint
442/// [with_credentials()]: super::builder::autokey_admin::ClientBuilder::with_credentials
443/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
444/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
445///
446/// # Pooling and Cloning
447///
448/// `AutokeyAdmin` holds a connection pool internally, it is advised to
449/// create one and reuse it. You do not need to wrap `AutokeyAdmin` in
450/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
451/// already uses an `Arc` internally.
452#[derive(Clone, Debug)]
453pub struct AutokeyAdmin {
454    inner: std::sync::Arc<dyn super::stub::dynamic::AutokeyAdmin>,
455}
456
457impl AutokeyAdmin {
458    /// Returns a builder for [AutokeyAdmin].
459    ///
460    /// ```
461    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
462    /// # use google_cloud_kms_v1::client::AutokeyAdmin;
463    /// let client = AutokeyAdmin::builder().build().await?;
464    /// # Ok(()) }
465    /// ```
466    pub fn builder() -> super::builder::autokey_admin::ClientBuilder {
467        crate::new_client_builder(super::builder::autokey_admin::client::Factory)
468    }
469
470    /// Creates a new client from the provided stub.
471    ///
472    /// The most common case for calling this function is in tests mocking the
473    /// client's behavior.
474    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
475    where
476        T: super::stub::AutokeyAdmin + 'static,
477    {
478        Self { inner: stub.into() }
479    }
480
481    pub(crate) async fn new(
482        config: gaxi::options::ClientConfig,
483    ) -> crate::ClientBuilderResult<Self> {
484        let inner = Self::build_inner(config).await?;
485        Ok(Self { inner })
486    }
487
488    async fn build_inner(
489        conf: gaxi::options::ClientConfig,
490    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::AutokeyAdmin>> {
491        if gaxi::options::tracing_enabled(&conf) {
492            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
493        }
494        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
495    }
496
497    async fn build_transport(
498        conf: gaxi::options::ClientConfig,
499    ) -> crate::ClientBuilderResult<impl super::stub::AutokeyAdmin> {
500        super::transport::AutokeyAdmin::new(conf).await
501    }
502
503    async fn build_with_tracing(
504        conf: gaxi::options::ClientConfig,
505    ) -> crate::ClientBuilderResult<impl super::stub::AutokeyAdmin> {
506        Self::build_transport(conf)
507            .await
508            .map(super::tracing::AutokeyAdmin::new)
509    }
510
511    /// Updates the [AutokeyConfig][google.cloud.kms.v1.AutokeyConfig] for a folder
512    /// or a project. The caller must have both `cloudkms.autokeyConfigs.update`
513    /// permission on the parent folder and `cloudkms.cryptoKeys.setIamPolicy`
514    /// permission on the provided key project. A
515    /// [KeyHandle][google.cloud.kms.v1.KeyHandle] creation in the folder's
516    /// descendant projects will use this configuration to determine where to
517    /// create the resulting [CryptoKey][google.cloud.kms.v1.CryptoKey].
518    ///
519    /// [google.cloud.kms.v1.AutokeyConfig]: crate::model::AutokeyConfig
520    /// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
521    /// [google.cloud.kms.v1.KeyHandle]: crate::model::KeyHandle
522    ///
523    /// # Example
524    /// ```
525    /// # use google_cloud_kms_v1::client::AutokeyAdmin;
526    /// # extern crate wkt as google_cloud_wkt;
527    /// use google_cloud_wkt::FieldMask;
528    /// use google_cloud_kms_v1::model::AutokeyConfig;
529    /// use google_cloud_kms_v1::Result;
530    /// async fn sample(
531    ///    client: &AutokeyAdmin, folder_id: &str
532    /// ) -> Result<()> {
533    ///     let response = client.update_autokey_config()
534    ///         .set_autokey_config(
535    ///             AutokeyConfig::new().set_name(format!("folders/{folder_id}/autokeyConfig"))/* set fields */
536    ///         )
537    ///         .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
538    ///         .send().await?;
539    ///     println!("response {:?}", response);
540    ///     Ok(())
541    /// }
542    /// ```
543    pub fn update_autokey_config(&self) -> super::builder::autokey_admin::UpdateAutokeyConfig {
544        super::builder::autokey_admin::UpdateAutokeyConfig::new(self.inner.clone())
545    }
546
547    /// Returns the [AutokeyConfig][google.cloud.kms.v1.AutokeyConfig] for a folder
548    /// or project.
549    ///
550    /// [google.cloud.kms.v1.AutokeyConfig]: crate::model::AutokeyConfig
551    ///
552    /// # Example
553    /// ```
554    /// # use google_cloud_kms_v1::client::AutokeyAdmin;
555    /// use google_cloud_kms_v1::Result;
556    /// async fn sample(
557    ///    client: &AutokeyAdmin, folder_id: &str
558    /// ) -> Result<()> {
559    ///     let response = client.get_autokey_config()
560    ///         .set_name(format!("folders/{folder_id}/autokeyConfig"))
561    ///         .send().await?;
562    ///     println!("response {:?}", response);
563    ///     Ok(())
564    /// }
565    /// ```
566    pub fn get_autokey_config(&self) -> super::builder::autokey_admin::GetAutokeyConfig {
567        super::builder::autokey_admin::GetAutokeyConfig::new(self.inner.clone())
568    }
569
570    /// Returns the effective Cloud KMS Autokey configuration for a given project.
571    ///
572    /// # Example
573    /// ```
574    /// # use google_cloud_kms_v1::client::AutokeyAdmin;
575    /// use google_cloud_kms_v1::Result;
576    /// async fn sample(
577    ///    client: &AutokeyAdmin
578    /// ) -> Result<()> {
579    ///     let response = client.show_effective_autokey_config()
580    ///         /* set fields */
581    ///         .send().await?;
582    ///     println!("response {:?}", response);
583    ///     Ok(())
584    /// }
585    /// ```
586    pub fn show_effective_autokey_config(
587        &self,
588    ) -> super::builder::autokey_admin::ShowEffectiveAutokeyConfig {
589        super::builder::autokey_admin::ShowEffectiveAutokeyConfig::new(self.inner.clone())
590    }
591
592    /// Lists information about the supported locations for this service.
593    ///
594    /// This method lists locations based on the resource scope provided in
595    /// the [ListLocationsRequest.name] field:
596    ///
597    /// * **Global locations**: If `name` is empty, the method lists the
598    ///   public locations available to all projects. * **Project-specific
599    ///   locations**: If `name` follows the format
600    ///   `projects/{project}`, the method lists locations visible to that
601    ///   specific project. This includes public, private, or other
602    ///   project-specific locations enabled for the project.
603    ///
604    /// For gRPC and client library implementations, the resource name is
605    /// passed as the `name` field. For direct service calls, the resource
606    /// name is
607    /// incorporated into the request path based on the specific service
608    /// implementation and version.
609    ///
610    /// # Example
611    /// ```
612    /// # use google_cloud_kms_v1::client::AutokeyAdmin;
613    /// use google_cloud_gax::paginator::ItemPaginator as _;
614    /// use google_cloud_kms_v1::Result;
615    /// async fn sample(
616    ///    client: &AutokeyAdmin
617    /// ) -> Result<()> {
618    ///     let mut list = client.list_locations()
619    ///         /* set fields */
620    ///         .by_item();
621    ///     while let Some(item) = list.next().await.transpose()? {
622    ///         println!("{:?}", item);
623    ///     }
624    ///     Ok(())
625    /// }
626    /// ```
627    pub fn list_locations(&self) -> super::builder::autokey_admin::ListLocations {
628        super::builder::autokey_admin::ListLocations::new(self.inner.clone())
629    }
630
631    /// Gets information about a location.
632    ///
633    /// # Example
634    /// ```
635    /// # use google_cloud_kms_v1::client::AutokeyAdmin;
636    /// use google_cloud_kms_v1::Result;
637    /// async fn sample(
638    ///    client: &AutokeyAdmin
639    /// ) -> Result<()> {
640    ///     let response = client.get_location()
641    ///         /* set fields */
642    ///         .send().await?;
643    ///     println!("response {:?}", response);
644    ///     Ok(())
645    /// }
646    /// ```
647    pub fn get_location(&self) -> super::builder::autokey_admin::GetLocation {
648        super::builder::autokey_admin::GetLocation::new(self.inner.clone())
649    }
650
651    /// Sets the access control policy on the specified resource. Replaces
652    /// any existing policy.
653    ///
654    /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
655    /// errors.
656    ///
657    /// # Example
658    /// ```
659    /// # use google_cloud_kms_v1::client::AutokeyAdmin;
660    /// use google_cloud_kms_v1::Result;
661    /// async fn sample(
662    ///    client: &AutokeyAdmin
663    /// ) -> Result<()> {
664    ///     let response = client.set_iam_policy()
665    ///         /* set fields */
666    ///         .send().await?;
667    ///     println!("response {:?}", response);
668    ///     Ok(())
669    /// }
670    /// ```
671    pub fn set_iam_policy(&self) -> super::builder::autokey_admin::SetIamPolicy {
672        super::builder::autokey_admin::SetIamPolicy::new(self.inner.clone())
673    }
674
675    /// Gets the access control policy for a resource. Returns an empty policy
676    /// if the resource exists and does not have a policy set.
677    ///
678    /// # Example
679    /// ```
680    /// # use google_cloud_kms_v1::client::AutokeyAdmin;
681    /// use google_cloud_kms_v1::Result;
682    /// async fn sample(
683    ///    client: &AutokeyAdmin
684    /// ) -> Result<()> {
685    ///     let response = client.get_iam_policy()
686    ///         /* set fields */
687    ///         .send().await?;
688    ///     println!("response {:?}", response);
689    ///     Ok(())
690    /// }
691    /// ```
692    pub fn get_iam_policy(&self) -> super::builder::autokey_admin::GetIamPolicy {
693        super::builder::autokey_admin::GetIamPolicy::new(self.inner.clone())
694    }
695
696    /// Returns permissions that a caller has on the specified resource. If the
697    /// resource does not exist, this will return an empty set of
698    /// permissions, not a `NOT_FOUND` error.
699    ///
700    /// Note: This operation is designed to be used for building
701    /// permission-aware UIs and command-line tools, not for authorization
702    /// checking. This operation may "fail open" without warning.
703    ///
704    /// # Example
705    /// ```
706    /// # use google_cloud_kms_v1::client::AutokeyAdmin;
707    /// use google_cloud_kms_v1::Result;
708    /// async fn sample(
709    ///    client: &AutokeyAdmin
710    /// ) -> Result<()> {
711    ///     let response = client.test_iam_permissions()
712    ///         /* set fields */
713    ///         .send().await?;
714    ///     println!("response {:?}", response);
715    ///     Ok(())
716    /// }
717    /// ```
718    pub fn test_iam_permissions(&self) -> super::builder::autokey_admin::TestIamPermissions {
719        super::builder::autokey_admin::TestIamPermissions::new(self.inner.clone())
720    }
721
722    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
723    ///
724    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
725    ///
726    /// # Example
727    /// ```
728    /// # use google_cloud_kms_v1::client::AutokeyAdmin;
729    /// use google_cloud_kms_v1::Result;
730    /// async fn sample(
731    ///    client: &AutokeyAdmin
732    /// ) -> Result<()> {
733    ///     let response = client.get_operation()
734    ///         /* set fields */
735    ///         .send().await?;
736    ///     println!("response {:?}", response);
737    ///     Ok(())
738    /// }
739    /// ```
740    pub fn get_operation(&self) -> super::builder::autokey_admin::GetOperation {
741        super::builder::autokey_admin::GetOperation::new(self.inner.clone())
742    }
743}
744
745/// Implements a client for the Cloud Key Management Service (KMS) API.
746///
747/// # Example
748/// ```
749/// # use google_cloud_kms_v1::client::EkmService;
750/// use google_cloud_gax::paginator::ItemPaginator as _;
751/// async fn sample(
752///    parent: &str,
753/// ) -> anyhow::Result<()> {
754///     let client = EkmService::builder().build().await?;
755///     let mut list = client.list_ekm_connections()
756///         .set_parent(parent)
757///         .by_item();
758///     while let Some(item) = list.next().await.transpose()? {
759///         println!("{:?}", item);
760///     }
761///     Ok(())
762/// }
763/// ```
764///
765/// # Service Description
766///
767/// Google Cloud Key Management EKM Service
768///
769/// Manages external cryptographic keys and operations using those keys.
770/// Implements a REST model with the following objects:
771///
772/// * [EkmConnection][google.cloud.kms.v1.EkmConnection]
773///
774/// [google.cloud.kms.v1.EkmConnection]: crate::model::EkmConnection
775///
776/// # Configuration
777///
778/// To configure `EkmService` use the `with_*` methods in the type returned
779/// by [builder()][EkmService::builder]. The default configuration should
780/// work for most applications. Common configuration changes include
781///
782/// * [with_endpoint()]: by default this client uses the global default endpoint
783///   (`https://cloudkms.googleapis.com`). Applications using regional
784///   endpoints or running in restricted networks (e.g. a network configured
785//    with [Private Google Access with VPC Service Controls]) may want to
786///   override this default.
787/// * [with_credentials()]: by default this client uses
788///   [Application Default Credentials]. Applications using custom
789///   authentication may need to override this default.
790///
791/// [with_endpoint()]: super::builder::ekm_service::ClientBuilder::with_endpoint
792/// [with_credentials()]: super::builder::ekm_service::ClientBuilder::with_credentials
793/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
794/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
795///
796/// # Pooling and Cloning
797///
798/// `EkmService` holds a connection pool internally, it is advised to
799/// create one and reuse it. You do not need to wrap `EkmService` in
800/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
801/// already uses an `Arc` internally.
802#[derive(Clone, Debug)]
803pub struct EkmService {
804    inner: std::sync::Arc<dyn super::stub::dynamic::EkmService>,
805}
806
807impl EkmService {
808    /// Returns a builder for [EkmService].
809    ///
810    /// ```
811    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
812    /// # use google_cloud_kms_v1::client::EkmService;
813    /// let client = EkmService::builder().build().await?;
814    /// # Ok(()) }
815    /// ```
816    pub fn builder() -> super::builder::ekm_service::ClientBuilder {
817        crate::new_client_builder(super::builder::ekm_service::client::Factory)
818    }
819
820    /// Creates a new client from the provided stub.
821    ///
822    /// The most common case for calling this function is in tests mocking the
823    /// client's behavior.
824    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
825    where
826        T: super::stub::EkmService + 'static,
827    {
828        Self { inner: stub.into() }
829    }
830
831    pub(crate) async fn new(
832        config: gaxi::options::ClientConfig,
833    ) -> crate::ClientBuilderResult<Self> {
834        let inner = Self::build_inner(config).await?;
835        Ok(Self { inner })
836    }
837
838    async fn build_inner(
839        conf: gaxi::options::ClientConfig,
840    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::EkmService>> {
841        if gaxi::options::tracing_enabled(&conf) {
842            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
843        }
844        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
845    }
846
847    async fn build_transport(
848        conf: gaxi::options::ClientConfig,
849    ) -> crate::ClientBuilderResult<impl super::stub::EkmService> {
850        super::transport::EkmService::new(conf).await
851    }
852
853    async fn build_with_tracing(
854        conf: gaxi::options::ClientConfig,
855    ) -> crate::ClientBuilderResult<impl super::stub::EkmService> {
856        Self::build_transport(conf)
857            .await
858            .map(super::tracing::EkmService::new)
859    }
860
861    /// Lists [EkmConnections][google.cloud.kms.v1.EkmConnection].
862    ///
863    /// [google.cloud.kms.v1.EkmConnection]: crate::model::EkmConnection
864    ///
865    /// # Example
866    /// ```
867    /// # use google_cloud_kms_v1::client::EkmService;
868    /// use google_cloud_gax::paginator::ItemPaginator as _;
869    /// use google_cloud_kms_v1::Result;
870    /// async fn sample(
871    ///    client: &EkmService, parent: &str
872    /// ) -> Result<()> {
873    ///     let mut list = client.list_ekm_connections()
874    ///         .set_parent(parent)
875    ///         .by_item();
876    ///     while let Some(item) = list.next().await.transpose()? {
877    ///         println!("{:?}", item);
878    ///     }
879    ///     Ok(())
880    /// }
881    /// ```
882    pub fn list_ekm_connections(&self) -> super::builder::ekm_service::ListEkmConnections {
883        super::builder::ekm_service::ListEkmConnections::new(self.inner.clone())
884    }
885
886    /// Returns metadata for a given
887    /// [EkmConnection][google.cloud.kms.v1.EkmConnection].
888    ///
889    /// [google.cloud.kms.v1.EkmConnection]: crate::model::EkmConnection
890    ///
891    /// # Example
892    /// ```
893    /// # use google_cloud_kms_v1::client::EkmService;
894    /// use google_cloud_kms_v1::Result;
895    /// async fn sample(
896    ///    client: &EkmService, project_id: &str, location_id: &str, ekm_connection_id: &str
897    /// ) -> Result<()> {
898    ///     let response = client.get_ekm_connection()
899    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/ekmConnections/{ekm_connection_id}"))
900    ///         .send().await?;
901    ///     println!("response {:?}", response);
902    ///     Ok(())
903    /// }
904    /// ```
905    pub fn get_ekm_connection(&self) -> super::builder::ekm_service::GetEkmConnection {
906        super::builder::ekm_service::GetEkmConnection::new(self.inner.clone())
907    }
908
909    /// Creates a new [EkmConnection][google.cloud.kms.v1.EkmConnection] in a given
910    /// Project and Location.
911    ///
912    /// [google.cloud.kms.v1.EkmConnection]: crate::model::EkmConnection
913    ///
914    /// # Example
915    /// ```
916    /// # use google_cloud_kms_v1::client::EkmService;
917    /// use google_cloud_kms_v1::model::EkmConnection;
918    /// use google_cloud_kms_v1::Result;
919    /// async fn sample(
920    ///    client: &EkmService, parent: &str
921    /// ) -> Result<()> {
922    ///     let response = client.create_ekm_connection()
923    ///         .set_parent(parent)
924    ///         .set_ekm_connection(
925    ///             EkmConnection::new()/* set fields */
926    ///         )
927    ///         .send().await?;
928    ///     println!("response {:?}", response);
929    ///     Ok(())
930    /// }
931    /// ```
932    pub fn create_ekm_connection(&self) -> super::builder::ekm_service::CreateEkmConnection {
933        super::builder::ekm_service::CreateEkmConnection::new(self.inner.clone())
934    }
935
936    /// Updates an [EkmConnection][google.cloud.kms.v1.EkmConnection]'s metadata.
937    ///
938    /// [google.cloud.kms.v1.EkmConnection]: crate::model::EkmConnection
939    ///
940    /// # Example
941    /// ```
942    /// # use google_cloud_kms_v1::client::EkmService;
943    /// # extern crate wkt as google_cloud_wkt;
944    /// use google_cloud_wkt::FieldMask;
945    /// use google_cloud_kms_v1::model::EkmConnection;
946    /// use google_cloud_kms_v1::Result;
947    /// async fn sample(
948    ///    client: &EkmService, project_id: &str, location_id: &str, ekm_connection_id: &str
949    /// ) -> Result<()> {
950    ///     let response = client.update_ekm_connection()
951    ///         .set_ekm_connection(
952    ///             EkmConnection::new().set_name(format!("projects/{project_id}/locations/{location_id}/ekmConnections/{ekm_connection_id}"))/* set fields */
953    ///         )
954    ///         .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
955    ///         .send().await?;
956    ///     println!("response {:?}", response);
957    ///     Ok(())
958    /// }
959    /// ```
960    pub fn update_ekm_connection(&self) -> super::builder::ekm_service::UpdateEkmConnection {
961        super::builder::ekm_service::UpdateEkmConnection::new(self.inner.clone())
962    }
963
964    /// Returns the [EkmConfig][google.cloud.kms.v1.EkmConfig] singleton resource
965    /// for a given project and location.
966    ///
967    /// [google.cloud.kms.v1.EkmConfig]: crate::model::EkmConfig
968    ///
969    /// # Example
970    /// ```
971    /// # use google_cloud_kms_v1::client::EkmService;
972    /// use google_cloud_kms_v1::Result;
973    /// async fn sample(
974    ///    client: &EkmService, project_id: &str, location_id: &str
975    /// ) -> Result<()> {
976    ///     let response = client.get_ekm_config()
977    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/ekmConfig"))
978    ///         .send().await?;
979    ///     println!("response {:?}", response);
980    ///     Ok(())
981    /// }
982    /// ```
983    pub fn get_ekm_config(&self) -> super::builder::ekm_service::GetEkmConfig {
984        super::builder::ekm_service::GetEkmConfig::new(self.inner.clone())
985    }
986
987    /// Updates the [EkmConfig][google.cloud.kms.v1.EkmConfig] singleton resource
988    /// for a given project and location.
989    ///
990    /// [google.cloud.kms.v1.EkmConfig]: crate::model::EkmConfig
991    ///
992    /// # Example
993    /// ```
994    /// # use google_cloud_kms_v1::client::EkmService;
995    /// # extern crate wkt as google_cloud_wkt;
996    /// use google_cloud_wkt::FieldMask;
997    /// use google_cloud_kms_v1::model::EkmConfig;
998    /// use google_cloud_kms_v1::Result;
999    /// async fn sample(
1000    ///    client: &EkmService, project_id: &str, location_id: &str
1001    /// ) -> Result<()> {
1002    ///     let response = client.update_ekm_config()
1003    ///         .set_ekm_config(
1004    ///             EkmConfig::new().set_name(format!("projects/{project_id}/locations/{location_id}/ekmConfig"))/* set fields */
1005    ///         )
1006    ///         .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
1007    ///         .send().await?;
1008    ///     println!("response {:?}", response);
1009    ///     Ok(())
1010    /// }
1011    /// ```
1012    pub fn update_ekm_config(&self) -> super::builder::ekm_service::UpdateEkmConfig {
1013        super::builder::ekm_service::UpdateEkmConfig::new(self.inner.clone())
1014    }
1015
1016    /// Verifies that Cloud KMS can successfully connect to the external key
1017    /// manager specified by an [EkmConnection][google.cloud.kms.v1.EkmConnection].
1018    /// If there is an error connecting to the EKM, this method returns a
1019    /// FAILED_PRECONDITION status containing structured information as described
1020    /// at <https://cloud.google.com/kms/docs/reference/ekm_errors>.
1021    ///
1022    /// [google.cloud.kms.v1.EkmConnection]: crate::model::EkmConnection
1023    ///
1024    /// # Example
1025    /// ```
1026    /// # use google_cloud_kms_v1::client::EkmService;
1027    /// use google_cloud_kms_v1::Result;
1028    /// async fn sample(
1029    ///    client: &EkmService
1030    /// ) -> Result<()> {
1031    ///     let response = client.verify_connectivity()
1032    ///         /* set fields */
1033    ///         .send().await?;
1034    ///     println!("response {:?}", response);
1035    ///     Ok(())
1036    /// }
1037    /// ```
1038    pub fn verify_connectivity(&self) -> super::builder::ekm_service::VerifyConnectivity {
1039        super::builder::ekm_service::VerifyConnectivity::new(self.inner.clone())
1040    }
1041
1042    /// Lists information about the supported locations for this service.
1043    ///
1044    /// This method lists locations based on the resource scope provided in
1045    /// the [ListLocationsRequest.name] field:
1046    ///
1047    /// * **Global locations**: If `name` is empty, the method lists the
1048    ///   public locations available to all projects. * **Project-specific
1049    ///   locations**: If `name` follows the format
1050    ///   `projects/{project}`, the method lists locations visible to that
1051    ///   specific project. This includes public, private, or other
1052    ///   project-specific locations enabled for the project.
1053    ///
1054    /// For gRPC and client library implementations, the resource name is
1055    /// passed as the `name` field. For direct service calls, the resource
1056    /// name is
1057    /// incorporated into the request path based on the specific service
1058    /// implementation and version.
1059    ///
1060    /// # Example
1061    /// ```
1062    /// # use google_cloud_kms_v1::client::EkmService;
1063    /// use google_cloud_gax::paginator::ItemPaginator as _;
1064    /// use google_cloud_kms_v1::Result;
1065    /// async fn sample(
1066    ///    client: &EkmService
1067    /// ) -> Result<()> {
1068    ///     let mut list = client.list_locations()
1069    ///         /* set fields */
1070    ///         .by_item();
1071    ///     while let Some(item) = list.next().await.transpose()? {
1072    ///         println!("{:?}", item);
1073    ///     }
1074    ///     Ok(())
1075    /// }
1076    /// ```
1077    pub fn list_locations(&self) -> super::builder::ekm_service::ListLocations {
1078        super::builder::ekm_service::ListLocations::new(self.inner.clone())
1079    }
1080
1081    /// Gets information about a location.
1082    ///
1083    /// # Example
1084    /// ```
1085    /// # use google_cloud_kms_v1::client::EkmService;
1086    /// use google_cloud_kms_v1::Result;
1087    /// async fn sample(
1088    ///    client: &EkmService
1089    /// ) -> Result<()> {
1090    ///     let response = client.get_location()
1091    ///         /* set fields */
1092    ///         .send().await?;
1093    ///     println!("response {:?}", response);
1094    ///     Ok(())
1095    /// }
1096    /// ```
1097    pub fn get_location(&self) -> super::builder::ekm_service::GetLocation {
1098        super::builder::ekm_service::GetLocation::new(self.inner.clone())
1099    }
1100
1101    /// Sets the access control policy on the specified resource. Replaces
1102    /// any existing policy.
1103    ///
1104    /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
1105    /// errors.
1106    ///
1107    /// # Example
1108    /// ```
1109    /// # use google_cloud_kms_v1::client::EkmService;
1110    /// use google_cloud_kms_v1::Result;
1111    /// async fn sample(
1112    ///    client: &EkmService
1113    /// ) -> Result<()> {
1114    ///     let response = client.set_iam_policy()
1115    ///         /* set fields */
1116    ///         .send().await?;
1117    ///     println!("response {:?}", response);
1118    ///     Ok(())
1119    /// }
1120    /// ```
1121    pub fn set_iam_policy(&self) -> super::builder::ekm_service::SetIamPolicy {
1122        super::builder::ekm_service::SetIamPolicy::new(self.inner.clone())
1123    }
1124
1125    /// Gets the access control policy for a resource. Returns an empty policy
1126    /// if the resource exists and does not have a policy set.
1127    ///
1128    /// # Example
1129    /// ```
1130    /// # use google_cloud_kms_v1::client::EkmService;
1131    /// use google_cloud_kms_v1::Result;
1132    /// async fn sample(
1133    ///    client: &EkmService
1134    /// ) -> Result<()> {
1135    ///     let response = client.get_iam_policy()
1136    ///         /* set fields */
1137    ///         .send().await?;
1138    ///     println!("response {:?}", response);
1139    ///     Ok(())
1140    /// }
1141    /// ```
1142    pub fn get_iam_policy(&self) -> super::builder::ekm_service::GetIamPolicy {
1143        super::builder::ekm_service::GetIamPolicy::new(self.inner.clone())
1144    }
1145
1146    /// Returns permissions that a caller has on the specified resource. If the
1147    /// resource does not exist, this will return an empty set of
1148    /// permissions, not a `NOT_FOUND` error.
1149    ///
1150    /// Note: This operation is designed to be used for building
1151    /// permission-aware UIs and command-line tools, not for authorization
1152    /// checking. This operation may "fail open" without warning.
1153    ///
1154    /// # Example
1155    /// ```
1156    /// # use google_cloud_kms_v1::client::EkmService;
1157    /// use google_cloud_kms_v1::Result;
1158    /// async fn sample(
1159    ///    client: &EkmService
1160    /// ) -> Result<()> {
1161    ///     let response = client.test_iam_permissions()
1162    ///         /* set fields */
1163    ///         .send().await?;
1164    ///     println!("response {:?}", response);
1165    ///     Ok(())
1166    /// }
1167    /// ```
1168    pub fn test_iam_permissions(&self) -> super::builder::ekm_service::TestIamPermissions {
1169        super::builder::ekm_service::TestIamPermissions::new(self.inner.clone())
1170    }
1171
1172    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
1173    ///
1174    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
1175    ///
1176    /// # Example
1177    /// ```
1178    /// # use google_cloud_kms_v1::client::EkmService;
1179    /// use google_cloud_kms_v1::Result;
1180    /// async fn sample(
1181    ///    client: &EkmService
1182    /// ) -> Result<()> {
1183    ///     let response = client.get_operation()
1184    ///         /* set fields */
1185    ///         .send().await?;
1186    ///     println!("response {:?}", response);
1187    ///     Ok(())
1188    /// }
1189    /// ```
1190    pub fn get_operation(&self) -> super::builder::ekm_service::GetOperation {
1191        super::builder::ekm_service::GetOperation::new(self.inner.clone())
1192    }
1193}
1194
1195/// Implements a client for the Cloud Key Management Service (KMS) API.
1196///
1197/// # Example
1198/// ```
1199/// # use google_cloud_kms_v1::client::HsmManagement;
1200/// use google_cloud_gax::paginator::ItemPaginator as _;
1201/// async fn sample(
1202///    parent: &str,
1203/// ) -> anyhow::Result<()> {
1204///     let client = HsmManagement::builder().build().await?;
1205///     let mut list = client.list_single_tenant_hsm_instances()
1206///         .set_parent(parent)
1207///         .by_item();
1208///     while let Some(item) = list.next().await.transpose()? {
1209///         println!("{:?}", item);
1210///     }
1211///     Ok(())
1212/// }
1213/// ```
1214///
1215/// # Service Description
1216///
1217/// Google Cloud HSM Management Service
1218///
1219/// Provides interfaces for managing HSM instances.
1220///
1221/// Implements a REST model with the following objects:
1222///
1223/// * [SingleTenantHsmInstance][google.cloud.kms.v1.SingleTenantHsmInstance]
1224/// * [SingleTenantHsmInstanceProposal][google.cloud.kms.v1.SingleTenantHsmInstanceProposal]
1225///
1226/// [google.cloud.kms.v1.SingleTenantHsmInstance]: crate::model::SingleTenantHsmInstance
1227/// [google.cloud.kms.v1.SingleTenantHsmInstanceProposal]: crate::model::SingleTenantHsmInstanceProposal
1228///
1229/// # Configuration
1230///
1231/// To configure `HsmManagement` use the `with_*` methods in the type returned
1232/// by [builder()][HsmManagement::builder]. The default configuration should
1233/// work for most applications. Common configuration changes include
1234///
1235/// * [with_endpoint()]: by default this client uses the global default endpoint
1236///   (`https://cloudkms.googleapis.com`). Applications using regional
1237///   endpoints or running in restricted networks (e.g. a network configured
1238//    with [Private Google Access with VPC Service Controls]) may want to
1239///   override this default.
1240/// * [with_credentials()]: by default this client uses
1241///   [Application Default Credentials]. Applications using custom
1242///   authentication may need to override this default.
1243///
1244/// [with_endpoint()]: super::builder::hsm_management::ClientBuilder::with_endpoint
1245/// [with_credentials()]: super::builder::hsm_management::ClientBuilder::with_credentials
1246/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
1247/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
1248///
1249/// # Pooling and Cloning
1250///
1251/// `HsmManagement` holds a connection pool internally, it is advised to
1252/// create one and reuse it. You do not need to wrap `HsmManagement` in
1253/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
1254/// already uses an `Arc` internally.
1255#[derive(Clone, Debug)]
1256pub struct HsmManagement {
1257    inner: std::sync::Arc<dyn super::stub::dynamic::HsmManagement>,
1258}
1259
1260impl HsmManagement {
1261    /// Returns a builder for [HsmManagement].
1262    ///
1263    /// ```
1264    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
1265    /// # use google_cloud_kms_v1::client::HsmManagement;
1266    /// let client = HsmManagement::builder().build().await?;
1267    /// # Ok(()) }
1268    /// ```
1269    pub fn builder() -> super::builder::hsm_management::ClientBuilder {
1270        crate::new_client_builder(super::builder::hsm_management::client::Factory)
1271    }
1272
1273    /// Creates a new client from the provided stub.
1274    ///
1275    /// The most common case for calling this function is in tests mocking the
1276    /// client's behavior.
1277    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
1278    where
1279        T: super::stub::HsmManagement + 'static,
1280    {
1281        Self { inner: stub.into() }
1282    }
1283
1284    pub(crate) async fn new(
1285        config: gaxi::options::ClientConfig,
1286    ) -> crate::ClientBuilderResult<Self> {
1287        let inner = Self::build_inner(config).await?;
1288        Ok(Self { inner })
1289    }
1290
1291    async fn build_inner(
1292        conf: gaxi::options::ClientConfig,
1293    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::HsmManagement>> {
1294        if gaxi::options::tracing_enabled(&conf) {
1295            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
1296        }
1297        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
1298    }
1299
1300    async fn build_transport(
1301        conf: gaxi::options::ClientConfig,
1302    ) -> crate::ClientBuilderResult<impl super::stub::HsmManagement> {
1303        super::transport::HsmManagement::new(conf).await
1304    }
1305
1306    async fn build_with_tracing(
1307        conf: gaxi::options::ClientConfig,
1308    ) -> crate::ClientBuilderResult<impl super::stub::HsmManagement> {
1309        Self::build_transport(conf)
1310            .await
1311            .map(super::tracing::HsmManagement::new)
1312    }
1313
1314    /// Lists
1315    /// [SingleTenantHsmInstances][google.cloud.kms.v1.SingleTenantHsmInstance].
1316    ///
1317    /// [google.cloud.kms.v1.SingleTenantHsmInstance]: crate::model::SingleTenantHsmInstance
1318    ///
1319    /// # Example
1320    /// ```
1321    /// # use google_cloud_kms_v1::client::HsmManagement;
1322    /// use google_cloud_gax::paginator::ItemPaginator as _;
1323    /// use google_cloud_kms_v1::Result;
1324    /// async fn sample(
1325    ///    client: &HsmManagement, parent: &str
1326    /// ) -> Result<()> {
1327    ///     let mut list = client.list_single_tenant_hsm_instances()
1328    ///         .set_parent(parent)
1329    ///         .by_item();
1330    ///     while let Some(item) = list.next().await.transpose()? {
1331    ///         println!("{:?}", item);
1332    ///     }
1333    ///     Ok(())
1334    /// }
1335    /// ```
1336    pub fn list_single_tenant_hsm_instances(
1337        &self,
1338    ) -> super::builder::hsm_management::ListSingleTenantHsmInstances {
1339        super::builder::hsm_management::ListSingleTenantHsmInstances::new(self.inner.clone())
1340    }
1341
1342    /// Returns metadata for a given
1343    /// [SingleTenantHsmInstance][google.cloud.kms.v1.SingleTenantHsmInstance].
1344    ///
1345    /// [google.cloud.kms.v1.SingleTenantHsmInstance]: crate::model::SingleTenantHsmInstance
1346    ///
1347    /// # Example
1348    /// ```
1349    /// # use google_cloud_kms_v1::client::HsmManagement;
1350    /// use google_cloud_kms_v1::Result;
1351    /// async fn sample(
1352    ///    client: &HsmManagement, project_id: &str, location_id: &str, single_tenant_hsm_instance_id: &str
1353    /// ) -> Result<()> {
1354    ///     let response = client.get_single_tenant_hsm_instance()
1355    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/singleTenantHsmInstances/{single_tenant_hsm_instance_id}"))
1356    ///         .send().await?;
1357    ///     println!("response {:?}", response);
1358    ///     Ok(())
1359    /// }
1360    /// ```
1361    pub fn get_single_tenant_hsm_instance(
1362        &self,
1363    ) -> super::builder::hsm_management::GetSingleTenantHsmInstance {
1364        super::builder::hsm_management::GetSingleTenantHsmInstance::new(self.inner.clone())
1365    }
1366
1367    /// Creates a new
1368    /// [SingleTenantHsmInstance][google.cloud.kms.v1.SingleTenantHsmInstance] in a
1369    /// given Project and Location. User must create a RegisterTwoFactorAuthKeys
1370    /// proposal with this single-tenant HSM instance to finish setup of the
1371    /// instance.
1372    ///
1373    /// [google.cloud.kms.v1.SingleTenantHsmInstance]: crate::model::SingleTenantHsmInstance
1374    ///
1375    /// # Long running operations
1376    ///
1377    /// This method is used to start, and/or poll a [long-running Operation].
1378    /// The [Working with long-running operations] chapter in the [user guide]
1379    /// covers these operations in detail.
1380    ///
1381    /// [long-running operation]: https://google.aip.dev/151
1382    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
1383    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
1384    ///
1385    /// # Example
1386    /// ```
1387    /// # use google_cloud_kms_v1::client::HsmManagement;
1388    /// use google_cloud_lro::Poller;
1389    /// use google_cloud_kms_v1::model::SingleTenantHsmInstance;
1390    /// use google_cloud_kms_v1::Result;
1391    /// async fn sample(
1392    ///    client: &HsmManagement, parent: &str
1393    /// ) -> Result<()> {
1394    ///     let response = client.create_single_tenant_hsm_instance()
1395    ///         .set_parent(parent)
1396    ///         .set_single_tenant_hsm_instance(
1397    ///             SingleTenantHsmInstance::new()/* set fields */
1398    ///         )
1399    ///         .poller().until_done().await?;
1400    ///     println!("response {:?}", response);
1401    ///     Ok(())
1402    /// }
1403    /// ```
1404    pub fn create_single_tenant_hsm_instance(
1405        &self,
1406    ) -> super::builder::hsm_management::CreateSingleTenantHsmInstance {
1407        super::builder::hsm_management::CreateSingleTenantHsmInstance::new(self.inner.clone())
1408    }
1409
1410    /// Creates a new
1411    /// [SingleTenantHsmInstanceProposal][google.cloud.kms.v1.SingleTenantHsmInstanceProposal]
1412    /// for a given
1413    /// [SingleTenantHsmInstance][google.cloud.kms.v1.SingleTenantHsmInstance].
1414    ///
1415    /// [google.cloud.kms.v1.SingleTenantHsmInstance]: crate::model::SingleTenantHsmInstance
1416    /// [google.cloud.kms.v1.SingleTenantHsmInstanceProposal]: crate::model::SingleTenantHsmInstanceProposal
1417    ///
1418    /// # Long running operations
1419    ///
1420    /// This method is used to start, and/or poll a [long-running Operation].
1421    /// The [Working with long-running operations] chapter in the [user guide]
1422    /// covers these operations in detail.
1423    ///
1424    /// [long-running operation]: https://google.aip.dev/151
1425    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
1426    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
1427    ///
1428    /// # Example
1429    /// ```
1430    /// # use google_cloud_kms_v1::client::HsmManagement;
1431    /// use google_cloud_lro::Poller;
1432    /// use google_cloud_kms_v1::model::SingleTenantHsmInstanceProposal;
1433    /// use google_cloud_kms_v1::Result;
1434    /// async fn sample(
1435    ///    client: &HsmManagement, project_id: &str, location_id: &str, single_tenant_hsm_instance_id: &str
1436    /// ) -> Result<()> {
1437    ///     let response = client.create_single_tenant_hsm_instance_proposal()
1438    ///         .set_parent(format!("projects/{project_id}/locations/{location_id}/singleTenantHsmInstances/{single_tenant_hsm_instance_id}"))
1439    ///         .set_single_tenant_hsm_instance_proposal(
1440    ///             SingleTenantHsmInstanceProposal::new()/* set fields */
1441    ///         )
1442    ///         .poller().until_done().await?;
1443    ///     println!("response {:?}", response);
1444    ///     Ok(())
1445    /// }
1446    /// ```
1447    pub fn create_single_tenant_hsm_instance_proposal(
1448        &self,
1449    ) -> super::builder::hsm_management::CreateSingleTenantHsmInstanceProposal {
1450        super::builder::hsm_management::CreateSingleTenantHsmInstanceProposal::new(
1451            self.inner.clone(),
1452        )
1453    }
1454
1455    /// Approves a
1456    /// [SingleTenantHsmInstanceProposal][google.cloud.kms.v1.SingleTenantHsmInstanceProposal]
1457    /// for a given
1458    /// [SingleTenantHsmInstance][google.cloud.kms.v1.SingleTenantHsmInstance]. The
1459    /// proposal must be in the
1460    /// [PENDING][google.cloud.kms.v1.SingleTenantHsmInstanceProposal.State.PENDING]
1461    /// state.
1462    ///
1463    /// [google.cloud.kms.v1.SingleTenantHsmInstance]: crate::model::SingleTenantHsmInstance
1464    /// [google.cloud.kms.v1.SingleTenantHsmInstanceProposal]: crate::model::SingleTenantHsmInstanceProposal
1465    /// [google.cloud.kms.v1.SingleTenantHsmInstanceProposal.State.PENDING]: crate::model::single_tenant_hsm_instance_proposal::State::Pending
1466    ///
1467    /// # Example
1468    /// ```
1469    /// # use google_cloud_kms_v1::client::HsmManagement;
1470    /// use google_cloud_kms_v1::Result;
1471    /// async fn sample(
1472    ///    client: &HsmManagement
1473    /// ) -> Result<()> {
1474    ///     let response = client.approve_single_tenant_hsm_instance_proposal()
1475    ///         /* set fields */
1476    ///         .send().await?;
1477    ///     println!("response {:?}", response);
1478    ///     Ok(())
1479    /// }
1480    /// ```
1481    pub fn approve_single_tenant_hsm_instance_proposal(
1482        &self,
1483    ) -> super::builder::hsm_management::ApproveSingleTenantHsmInstanceProposal {
1484        super::builder::hsm_management::ApproveSingleTenantHsmInstanceProposal::new(
1485            self.inner.clone(),
1486        )
1487    }
1488
1489    /// Executes a
1490    /// [SingleTenantHsmInstanceProposal][google.cloud.kms.v1.SingleTenantHsmInstanceProposal]
1491    /// for a given
1492    /// [SingleTenantHsmInstance][google.cloud.kms.v1.SingleTenantHsmInstance]. The
1493    /// proposal must be in the
1494    /// [APPROVED][google.cloud.kms.v1.SingleTenantHsmInstanceProposal.State.APPROVED]
1495    /// state.
1496    ///
1497    /// [google.cloud.kms.v1.SingleTenantHsmInstance]: crate::model::SingleTenantHsmInstance
1498    /// [google.cloud.kms.v1.SingleTenantHsmInstanceProposal]: crate::model::SingleTenantHsmInstanceProposal
1499    /// [google.cloud.kms.v1.SingleTenantHsmInstanceProposal.State.APPROVED]: crate::model::single_tenant_hsm_instance_proposal::State::Approved
1500    ///
1501    /// # Long running operations
1502    ///
1503    /// This method is used to start, and/or poll a [long-running Operation].
1504    /// The [Working with long-running operations] chapter in the [user guide]
1505    /// covers these operations in detail.
1506    ///
1507    /// [long-running operation]: https://google.aip.dev/151
1508    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
1509    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
1510    ///
1511    /// # Example
1512    /// ```
1513    /// # use google_cloud_kms_v1::client::HsmManagement;
1514    /// use google_cloud_lro::Poller;
1515    /// use google_cloud_kms_v1::Result;
1516    /// async fn sample(
1517    ///    client: &HsmManagement
1518    /// ) -> Result<()> {
1519    ///     let response = client.execute_single_tenant_hsm_instance_proposal()
1520    ///         /* set fields */
1521    ///         .poller().until_done().await?;
1522    ///     println!("response {:?}", response);
1523    ///     Ok(())
1524    /// }
1525    /// ```
1526    pub fn execute_single_tenant_hsm_instance_proposal(
1527        &self,
1528    ) -> super::builder::hsm_management::ExecuteSingleTenantHsmInstanceProposal {
1529        super::builder::hsm_management::ExecuteSingleTenantHsmInstanceProposal::new(
1530            self.inner.clone(),
1531        )
1532    }
1533
1534    /// Returns metadata for a given
1535    /// [SingleTenantHsmInstanceProposal][google.cloud.kms.v1.SingleTenantHsmInstanceProposal].
1536    ///
1537    /// [google.cloud.kms.v1.SingleTenantHsmInstanceProposal]: crate::model::SingleTenantHsmInstanceProposal
1538    ///
1539    /// # Example
1540    /// ```
1541    /// # use google_cloud_kms_v1::client::HsmManagement;
1542    /// use google_cloud_kms_v1::Result;
1543    /// async fn sample(
1544    ///    client: &HsmManagement, project_id: &str, location_id: &str, single_tenant_hsm_instance_id: &str, proposal_id: &str
1545    /// ) -> Result<()> {
1546    ///     let response = client.get_single_tenant_hsm_instance_proposal()
1547    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/singleTenantHsmInstances/{single_tenant_hsm_instance_id}/proposals/{proposal_id}"))
1548    ///         .send().await?;
1549    ///     println!("response {:?}", response);
1550    ///     Ok(())
1551    /// }
1552    /// ```
1553    pub fn get_single_tenant_hsm_instance_proposal(
1554        &self,
1555    ) -> super::builder::hsm_management::GetSingleTenantHsmInstanceProposal {
1556        super::builder::hsm_management::GetSingleTenantHsmInstanceProposal::new(self.inner.clone())
1557    }
1558
1559    /// Lists
1560    /// [SingleTenantHsmInstanceProposals][google.cloud.kms.v1.SingleTenantHsmInstanceProposal].
1561    ///
1562    /// [google.cloud.kms.v1.SingleTenantHsmInstanceProposal]: crate::model::SingleTenantHsmInstanceProposal
1563    ///
1564    /// # Example
1565    /// ```
1566    /// # use google_cloud_kms_v1::client::HsmManagement;
1567    /// use google_cloud_gax::paginator::ItemPaginator as _;
1568    /// use google_cloud_kms_v1::Result;
1569    /// async fn sample(
1570    ///    client: &HsmManagement, project_id: &str, location_id: &str, single_tenant_hsm_instance_id: &str
1571    /// ) -> Result<()> {
1572    ///     let mut list = client.list_single_tenant_hsm_instance_proposals()
1573    ///         .set_parent(format!("projects/{project_id}/locations/{location_id}/singleTenantHsmInstances/{single_tenant_hsm_instance_id}"))
1574    ///         .by_item();
1575    ///     while let Some(item) = list.next().await.transpose()? {
1576    ///         println!("{:?}", item);
1577    ///     }
1578    ///     Ok(())
1579    /// }
1580    /// ```
1581    pub fn list_single_tenant_hsm_instance_proposals(
1582        &self,
1583    ) -> super::builder::hsm_management::ListSingleTenantHsmInstanceProposals {
1584        super::builder::hsm_management::ListSingleTenantHsmInstanceProposals::new(
1585            self.inner.clone(),
1586        )
1587    }
1588
1589    /// Deletes a
1590    /// [SingleTenantHsmInstanceProposal][google.cloud.kms.v1.SingleTenantHsmInstanceProposal].
1591    ///
1592    /// [google.cloud.kms.v1.SingleTenantHsmInstanceProposal]: crate::model::SingleTenantHsmInstanceProposal
1593    ///
1594    /// # Example
1595    /// ```
1596    /// # use google_cloud_kms_v1::client::HsmManagement;
1597    /// use google_cloud_kms_v1::Result;
1598    /// async fn sample(
1599    ///    client: &HsmManagement, project_id: &str, location_id: &str, single_tenant_hsm_instance_id: &str, proposal_id: &str
1600    /// ) -> Result<()> {
1601    ///     client.delete_single_tenant_hsm_instance_proposal()
1602    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/singleTenantHsmInstances/{single_tenant_hsm_instance_id}/proposals/{proposal_id}"))
1603    ///         .send().await?;
1604    ///     Ok(())
1605    /// }
1606    /// ```
1607    pub fn delete_single_tenant_hsm_instance_proposal(
1608        &self,
1609    ) -> super::builder::hsm_management::DeleteSingleTenantHsmInstanceProposal {
1610        super::builder::hsm_management::DeleteSingleTenantHsmInstanceProposal::new(
1611            self.inner.clone(),
1612        )
1613    }
1614
1615    /// Lists information about the supported locations for this service.
1616    ///
1617    /// This method lists locations based on the resource scope provided in
1618    /// the [ListLocationsRequest.name] field:
1619    ///
1620    /// * **Global locations**: If `name` is empty, the method lists the
1621    ///   public locations available to all projects. * **Project-specific
1622    ///   locations**: If `name` follows the format
1623    ///   `projects/{project}`, the method lists locations visible to that
1624    ///   specific project. This includes public, private, or other
1625    ///   project-specific locations enabled for the project.
1626    ///
1627    /// For gRPC and client library implementations, the resource name is
1628    /// passed as the `name` field. For direct service calls, the resource
1629    /// name is
1630    /// incorporated into the request path based on the specific service
1631    /// implementation and version.
1632    ///
1633    /// # Example
1634    /// ```
1635    /// # use google_cloud_kms_v1::client::HsmManagement;
1636    /// use google_cloud_gax::paginator::ItemPaginator as _;
1637    /// use google_cloud_kms_v1::Result;
1638    /// async fn sample(
1639    ///    client: &HsmManagement
1640    /// ) -> Result<()> {
1641    ///     let mut list = client.list_locations()
1642    ///         /* set fields */
1643    ///         .by_item();
1644    ///     while let Some(item) = list.next().await.transpose()? {
1645    ///         println!("{:?}", item);
1646    ///     }
1647    ///     Ok(())
1648    /// }
1649    /// ```
1650    pub fn list_locations(&self) -> super::builder::hsm_management::ListLocations {
1651        super::builder::hsm_management::ListLocations::new(self.inner.clone())
1652    }
1653
1654    /// Gets information about a location.
1655    ///
1656    /// # Example
1657    /// ```
1658    /// # use google_cloud_kms_v1::client::HsmManagement;
1659    /// use google_cloud_kms_v1::Result;
1660    /// async fn sample(
1661    ///    client: &HsmManagement
1662    /// ) -> Result<()> {
1663    ///     let response = client.get_location()
1664    ///         /* set fields */
1665    ///         .send().await?;
1666    ///     println!("response {:?}", response);
1667    ///     Ok(())
1668    /// }
1669    /// ```
1670    pub fn get_location(&self) -> super::builder::hsm_management::GetLocation {
1671        super::builder::hsm_management::GetLocation::new(self.inner.clone())
1672    }
1673
1674    /// Sets the access control policy on the specified resource. Replaces
1675    /// any existing policy.
1676    ///
1677    /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
1678    /// errors.
1679    ///
1680    /// # Example
1681    /// ```
1682    /// # use google_cloud_kms_v1::client::HsmManagement;
1683    /// use google_cloud_kms_v1::Result;
1684    /// async fn sample(
1685    ///    client: &HsmManagement
1686    /// ) -> Result<()> {
1687    ///     let response = client.set_iam_policy()
1688    ///         /* set fields */
1689    ///         .send().await?;
1690    ///     println!("response {:?}", response);
1691    ///     Ok(())
1692    /// }
1693    /// ```
1694    pub fn set_iam_policy(&self) -> super::builder::hsm_management::SetIamPolicy {
1695        super::builder::hsm_management::SetIamPolicy::new(self.inner.clone())
1696    }
1697
1698    /// Gets the access control policy for a resource. Returns an empty policy
1699    /// if the resource exists and does not have a policy set.
1700    ///
1701    /// # Example
1702    /// ```
1703    /// # use google_cloud_kms_v1::client::HsmManagement;
1704    /// use google_cloud_kms_v1::Result;
1705    /// async fn sample(
1706    ///    client: &HsmManagement
1707    /// ) -> Result<()> {
1708    ///     let response = client.get_iam_policy()
1709    ///         /* set fields */
1710    ///         .send().await?;
1711    ///     println!("response {:?}", response);
1712    ///     Ok(())
1713    /// }
1714    /// ```
1715    pub fn get_iam_policy(&self) -> super::builder::hsm_management::GetIamPolicy {
1716        super::builder::hsm_management::GetIamPolicy::new(self.inner.clone())
1717    }
1718
1719    /// Returns permissions that a caller has on the specified resource. If the
1720    /// resource does not exist, this will return an empty set of
1721    /// permissions, not a `NOT_FOUND` error.
1722    ///
1723    /// Note: This operation is designed to be used for building
1724    /// permission-aware UIs and command-line tools, not for authorization
1725    /// checking. This operation may "fail open" without warning.
1726    ///
1727    /// # Example
1728    /// ```
1729    /// # use google_cloud_kms_v1::client::HsmManagement;
1730    /// use google_cloud_kms_v1::Result;
1731    /// async fn sample(
1732    ///    client: &HsmManagement
1733    /// ) -> Result<()> {
1734    ///     let response = client.test_iam_permissions()
1735    ///         /* set fields */
1736    ///         .send().await?;
1737    ///     println!("response {:?}", response);
1738    ///     Ok(())
1739    /// }
1740    /// ```
1741    pub fn test_iam_permissions(&self) -> super::builder::hsm_management::TestIamPermissions {
1742        super::builder::hsm_management::TestIamPermissions::new(self.inner.clone())
1743    }
1744
1745    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
1746    ///
1747    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
1748    ///
1749    /// # Example
1750    /// ```
1751    /// # use google_cloud_kms_v1::client::HsmManagement;
1752    /// use google_cloud_kms_v1::Result;
1753    /// async fn sample(
1754    ///    client: &HsmManagement
1755    /// ) -> Result<()> {
1756    ///     let response = client.get_operation()
1757    ///         /* set fields */
1758    ///         .send().await?;
1759    ///     println!("response {:?}", response);
1760    ///     Ok(())
1761    /// }
1762    /// ```
1763    pub fn get_operation(&self) -> super::builder::hsm_management::GetOperation {
1764        super::builder::hsm_management::GetOperation::new(self.inner.clone())
1765    }
1766}
1767
1768/// Implements a client for the Cloud Key Management Service (KMS) API.
1769///
1770/// # Example
1771/// ```
1772/// # use google_cloud_kms_v1::client::KeyManagementService;
1773/// use google_cloud_gax::paginator::ItemPaginator as _;
1774/// async fn sample(
1775///    parent: &str,
1776/// ) -> anyhow::Result<()> {
1777///     let client = KeyManagementService::builder().build().await?;
1778///     let mut list = client.list_key_rings()
1779///         .set_parent(parent)
1780///         .by_item();
1781///     while let Some(item) = list.next().await.transpose()? {
1782///         println!("{:?}", item);
1783///     }
1784///     Ok(())
1785/// }
1786/// ```
1787///
1788/// # Service Description
1789///
1790/// Google Cloud Key Management Service
1791///
1792/// Manages cryptographic keys and operations using those keys. Implements a REST
1793/// model with the following objects:
1794///
1795/// * [KeyRing][google.cloud.kms.v1.KeyRing]
1796/// * [CryptoKey][google.cloud.kms.v1.CryptoKey]
1797/// * [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion]
1798/// * [ImportJob][google.cloud.kms.v1.ImportJob]
1799///
1800/// If you are using manual gRPC libraries, see
1801/// [Using gRPC with Cloud KMS](https://cloud.google.com/kms/docs/grpc).
1802///
1803/// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
1804/// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
1805/// [google.cloud.kms.v1.ImportJob]: crate::model::ImportJob
1806/// [google.cloud.kms.v1.KeyRing]: crate::model::KeyRing
1807///
1808/// # Configuration
1809///
1810/// To configure `KeyManagementService` use the `with_*` methods in the type returned
1811/// by [builder()][KeyManagementService::builder]. The default configuration should
1812/// work for most applications. Common configuration changes include
1813///
1814/// * [with_endpoint()]: by default this client uses the global default endpoint
1815///   (`https://cloudkms.googleapis.com`). Applications using regional
1816///   endpoints or running in restricted networks (e.g. a network configured
1817//    with [Private Google Access with VPC Service Controls]) may want to
1818///   override this default.
1819/// * [with_credentials()]: by default this client uses
1820///   [Application Default Credentials]. Applications using custom
1821///   authentication may need to override this default.
1822///
1823/// [with_endpoint()]: super::builder::key_management_service::ClientBuilder::with_endpoint
1824/// [with_credentials()]: super::builder::key_management_service::ClientBuilder::with_credentials
1825/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
1826/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
1827///
1828/// # Pooling and Cloning
1829///
1830/// `KeyManagementService` holds a connection pool internally, it is advised to
1831/// create one and reuse it. You do not need to wrap `KeyManagementService` in
1832/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
1833/// already uses an `Arc` internally.
1834#[derive(Clone, Debug)]
1835pub struct KeyManagementService {
1836    inner: std::sync::Arc<dyn super::stub::dynamic::KeyManagementService>,
1837}
1838
1839impl KeyManagementService {
1840    /// Returns a builder for [KeyManagementService].
1841    ///
1842    /// ```
1843    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
1844    /// # use google_cloud_kms_v1::client::KeyManagementService;
1845    /// let client = KeyManagementService::builder().build().await?;
1846    /// # Ok(()) }
1847    /// ```
1848    pub fn builder() -> super::builder::key_management_service::ClientBuilder {
1849        crate::new_client_builder(super::builder::key_management_service::client::Factory)
1850    }
1851
1852    /// Creates a new client from the provided stub.
1853    ///
1854    /// The most common case for calling this function is in tests mocking the
1855    /// client's behavior.
1856    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
1857    where
1858        T: super::stub::KeyManagementService + 'static,
1859    {
1860        Self { inner: stub.into() }
1861    }
1862
1863    pub(crate) async fn new(
1864        config: gaxi::options::ClientConfig,
1865    ) -> crate::ClientBuilderResult<Self> {
1866        let inner = Self::build_inner(config).await?;
1867        Ok(Self { inner })
1868    }
1869
1870    async fn build_inner(
1871        conf: gaxi::options::ClientConfig,
1872    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::KeyManagementService>>
1873    {
1874        if gaxi::options::tracing_enabled(&conf) {
1875            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
1876        }
1877        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
1878    }
1879
1880    async fn build_transport(
1881        conf: gaxi::options::ClientConfig,
1882    ) -> crate::ClientBuilderResult<impl super::stub::KeyManagementService> {
1883        super::transport::KeyManagementService::new(conf).await
1884    }
1885
1886    async fn build_with_tracing(
1887        conf: gaxi::options::ClientConfig,
1888    ) -> crate::ClientBuilderResult<impl super::stub::KeyManagementService> {
1889        Self::build_transport(conf)
1890            .await
1891            .map(super::tracing::KeyManagementService::new)
1892    }
1893
1894    /// Lists [KeyRings][google.cloud.kms.v1.KeyRing].
1895    ///
1896    /// [google.cloud.kms.v1.KeyRing]: crate::model::KeyRing
1897    ///
1898    /// # Example
1899    /// ```
1900    /// # use google_cloud_kms_v1::client::KeyManagementService;
1901    /// use google_cloud_gax::paginator::ItemPaginator as _;
1902    /// use google_cloud_kms_v1::Result;
1903    /// async fn sample(
1904    ///    client: &KeyManagementService, parent: &str
1905    /// ) -> Result<()> {
1906    ///     let mut list = client.list_key_rings()
1907    ///         .set_parent(parent)
1908    ///         .by_item();
1909    ///     while let Some(item) = list.next().await.transpose()? {
1910    ///         println!("{:?}", item);
1911    ///     }
1912    ///     Ok(())
1913    /// }
1914    /// ```
1915    pub fn list_key_rings(&self) -> super::builder::key_management_service::ListKeyRings {
1916        super::builder::key_management_service::ListKeyRings::new(self.inner.clone())
1917    }
1918
1919    /// Lists [CryptoKeys][google.cloud.kms.v1.CryptoKey].
1920    ///
1921    /// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
1922    ///
1923    /// # Example
1924    /// ```
1925    /// # use google_cloud_kms_v1::client::KeyManagementService;
1926    /// use google_cloud_gax::paginator::ItemPaginator as _;
1927    /// use google_cloud_kms_v1::Result;
1928    /// async fn sample(
1929    ///    client: &KeyManagementService, project_id: &str, location_id: &str, key_ring_id: &str
1930    /// ) -> Result<()> {
1931    ///     let mut list = client.list_crypto_keys()
1932    ///         .set_parent(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}"))
1933    ///         .by_item();
1934    ///     while let Some(item) = list.next().await.transpose()? {
1935    ///         println!("{:?}", item);
1936    ///     }
1937    ///     Ok(())
1938    /// }
1939    /// ```
1940    pub fn list_crypto_keys(&self) -> super::builder::key_management_service::ListCryptoKeys {
1941        super::builder::key_management_service::ListCryptoKeys::new(self.inner.clone())
1942    }
1943
1944    /// Lists [CryptoKeyVersions][google.cloud.kms.v1.CryptoKeyVersion].
1945    ///
1946    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
1947    ///
1948    /// # Example
1949    /// ```
1950    /// # use google_cloud_kms_v1::client::KeyManagementService;
1951    /// use google_cloud_gax::paginator::ItemPaginator as _;
1952    /// use google_cloud_kms_v1::Result;
1953    /// async fn sample(
1954    ///    client: &KeyManagementService, project_id: &str, location_id: &str, key_ring_id: &str, crypto_key_id: &str
1955    /// ) -> Result<()> {
1956    ///     let mut list = client.list_crypto_key_versions()
1957    ///         .set_parent(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}/cryptoKeys/{crypto_key_id}"))
1958    ///         .by_item();
1959    ///     while let Some(item) = list.next().await.transpose()? {
1960    ///         println!("{:?}", item);
1961    ///     }
1962    ///     Ok(())
1963    /// }
1964    /// ```
1965    pub fn list_crypto_key_versions(
1966        &self,
1967    ) -> super::builder::key_management_service::ListCryptoKeyVersions {
1968        super::builder::key_management_service::ListCryptoKeyVersions::new(self.inner.clone())
1969    }
1970
1971    /// Lists [ImportJobs][google.cloud.kms.v1.ImportJob].
1972    ///
1973    /// [google.cloud.kms.v1.ImportJob]: crate::model::ImportJob
1974    ///
1975    /// # Example
1976    /// ```
1977    /// # use google_cloud_kms_v1::client::KeyManagementService;
1978    /// use google_cloud_gax::paginator::ItemPaginator as _;
1979    /// use google_cloud_kms_v1::Result;
1980    /// async fn sample(
1981    ///    client: &KeyManagementService, project_id: &str, location_id: &str, key_ring_id: &str
1982    /// ) -> Result<()> {
1983    ///     let mut list = client.list_import_jobs()
1984    ///         .set_parent(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}"))
1985    ///         .by_item();
1986    ///     while let Some(item) = list.next().await.transpose()? {
1987    ///         println!("{:?}", item);
1988    ///     }
1989    ///     Ok(())
1990    /// }
1991    /// ```
1992    pub fn list_import_jobs(&self) -> super::builder::key_management_service::ListImportJobs {
1993        super::builder::key_management_service::ListImportJobs::new(self.inner.clone())
1994    }
1995
1996    /// Lists the [RetiredResources][google.cloud.kms.v1.RetiredResource] which are
1997    /// the records of deleted [CryptoKeys][google.cloud.kms.v1.CryptoKey].
1998    /// RetiredResources prevent the reuse of these resource names after deletion.
1999    ///
2000    /// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
2001    /// [google.cloud.kms.v1.RetiredResource]: crate::model::RetiredResource
2002    ///
2003    /// # Example
2004    /// ```
2005    /// # use google_cloud_kms_v1::client::KeyManagementService;
2006    /// use google_cloud_gax::paginator::ItemPaginator as _;
2007    /// use google_cloud_kms_v1::Result;
2008    /// async fn sample(
2009    ///    client: &KeyManagementService, project_id: &str, location_id: &str
2010    /// ) -> Result<()> {
2011    ///     let mut list = client.list_retired_resources()
2012    ///         .set_parent(format!("projects/{project_id}/locations/{location_id}"))
2013    ///         .by_item();
2014    ///     while let Some(item) = list.next().await.transpose()? {
2015    ///         println!("{:?}", item);
2016    ///     }
2017    ///     Ok(())
2018    /// }
2019    /// ```
2020    pub fn list_retired_resources(
2021        &self,
2022    ) -> super::builder::key_management_service::ListRetiredResources {
2023        super::builder::key_management_service::ListRetiredResources::new(self.inner.clone())
2024    }
2025
2026    /// Returns metadata for a given [KeyRing][google.cloud.kms.v1.KeyRing].
2027    ///
2028    /// [google.cloud.kms.v1.KeyRing]: crate::model::KeyRing
2029    ///
2030    /// # Example
2031    /// ```
2032    /// # use google_cloud_kms_v1::client::KeyManagementService;
2033    /// use google_cloud_kms_v1::Result;
2034    /// async fn sample(
2035    ///    client: &KeyManagementService, project_id: &str, location_id: &str, key_ring_id: &str
2036    /// ) -> Result<()> {
2037    ///     let response = client.get_key_ring()
2038    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}"))
2039    ///         .send().await?;
2040    ///     println!("response {:?}", response);
2041    ///     Ok(())
2042    /// }
2043    /// ```
2044    pub fn get_key_ring(&self) -> super::builder::key_management_service::GetKeyRing {
2045        super::builder::key_management_service::GetKeyRing::new(self.inner.clone())
2046    }
2047
2048    /// Returns metadata for a given [CryptoKey][google.cloud.kms.v1.CryptoKey], as
2049    /// well as its [primary][google.cloud.kms.v1.CryptoKey.primary]
2050    /// [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion].
2051    ///
2052    /// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
2053    /// [google.cloud.kms.v1.CryptoKey.primary]: crate::model::CryptoKey::primary
2054    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2055    ///
2056    /// # Example
2057    /// ```
2058    /// # use google_cloud_kms_v1::client::KeyManagementService;
2059    /// use google_cloud_kms_v1::Result;
2060    /// async fn sample(
2061    ///    client: &KeyManagementService, project_id: &str, location_id: &str, key_ring_id: &str, crypto_key_id: &str
2062    /// ) -> Result<()> {
2063    ///     let response = client.get_crypto_key()
2064    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}/cryptoKeys/{crypto_key_id}"))
2065    ///         .send().await?;
2066    ///     println!("response {:?}", response);
2067    ///     Ok(())
2068    /// }
2069    /// ```
2070    pub fn get_crypto_key(&self) -> super::builder::key_management_service::GetCryptoKey {
2071        super::builder::key_management_service::GetCryptoKey::new(self.inner.clone())
2072    }
2073
2074    /// Returns metadata for a given
2075    /// [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion].
2076    ///
2077    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2078    ///
2079    /// # Example
2080    /// ```
2081    /// # use google_cloud_kms_v1::client::KeyManagementService;
2082    /// use google_cloud_kms_v1::Result;
2083    /// async fn sample(
2084    ///    client: &KeyManagementService, project_id: &str, location_id: &str, key_ring_id: &str, crypto_key_id: &str, crypto_key_version_id: &str
2085    /// ) -> Result<()> {
2086    ///     let response = client.get_crypto_key_version()
2087    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}/cryptoKeys/{crypto_key_id}/cryptoKeyVersions/{crypto_key_version_id}"))
2088    ///         .send().await?;
2089    ///     println!("response {:?}", response);
2090    ///     Ok(())
2091    /// }
2092    /// ```
2093    pub fn get_crypto_key_version(
2094        &self,
2095    ) -> super::builder::key_management_service::GetCryptoKeyVersion {
2096        super::builder::key_management_service::GetCryptoKeyVersion::new(self.inner.clone())
2097    }
2098
2099    /// Returns the public key for the given
2100    /// [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion]. The
2101    /// [CryptoKey.purpose][google.cloud.kms.v1.CryptoKey.purpose] must be
2102    /// [ASYMMETRIC_SIGN][google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.ASYMMETRIC_SIGN]
2103    /// or
2104    /// [ASYMMETRIC_DECRYPT][google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.ASYMMETRIC_DECRYPT].
2105    ///
2106    /// [google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.ASYMMETRIC_DECRYPT]: crate::model::crypto_key::CryptoKeyPurpose::AsymmetricDecrypt
2107    /// [google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.ASYMMETRIC_SIGN]: crate::model::crypto_key::CryptoKeyPurpose::AsymmetricSign
2108    /// [google.cloud.kms.v1.CryptoKey.purpose]: crate::model::CryptoKey::purpose
2109    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2110    ///
2111    /// # Example
2112    /// ```
2113    /// # use google_cloud_kms_v1::client::KeyManagementService;
2114    /// use google_cloud_kms_v1::Result;
2115    /// async fn sample(
2116    ///    client: &KeyManagementService
2117    /// ) -> Result<()> {
2118    ///     let response = client.get_public_key()
2119    ///         /* set fields */
2120    ///         .send().await?;
2121    ///     println!("response {:?}", response);
2122    ///     Ok(())
2123    /// }
2124    /// ```
2125    pub fn get_public_key(&self) -> super::builder::key_management_service::GetPublicKey {
2126        super::builder::key_management_service::GetPublicKey::new(self.inner.clone())
2127    }
2128
2129    /// Returns metadata for a given [ImportJob][google.cloud.kms.v1.ImportJob].
2130    ///
2131    /// [google.cloud.kms.v1.ImportJob]: crate::model::ImportJob
2132    ///
2133    /// # Example
2134    /// ```
2135    /// # use google_cloud_kms_v1::client::KeyManagementService;
2136    /// use google_cloud_kms_v1::Result;
2137    /// async fn sample(
2138    ///    client: &KeyManagementService, project_id: &str, location_id: &str, key_ring_id: &str, import_job_id: &str
2139    /// ) -> Result<()> {
2140    ///     let response = client.get_import_job()
2141    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}/importJobs/{import_job_id}"))
2142    ///         .send().await?;
2143    ///     println!("response {:?}", response);
2144    ///     Ok(())
2145    /// }
2146    /// ```
2147    pub fn get_import_job(&self) -> super::builder::key_management_service::GetImportJob {
2148        super::builder::key_management_service::GetImportJob::new(self.inner.clone())
2149    }
2150
2151    /// Retrieves a specific [RetiredResource][google.cloud.kms.v1.RetiredResource]
2152    /// resource, which represents the record of a deleted
2153    /// [CryptoKey][google.cloud.kms.v1.CryptoKey].
2154    ///
2155    /// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
2156    /// [google.cloud.kms.v1.RetiredResource]: crate::model::RetiredResource
2157    ///
2158    /// # Example
2159    /// ```
2160    /// # use google_cloud_kms_v1::client::KeyManagementService;
2161    /// use google_cloud_kms_v1::Result;
2162    /// async fn sample(
2163    ///    client: &KeyManagementService, project_id: &str, location_id: &str, retired_resource_id: &str
2164    /// ) -> Result<()> {
2165    ///     let response = client.get_retired_resource()
2166    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/retiredResources/{retired_resource_id}"))
2167    ///         .send().await?;
2168    ///     println!("response {:?}", response);
2169    ///     Ok(())
2170    /// }
2171    /// ```
2172    pub fn get_retired_resource(
2173        &self,
2174    ) -> super::builder::key_management_service::GetRetiredResource {
2175        super::builder::key_management_service::GetRetiredResource::new(self.inner.clone())
2176    }
2177
2178    /// Create a new [KeyRing][google.cloud.kms.v1.KeyRing] in a given Project and
2179    /// Location.
2180    ///
2181    /// [google.cloud.kms.v1.KeyRing]: crate::model::KeyRing
2182    ///
2183    /// # Example
2184    /// ```
2185    /// # use google_cloud_kms_v1::client::KeyManagementService;
2186    /// use google_cloud_kms_v1::model::KeyRing;
2187    /// use google_cloud_kms_v1::Result;
2188    /// async fn sample(
2189    ///    client: &KeyManagementService, parent: &str
2190    /// ) -> Result<()> {
2191    ///     let response = client.create_key_ring()
2192    ///         .set_parent(parent)
2193    ///         .set_key_ring(
2194    ///             KeyRing::new()/* set fields */
2195    ///         )
2196    ///         .send().await?;
2197    ///     println!("response {:?}", response);
2198    ///     Ok(())
2199    /// }
2200    /// ```
2201    pub fn create_key_ring(&self) -> super::builder::key_management_service::CreateKeyRing {
2202        super::builder::key_management_service::CreateKeyRing::new(self.inner.clone())
2203    }
2204
2205    /// Create a new [CryptoKey][google.cloud.kms.v1.CryptoKey] within a
2206    /// [KeyRing][google.cloud.kms.v1.KeyRing].
2207    ///
2208    /// [CryptoKey.purpose][google.cloud.kms.v1.CryptoKey.purpose] and
2209    /// [CryptoKey.version_template.algorithm][google.cloud.kms.v1.CryptoKeyVersionTemplate.algorithm]
2210    /// are required.
2211    ///
2212    /// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
2213    /// [google.cloud.kms.v1.CryptoKey.purpose]: crate::model::CryptoKey::purpose
2214    /// [google.cloud.kms.v1.CryptoKeyVersionTemplate.algorithm]: crate::model::CryptoKeyVersionTemplate::algorithm
2215    /// [google.cloud.kms.v1.KeyRing]: crate::model::KeyRing
2216    ///
2217    /// # Example
2218    /// ```
2219    /// # use google_cloud_kms_v1::client::KeyManagementService;
2220    /// use google_cloud_kms_v1::model::CryptoKey;
2221    /// use google_cloud_kms_v1::Result;
2222    /// async fn sample(
2223    ///    client: &KeyManagementService, project_id: &str, location_id: &str, key_ring_id: &str
2224    /// ) -> Result<()> {
2225    ///     let response = client.create_crypto_key()
2226    ///         .set_parent(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}"))
2227    ///         .set_crypto_key(
2228    ///             CryptoKey::new()/* set fields */
2229    ///         )
2230    ///         .send().await?;
2231    ///     println!("response {:?}", response);
2232    ///     Ok(())
2233    /// }
2234    /// ```
2235    pub fn create_crypto_key(&self) -> super::builder::key_management_service::CreateCryptoKey {
2236        super::builder::key_management_service::CreateCryptoKey::new(self.inner.clone())
2237    }
2238
2239    /// Create a new [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] in a
2240    /// [CryptoKey][google.cloud.kms.v1.CryptoKey].
2241    ///
2242    /// The server will assign the next sequential id. If unset,
2243    /// [state][google.cloud.kms.v1.CryptoKeyVersion.state] will be set to
2244    /// [ENABLED][google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.ENABLED].
2245    ///
2246    /// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
2247    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2248    /// [google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.ENABLED]: crate::model::crypto_key_version::CryptoKeyVersionState::Enabled
2249    /// [google.cloud.kms.v1.CryptoKeyVersion.state]: crate::model::CryptoKeyVersion::state
2250    ///
2251    /// # Example
2252    /// ```
2253    /// # use google_cloud_kms_v1::client::KeyManagementService;
2254    /// use google_cloud_kms_v1::model::CryptoKeyVersion;
2255    /// use google_cloud_kms_v1::Result;
2256    /// async fn sample(
2257    ///    client: &KeyManagementService, project_id: &str, location_id: &str, key_ring_id: &str, crypto_key_id: &str
2258    /// ) -> Result<()> {
2259    ///     let response = client.create_crypto_key_version()
2260    ///         .set_parent(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}/cryptoKeys/{crypto_key_id}"))
2261    ///         .set_crypto_key_version(
2262    ///             CryptoKeyVersion::new()/* set fields */
2263    ///         )
2264    ///         .send().await?;
2265    ///     println!("response {:?}", response);
2266    ///     Ok(())
2267    /// }
2268    /// ```
2269    pub fn create_crypto_key_version(
2270        &self,
2271    ) -> super::builder::key_management_service::CreateCryptoKeyVersion {
2272        super::builder::key_management_service::CreateCryptoKeyVersion::new(self.inner.clone())
2273    }
2274
2275    /// Permanently deletes the given [CryptoKey][google.cloud.kms.v1.CryptoKey].
2276    /// All child [CryptoKeyVersions][google.cloud.kms.v1.CryptoKeyVersion] must
2277    /// have been previously deleted using
2278    /// [KeyManagementService.DeleteCryptoKeyVersion][google.cloud.kms.v1.KeyManagementService.DeleteCryptoKeyVersion].
2279    /// The specified crypto key will be immediately and permanently deleted upon
2280    /// calling this method. This action cannot be undone.
2281    ///
2282    /// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
2283    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2284    /// [google.cloud.kms.v1.KeyManagementService.DeleteCryptoKeyVersion]: crate::client::KeyManagementService::delete_crypto_key_version
2285    ///
2286    /// # Long running operations
2287    ///
2288    /// This method is used to start, and/or poll a [long-running Operation].
2289    /// The [Working with long-running operations] chapter in the [user guide]
2290    /// covers these operations in detail.
2291    ///
2292    /// [long-running operation]: https://google.aip.dev/151
2293    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
2294    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
2295    ///
2296    /// # Example
2297    /// ```
2298    /// # use google_cloud_kms_v1::client::KeyManagementService;
2299    /// use google_cloud_lro::Poller;
2300    /// use google_cloud_kms_v1::Result;
2301    /// async fn sample(
2302    ///    client: &KeyManagementService, project_id: &str, location_id: &str, key_ring_id: &str, crypto_key_id: &str
2303    /// ) -> Result<()> {
2304    ///     client.delete_crypto_key()
2305    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}/cryptoKeys/{crypto_key_id}"))
2306    ///         .poller().until_done().await?;
2307    ///     Ok(())
2308    /// }
2309    /// ```
2310    pub fn delete_crypto_key(&self) -> super::builder::key_management_service::DeleteCryptoKey {
2311        super::builder::key_management_service::DeleteCryptoKey::new(self.inner.clone())
2312    }
2313
2314    /// Permanently deletes the given
2315    /// [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion]. Only possible if
2316    /// the version has not been previously imported and if its
2317    /// [state][google.cloud.kms.v1.CryptoKeyVersion.state] is one of
2318    /// [DESTROYED][CryptoKeyVersionState.DESTROYED],
2319    /// [IMPORT_FAILED][CryptoKeyVersionState.IMPORT_FAILED], or
2320    /// [GENERATION_FAILED][CryptoKeyVersionState.GENERATION_FAILED].
2321    /// Successfully imported
2322    /// [CryptoKeyVersions][google.cloud.kms.v1.CryptoKeyVersion] cannot be deleted
2323    /// at this time. The specified version will be immediately and permanently
2324    /// deleted upon calling this method. This action cannot be undone.
2325    ///
2326    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2327    /// [google.cloud.kms.v1.CryptoKeyVersion.state]: crate::model::CryptoKeyVersion::state
2328    ///
2329    /// # Long running operations
2330    ///
2331    /// This method is used to start, and/or poll a [long-running Operation].
2332    /// The [Working with long-running operations] chapter in the [user guide]
2333    /// covers these operations in detail.
2334    ///
2335    /// [long-running operation]: https://google.aip.dev/151
2336    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
2337    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
2338    ///
2339    /// # Example
2340    /// ```
2341    /// # use google_cloud_kms_v1::client::KeyManagementService;
2342    /// use google_cloud_lro::Poller;
2343    /// use google_cloud_kms_v1::Result;
2344    /// async fn sample(
2345    ///    client: &KeyManagementService, project_id: &str, location_id: &str, key_ring_id: &str, crypto_key_id: &str, crypto_key_version_id: &str
2346    /// ) -> Result<()> {
2347    ///     client.delete_crypto_key_version()
2348    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}/cryptoKeys/{crypto_key_id}/cryptoKeyVersions/{crypto_key_version_id}"))
2349    ///         .poller().until_done().await?;
2350    ///     Ok(())
2351    /// }
2352    /// ```
2353    pub fn delete_crypto_key_version(
2354        &self,
2355    ) -> super::builder::key_management_service::DeleteCryptoKeyVersion {
2356        super::builder::key_management_service::DeleteCryptoKeyVersion::new(self.inner.clone())
2357    }
2358
2359    /// Import wrapped key material into a
2360    /// [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion].
2361    ///
2362    /// All requests must specify a [CryptoKey][google.cloud.kms.v1.CryptoKey]. If
2363    /// a [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] is additionally
2364    /// specified in the request, key material will be reimported into that
2365    /// version. Otherwise, a new version will be created, and will be assigned the
2366    /// next sequential id within the [CryptoKey][google.cloud.kms.v1.CryptoKey].
2367    ///
2368    /// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
2369    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2370    ///
2371    /// # Example
2372    /// ```
2373    /// # use google_cloud_kms_v1::client::KeyManagementService;
2374    /// use google_cloud_kms_v1::Result;
2375    /// async fn sample(
2376    ///    client: &KeyManagementService
2377    /// ) -> Result<()> {
2378    ///     let response = client.import_crypto_key_version()
2379    ///         /* set fields */
2380    ///         .send().await?;
2381    ///     println!("response {:?}", response);
2382    ///     Ok(())
2383    /// }
2384    /// ```
2385    pub fn import_crypto_key_version(
2386        &self,
2387    ) -> super::builder::key_management_service::ImportCryptoKeyVersion {
2388        super::builder::key_management_service::ImportCryptoKeyVersion::new(self.inner.clone())
2389    }
2390
2391    /// Create a new [ImportJob][google.cloud.kms.v1.ImportJob] within a
2392    /// [KeyRing][google.cloud.kms.v1.KeyRing].
2393    ///
2394    /// [ImportJob.import_method][google.cloud.kms.v1.ImportJob.import_method] is
2395    /// required.
2396    ///
2397    /// [google.cloud.kms.v1.ImportJob]: crate::model::ImportJob
2398    /// [google.cloud.kms.v1.ImportJob.import_method]: crate::model::ImportJob::import_method
2399    /// [google.cloud.kms.v1.KeyRing]: crate::model::KeyRing
2400    ///
2401    /// # Example
2402    /// ```
2403    /// # use google_cloud_kms_v1::client::KeyManagementService;
2404    /// use google_cloud_kms_v1::model::ImportJob;
2405    /// use google_cloud_kms_v1::Result;
2406    /// async fn sample(
2407    ///    client: &KeyManagementService, project_id: &str, location_id: &str, key_ring_id: &str
2408    /// ) -> Result<()> {
2409    ///     let response = client.create_import_job()
2410    ///         .set_parent(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}"))
2411    ///         .set_import_job(
2412    ///             ImportJob::new()/* set fields */
2413    ///         )
2414    ///         .send().await?;
2415    ///     println!("response {:?}", response);
2416    ///     Ok(())
2417    /// }
2418    /// ```
2419    pub fn create_import_job(&self) -> super::builder::key_management_service::CreateImportJob {
2420        super::builder::key_management_service::CreateImportJob::new(self.inner.clone())
2421    }
2422
2423    /// Update a [CryptoKey][google.cloud.kms.v1.CryptoKey].
2424    ///
2425    /// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
2426    ///
2427    /// # Example
2428    /// ```
2429    /// # use google_cloud_kms_v1::client::KeyManagementService;
2430    /// # extern crate wkt as google_cloud_wkt;
2431    /// use google_cloud_wkt::FieldMask;
2432    /// use google_cloud_kms_v1::model::CryptoKey;
2433    /// use google_cloud_kms_v1::Result;
2434    /// async fn sample(
2435    ///    client: &KeyManagementService, project_id: &str, location_id: &str, key_ring_id: &str, crypto_key_id: &str
2436    /// ) -> Result<()> {
2437    ///     let response = client.update_crypto_key()
2438    ///         .set_crypto_key(
2439    ///             CryptoKey::new().set_name(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}/cryptoKeys/{crypto_key_id}"))/* set fields */
2440    ///         )
2441    ///         .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
2442    ///         .send().await?;
2443    ///     println!("response {:?}", response);
2444    ///     Ok(())
2445    /// }
2446    /// ```
2447    pub fn update_crypto_key(&self) -> super::builder::key_management_service::UpdateCryptoKey {
2448        super::builder::key_management_service::UpdateCryptoKey::new(self.inner.clone())
2449    }
2450
2451    /// Update a [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion]'s
2452    /// metadata.
2453    ///
2454    /// [state][google.cloud.kms.v1.CryptoKeyVersion.state] may be changed between
2455    /// [ENABLED][google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.ENABLED]
2456    /// and
2457    /// [DISABLED][google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.DISABLED]
2458    /// using this method. See
2459    /// [DestroyCryptoKeyVersion][google.cloud.kms.v1.KeyManagementService.DestroyCryptoKeyVersion]
2460    /// and
2461    /// [RestoreCryptoKeyVersion][google.cloud.kms.v1.KeyManagementService.RestoreCryptoKeyVersion]
2462    /// to move between other states.
2463    ///
2464    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2465    /// [google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.DISABLED]: crate::model::crypto_key_version::CryptoKeyVersionState::Disabled
2466    /// [google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.ENABLED]: crate::model::crypto_key_version::CryptoKeyVersionState::Enabled
2467    /// [google.cloud.kms.v1.CryptoKeyVersion.state]: crate::model::CryptoKeyVersion::state
2468    /// [google.cloud.kms.v1.KeyManagementService.DestroyCryptoKeyVersion]: crate::client::KeyManagementService::destroy_crypto_key_version
2469    /// [google.cloud.kms.v1.KeyManagementService.RestoreCryptoKeyVersion]: crate::client::KeyManagementService::restore_crypto_key_version
2470    ///
2471    /// # Example
2472    /// ```
2473    /// # use google_cloud_kms_v1::client::KeyManagementService;
2474    /// # extern crate wkt as google_cloud_wkt;
2475    /// use google_cloud_wkt::FieldMask;
2476    /// use google_cloud_kms_v1::model::CryptoKeyVersion;
2477    /// use google_cloud_kms_v1::Result;
2478    /// async fn sample(
2479    ///    client: &KeyManagementService, project_id: &str, location_id: &str, key_ring_id: &str, crypto_key_id: &str, crypto_key_version_id: &str
2480    /// ) -> Result<()> {
2481    ///     let response = client.update_crypto_key_version()
2482    ///         .set_crypto_key_version(
2483    ///             CryptoKeyVersion::new().set_name(format!("projects/{project_id}/locations/{location_id}/keyRings/{key_ring_id}/cryptoKeys/{crypto_key_id}/cryptoKeyVersions/{crypto_key_version_id}"))/* set fields */
2484    ///         )
2485    ///         .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
2486    ///         .send().await?;
2487    ///     println!("response {:?}", response);
2488    ///     Ok(())
2489    /// }
2490    /// ```
2491    pub fn update_crypto_key_version(
2492        &self,
2493    ) -> super::builder::key_management_service::UpdateCryptoKeyVersion {
2494        super::builder::key_management_service::UpdateCryptoKeyVersion::new(self.inner.clone())
2495    }
2496
2497    /// Update the version of a [CryptoKey][google.cloud.kms.v1.CryptoKey] that
2498    /// will be used in
2499    /// [Encrypt][google.cloud.kms.v1.KeyManagementService.Encrypt].
2500    ///
2501    /// Returns an error if called on a key whose purpose is not
2502    /// [ENCRYPT_DECRYPT][google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT].
2503    ///
2504    /// [google.cloud.kms.v1.CryptoKey]: crate::model::CryptoKey
2505    /// [google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT]: crate::model::crypto_key::CryptoKeyPurpose::EncryptDecrypt
2506    /// [google.cloud.kms.v1.KeyManagementService.Encrypt]: crate::client::KeyManagementService::encrypt
2507    ///
2508    /// # Example
2509    /// ```
2510    /// # use google_cloud_kms_v1::client::KeyManagementService;
2511    /// use google_cloud_kms_v1::Result;
2512    /// async fn sample(
2513    ///    client: &KeyManagementService
2514    /// ) -> Result<()> {
2515    ///     let response = client.update_crypto_key_primary_version()
2516    ///         /* set fields */
2517    ///         .send().await?;
2518    ///     println!("response {:?}", response);
2519    ///     Ok(())
2520    /// }
2521    /// ```
2522    pub fn update_crypto_key_primary_version(
2523        &self,
2524    ) -> super::builder::key_management_service::UpdateCryptoKeyPrimaryVersion {
2525        super::builder::key_management_service::UpdateCryptoKeyPrimaryVersion::new(
2526            self.inner.clone(),
2527        )
2528    }
2529
2530    /// Schedule a [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] for
2531    /// destruction.
2532    ///
2533    /// Upon calling this method,
2534    /// [CryptoKeyVersion.state][google.cloud.kms.v1.CryptoKeyVersion.state] will
2535    /// be set to
2536    /// [DESTROY_SCHEDULED][google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.DESTROY_SCHEDULED],
2537    /// and [destroy_time][google.cloud.kms.v1.CryptoKeyVersion.destroy_time] will
2538    /// be set to the time
2539    /// [destroy_scheduled_duration][google.cloud.kms.v1.CryptoKey.destroy_scheduled_duration]
2540    /// in the future. At that time, the
2541    /// [state][google.cloud.kms.v1.CryptoKeyVersion.state] will automatically
2542    /// change to
2543    /// [DESTROYED][google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.DESTROYED],
2544    /// and the key material will be irrevocably destroyed.
2545    ///
2546    /// Before the
2547    /// [destroy_time][google.cloud.kms.v1.CryptoKeyVersion.destroy_time] is
2548    /// reached,
2549    /// [RestoreCryptoKeyVersion][google.cloud.kms.v1.KeyManagementService.RestoreCryptoKeyVersion]
2550    /// may be called to reverse the process.
2551    ///
2552    /// [google.cloud.kms.v1.CryptoKey.destroy_scheduled_duration]: crate::model::CryptoKey::destroy_scheduled_duration
2553    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2554    /// [google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.DESTROYED]: crate::model::crypto_key_version::CryptoKeyVersionState::Destroyed
2555    /// [google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.DESTROY_SCHEDULED]: crate::model::crypto_key_version::CryptoKeyVersionState::DestroyScheduled
2556    /// [google.cloud.kms.v1.CryptoKeyVersion.destroy_time]: crate::model::CryptoKeyVersion::destroy_time
2557    /// [google.cloud.kms.v1.CryptoKeyVersion.state]: crate::model::CryptoKeyVersion::state
2558    /// [google.cloud.kms.v1.KeyManagementService.RestoreCryptoKeyVersion]: crate::client::KeyManagementService::restore_crypto_key_version
2559    ///
2560    /// # Example
2561    /// ```
2562    /// # use google_cloud_kms_v1::client::KeyManagementService;
2563    /// use google_cloud_kms_v1::Result;
2564    /// async fn sample(
2565    ///    client: &KeyManagementService
2566    /// ) -> Result<()> {
2567    ///     let response = client.destroy_crypto_key_version()
2568    ///         /* set fields */
2569    ///         .send().await?;
2570    ///     println!("response {:?}", response);
2571    ///     Ok(())
2572    /// }
2573    /// ```
2574    pub fn destroy_crypto_key_version(
2575        &self,
2576    ) -> super::builder::key_management_service::DestroyCryptoKeyVersion {
2577        super::builder::key_management_service::DestroyCryptoKeyVersion::new(self.inner.clone())
2578    }
2579
2580    /// Restore a [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] in the
2581    /// [DESTROY_SCHEDULED][google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.DESTROY_SCHEDULED]
2582    /// state.
2583    ///
2584    /// Upon restoration of the CryptoKeyVersion,
2585    /// [state][google.cloud.kms.v1.CryptoKeyVersion.state] will be set to
2586    /// [DISABLED][google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.DISABLED],
2587    /// and [destroy_time][google.cloud.kms.v1.CryptoKeyVersion.destroy_time] will
2588    /// be cleared.
2589    ///
2590    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2591    /// [google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.DESTROY_SCHEDULED]: crate::model::crypto_key_version::CryptoKeyVersionState::DestroyScheduled
2592    /// [google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.DISABLED]: crate::model::crypto_key_version::CryptoKeyVersionState::Disabled
2593    /// [google.cloud.kms.v1.CryptoKeyVersion.destroy_time]: crate::model::CryptoKeyVersion::destroy_time
2594    /// [google.cloud.kms.v1.CryptoKeyVersion.state]: crate::model::CryptoKeyVersion::state
2595    ///
2596    /// # Example
2597    /// ```
2598    /// # use google_cloud_kms_v1::client::KeyManagementService;
2599    /// use google_cloud_kms_v1::Result;
2600    /// async fn sample(
2601    ///    client: &KeyManagementService
2602    /// ) -> Result<()> {
2603    ///     let response = client.restore_crypto_key_version()
2604    ///         /* set fields */
2605    ///         .send().await?;
2606    ///     println!("response {:?}", response);
2607    ///     Ok(())
2608    /// }
2609    /// ```
2610    pub fn restore_crypto_key_version(
2611        &self,
2612    ) -> super::builder::key_management_service::RestoreCryptoKeyVersion {
2613        super::builder::key_management_service::RestoreCryptoKeyVersion::new(self.inner.clone())
2614    }
2615
2616    /// Encrypts data, so that it can only be recovered by a call to
2617    /// [Decrypt][google.cloud.kms.v1.KeyManagementService.Decrypt]. The
2618    /// [CryptoKey.purpose][google.cloud.kms.v1.CryptoKey.purpose] must be
2619    /// [ENCRYPT_DECRYPT][google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT].
2620    ///
2621    /// [google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT]: crate::model::crypto_key::CryptoKeyPurpose::EncryptDecrypt
2622    /// [google.cloud.kms.v1.CryptoKey.purpose]: crate::model::CryptoKey::purpose
2623    /// [google.cloud.kms.v1.KeyManagementService.Decrypt]: crate::client::KeyManagementService::decrypt
2624    ///
2625    /// # Example
2626    /// ```
2627    /// # use google_cloud_kms_v1::client::KeyManagementService;
2628    /// use google_cloud_kms_v1::Result;
2629    /// async fn sample(
2630    ///    client: &KeyManagementService
2631    /// ) -> Result<()> {
2632    ///     let response = client.encrypt()
2633    ///         /* set fields */
2634    ///         .send().await?;
2635    ///     println!("response {:?}", response);
2636    ///     Ok(())
2637    /// }
2638    /// ```
2639    pub fn encrypt(&self) -> super::builder::key_management_service::Encrypt {
2640        super::builder::key_management_service::Encrypt::new(self.inner.clone())
2641    }
2642
2643    /// Decrypts data that was protected by
2644    /// [Encrypt][google.cloud.kms.v1.KeyManagementService.Encrypt]. The
2645    /// [CryptoKey.purpose][google.cloud.kms.v1.CryptoKey.purpose] must be
2646    /// [ENCRYPT_DECRYPT][google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT].
2647    ///
2648    /// [google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT]: crate::model::crypto_key::CryptoKeyPurpose::EncryptDecrypt
2649    /// [google.cloud.kms.v1.CryptoKey.purpose]: crate::model::CryptoKey::purpose
2650    /// [google.cloud.kms.v1.KeyManagementService.Encrypt]: crate::client::KeyManagementService::encrypt
2651    ///
2652    /// # Example
2653    /// ```
2654    /// # use google_cloud_kms_v1::client::KeyManagementService;
2655    /// use google_cloud_kms_v1::Result;
2656    /// async fn sample(
2657    ///    client: &KeyManagementService
2658    /// ) -> Result<()> {
2659    ///     let response = client.decrypt()
2660    ///         /* set fields */
2661    ///         .send().await?;
2662    ///     println!("response {:?}", response);
2663    ///     Ok(())
2664    /// }
2665    /// ```
2666    pub fn decrypt(&self) -> super::builder::key_management_service::Decrypt {
2667        super::builder::key_management_service::Decrypt::new(self.inner.clone())
2668    }
2669
2670    /// Encrypts data using portable cryptographic primitives. Most users should
2671    /// choose [Encrypt][google.cloud.kms.v1.KeyManagementService.Encrypt] and
2672    /// [Decrypt][google.cloud.kms.v1.KeyManagementService.Decrypt] rather than
2673    /// their raw counterparts. The
2674    /// [CryptoKey.purpose][google.cloud.kms.v1.CryptoKey.purpose] must be
2675    /// [RAW_ENCRYPT_DECRYPT][google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.RAW_ENCRYPT_DECRYPT].
2676    ///
2677    /// [google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.RAW_ENCRYPT_DECRYPT]: crate::model::crypto_key::CryptoKeyPurpose::RawEncryptDecrypt
2678    /// [google.cloud.kms.v1.CryptoKey.purpose]: crate::model::CryptoKey::purpose
2679    /// [google.cloud.kms.v1.KeyManagementService.Decrypt]: crate::client::KeyManagementService::decrypt
2680    /// [google.cloud.kms.v1.KeyManagementService.Encrypt]: crate::client::KeyManagementService::encrypt
2681    ///
2682    /// # Example
2683    /// ```
2684    /// # use google_cloud_kms_v1::client::KeyManagementService;
2685    /// use google_cloud_kms_v1::Result;
2686    /// async fn sample(
2687    ///    client: &KeyManagementService
2688    /// ) -> Result<()> {
2689    ///     let response = client.raw_encrypt()
2690    ///         /* set fields */
2691    ///         .send().await?;
2692    ///     println!("response {:?}", response);
2693    ///     Ok(())
2694    /// }
2695    /// ```
2696    pub fn raw_encrypt(&self) -> super::builder::key_management_service::RawEncrypt {
2697        super::builder::key_management_service::RawEncrypt::new(self.inner.clone())
2698    }
2699
2700    /// Decrypts data that was originally encrypted using a raw cryptographic
2701    /// mechanism. The [CryptoKey.purpose][google.cloud.kms.v1.CryptoKey.purpose]
2702    /// must be
2703    /// [RAW_ENCRYPT_DECRYPT][google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.RAW_ENCRYPT_DECRYPT].
2704    ///
2705    /// [google.cloud.kms.v1.CryptoKey.CryptoKeyPurpose.RAW_ENCRYPT_DECRYPT]: crate::model::crypto_key::CryptoKeyPurpose::RawEncryptDecrypt
2706    /// [google.cloud.kms.v1.CryptoKey.purpose]: crate::model::CryptoKey::purpose
2707    ///
2708    /// # Example
2709    /// ```
2710    /// # use google_cloud_kms_v1::client::KeyManagementService;
2711    /// use google_cloud_kms_v1::Result;
2712    /// async fn sample(
2713    ///    client: &KeyManagementService
2714    /// ) -> Result<()> {
2715    ///     let response = client.raw_decrypt()
2716    ///         /* set fields */
2717    ///         .send().await?;
2718    ///     println!("response {:?}", response);
2719    ///     Ok(())
2720    /// }
2721    /// ```
2722    pub fn raw_decrypt(&self) -> super::builder::key_management_service::RawDecrypt {
2723        super::builder::key_management_service::RawDecrypt::new(self.inner.clone())
2724    }
2725
2726    /// Signs data using a [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion]
2727    /// with [CryptoKey.purpose][google.cloud.kms.v1.CryptoKey.purpose]
2728    /// ASYMMETRIC_SIGN, producing a signature that can be verified with the public
2729    /// key retrieved from
2730    /// [GetPublicKey][google.cloud.kms.v1.KeyManagementService.GetPublicKey].
2731    ///
2732    /// [google.cloud.kms.v1.CryptoKey.purpose]: crate::model::CryptoKey::purpose
2733    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2734    /// [google.cloud.kms.v1.KeyManagementService.GetPublicKey]: crate::client::KeyManagementService::get_public_key
2735    ///
2736    /// # Example
2737    /// ```
2738    /// # use google_cloud_kms_v1::client::KeyManagementService;
2739    /// use google_cloud_kms_v1::Result;
2740    /// async fn sample(
2741    ///    client: &KeyManagementService
2742    /// ) -> Result<()> {
2743    ///     let response = client.asymmetric_sign()
2744    ///         /* set fields */
2745    ///         .send().await?;
2746    ///     println!("response {:?}", response);
2747    ///     Ok(())
2748    /// }
2749    /// ```
2750    pub fn asymmetric_sign(&self) -> super::builder::key_management_service::AsymmetricSign {
2751        super::builder::key_management_service::AsymmetricSign::new(self.inner.clone())
2752    }
2753
2754    /// Decrypts data that was encrypted with a public key retrieved from
2755    /// [GetPublicKey][google.cloud.kms.v1.KeyManagementService.GetPublicKey]
2756    /// corresponding to a [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion]
2757    /// with [CryptoKey.purpose][google.cloud.kms.v1.CryptoKey.purpose]
2758    /// ASYMMETRIC_DECRYPT.
2759    ///
2760    /// [google.cloud.kms.v1.CryptoKey.purpose]: crate::model::CryptoKey::purpose
2761    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2762    /// [google.cloud.kms.v1.KeyManagementService.GetPublicKey]: crate::client::KeyManagementService::get_public_key
2763    ///
2764    /// # Example
2765    /// ```
2766    /// # use google_cloud_kms_v1::client::KeyManagementService;
2767    /// use google_cloud_kms_v1::Result;
2768    /// async fn sample(
2769    ///    client: &KeyManagementService
2770    /// ) -> Result<()> {
2771    ///     let response = client.asymmetric_decrypt()
2772    ///         /* set fields */
2773    ///         .send().await?;
2774    ///     println!("response {:?}", response);
2775    ///     Ok(())
2776    /// }
2777    /// ```
2778    pub fn asymmetric_decrypt(&self) -> super::builder::key_management_service::AsymmetricDecrypt {
2779        super::builder::key_management_service::AsymmetricDecrypt::new(self.inner.clone())
2780    }
2781
2782    /// Signs data using a [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion]
2783    /// with [CryptoKey.purpose][google.cloud.kms.v1.CryptoKey.purpose] MAC,
2784    /// producing a tag that can be verified by another source with the same key.
2785    ///
2786    /// [google.cloud.kms.v1.CryptoKey.purpose]: crate::model::CryptoKey::purpose
2787    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2788    ///
2789    /// # Example
2790    /// ```
2791    /// # use google_cloud_kms_v1::client::KeyManagementService;
2792    /// use google_cloud_kms_v1::Result;
2793    /// async fn sample(
2794    ///    client: &KeyManagementService
2795    /// ) -> Result<()> {
2796    ///     let response = client.mac_sign()
2797    ///         /* set fields */
2798    ///         .send().await?;
2799    ///     println!("response {:?}", response);
2800    ///     Ok(())
2801    /// }
2802    /// ```
2803    pub fn mac_sign(&self) -> super::builder::key_management_service::MacSign {
2804        super::builder::key_management_service::MacSign::new(self.inner.clone())
2805    }
2806
2807    /// Verifies MAC tag using a
2808    /// [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] with
2809    /// [CryptoKey.purpose][google.cloud.kms.v1.CryptoKey.purpose] MAC, and returns
2810    /// a response that indicates whether or not the verification was successful.
2811    ///
2812    /// [google.cloud.kms.v1.CryptoKey.purpose]: crate::model::CryptoKey::purpose
2813    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2814    ///
2815    /// # Example
2816    /// ```
2817    /// # use google_cloud_kms_v1::client::KeyManagementService;
2818    /// use google_cloud_kms_v1::Result;
2819    /// async fn sample(
2820    ///    client: &KeyManagementService
2821    /// ) -> Result<()> {
2822    ///     let response = client.mac_verify()
2823    ///         /* set fields */
2824    ///         .send().await?;
2825    ///     println!("response {:?}", response);
2826    ///     Ok(())
2827    /// }
2828    /// ```
2829    pub fn mac_verify(&self) -> super::builder::key_management_service::MacVerify {
2830        super::builder::key_management_service::MacVerify::new(self.inner.clone())
2831    }
2832
2833    /// Decapsulates data that was encapsulated with a public key retrieved from
2834    /// [GetPublicKey][google.cloud.kms.v1.KeyManagementService.GetPublicKey]
2835    /// corresponding to a [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion]
2836    /// with [CryptoKey.purpose][google.cloud.kms.v1.CryptoKey.purpose]
2837    /// KEY_ENCAPSULATION.
2838    ///
2839    /// [google.cloud.kms.v1.CryptoKey.purpose]: crate::model::CryptoKey::purpose
2840    /// [google.cloud.kms.v1.CryptoKeyVersion]: crate::model::CryptoKeyVersion
2841    /// [google.cloud.kms.v1.KeyManagementService.GetPublicKey]: crate::client::KeyManagementService::get_public_key
2842    ///
2843    /// # Example
2844    /// ```
2845    /// # use google_cloud_kms_v1::client::KeyManagementService;
2846    /// use google_cloud_kms_v1::Result;
2847    /// async fn sample(
2848    ///    client: &KeyManagementService
2849    /// ) -> Result<()> {
2850    ///     let response = client.decapsulate()
2851    ///         /* set fields */
2852    ///         .send().await?;
2853    ///     println!("response {:?}", response);
2854    ///     Ok(())
2855    /// }
2856    /// ```
2857    pub fn decapsulate(&self) -> super::builder::key_management_service::Decapsulate {
2858        super::builder::key_management_service::Decapsulate::new(self.inner.clone())
2859    }
2860
2861    /// Generate random bytes using the Cloud KMS randomness source in the provided
2862    /// location.
2863    ///
2864    /// # Example
2865    /// ```
2866    /// # use google_cloud_kms_v1::client::KeyManagementService;
2867    /// use google_cloud_kms_v1::Result;
2868    /// async fn sample(
2869    ///    client: &KeyManagementService
2870    /// ) -> Result<()> {
2871    ///     let response = client.generate_random_bytes()
2872    ///         /* set fields */
2873    ///         .send().await?;
2874    ///     println!("response {:?}", response);
2875    ///     Ok(())
2876    /// }
2877    /// ```
2878    pub fn generate_random_bytes(
2879        &self,
2880    ) -> super::builder::key_management_service::GenerateRandomBytes {
2881        super::builder::key_management_service::GenerateRandomBytes::new(self.inner.clone())
2882    }
2883
2884    /// Lists information about the supported locations for this service.
2885    ///
2886    /// This method lists locations based on the resource scope provided in
2887    /// the [ListLocationsRequest.name] field:
2888    ///
2889    /// * **Global locations**: If `name` is empty, the method lists the
2890    ///   public locations available to all projects. * **Project-specific
2891    ///   locations**: If `name` follows the format
2892    ///   `projects/{project}`, the method lists locations visible to that
2893    ///   specific project. This includes public, private, or other
2894    ///   project-specific locations enabled for the project.
2895    ///
2896    /// For gRPC and client library implementations, the resource name is
2897    /// passed as the `name` field. For direct service calls, the resource
2898    /// name is
2899    /// incorporated into the request path based on the specific service
2900    /// implementation and version.
2901    ///
2902    /// # Example
2903    /// ```
2904    /// # use google_cloud_kms_v1::client::KeyManagementService;
2905    /// use google_cloud_gax::paginator::ItemPaginator as _;
2906    /// use google_cloud_kms_v1::Result;
2907    /// async fn sample(
2908    ///    client: &KeyManagementService
2909    /// ) -> Result<()> {
2910    ///     let mut list = client.list_locations()
2911    ///         /* set fields */
2912    ///         .by_item();
2913    ///     while let Some(item) = list.next().await.transpose()? {
2914    ///         println!("{:?}", item);
2915    ///     }
2916    ///     Ok(())
2917    /// }
2918    /// ```
2919    pub fn list_locations(&self) -> super::builder::key_management_service::ListLocations {
2920        super::builder::key_management_service::ListLocations::new(self.inner.clone())
2921    }
2922
2923    /// Gets information about a location.
2924    ///
2925    /// # Example
2926    /// ```
2927    /// # use google_cloud_kms_v1::client::KeyManagementService;
2928    /// use google_cloud_kms_v1::Result;
2929    /// async fn sample(
2930    ///    client: &KeyManagementService
2931    /// ) -> Result<()> {
2932    ///     let response = client.get_location()
2933    ///         /* set fields */
2934    ///         .send().await?;
2935    ///     println!("response {:?}", response);
2936    ///     Ok(())
2937    /// }
2938    /// ```
2939    pub fn get_location(&self) -> super::builder::key_management_service::GetLocation {
2940        super::builder::key_management_service::GetLocation::new(self.inner.clone())
2941    }
2942
2943    /// Sets the access control policy on the specified resource. Replaces
2944    /// any existing policy.
2945    ///
2946    /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
2947    /// errors.
2948    ///
2949    /// # Example
2950    /// ```
2951    /// # use google_cloud_kms_v1::client::KeyManagementService;
2952    /// use google_cloud_kms_v1::Result;
2953    /// async fn sample(
2954    ///    client: &KeyManagementService
2955    /// ) -> Result<()> {
2956    ///     let response = client.set_iam_policy()
2957    ///         /* set fields */
2958    ///         .send().await?;
2959    ///     println!("response {:?}", response);
2960    ///     Ok(())
2961    /// }
2962    /// ```
2963    pub fn set_iam_policy(&self) -> super::builder::key_management_service::SetIamPolicy {
2964        super::builder::key_management_service::SetIamPolicy::new(self.inner.clone())
2965    }
2966
2967    /// Gets the access control policy for a resource. Returns an empty policy
2968    /// if the resource exists and does not have a policy set.
2969    ///
2970    /// # Example
2971    /// ```
2972    /// # use google_cloud_kms_v1::client::KeyManagementService;
2973    /// use google_cloud_kms_v1::Result;
2974    /// async fn sample(
2975    ///    client: &KeyManagementService
2976    /// ) -> Result<()> {
2977    ///     let response = client.get_iam_policy()
2978    ///         /* set fields */
2979    ///         .send().await?;
2980    ///     println!("response {:?}", response);
2981    ///     Ok(())
2982    /// }
2983    /// ```
2984    pub fn get_iam_policy(&self) -> super::builder::key_management_service::GetIamPolicy {
2985        super::builder::key_management_service::GetIamPolicy::new(self.inner.clone())
2986    }
2987
2988    /// Returns permissions that a caller has on the specified resource. If the
2989    /// resource does not exist, this will return an empty set of
2990    /// permissions, not a `NOT_FOUND` error.
2991    ///
2992    /// Note: This operation is designed to be used for building
2993    /// permission-aware UIs and command-line tools, not for authorization
2994    /// checking. This operation may "fail open" without warning.
2995    ///
2996    /// # Example
2997    /// ```
2998    /// # use google_cloud_kms_v1::client::KeyManagementService;
2999    /// use google_cloud_kms_v1::Result;
3000    /// async fn sample(
3001    ///    client: &KeyManagementService
3002    /// ) -> Result<()> {
3003    ///     let response = client.test_iam_permissions()
3004    ///         /* set fields */
3005    ///         .send().await?;
3006    ///     println!("response {:?}", response);
3007    ///     Ok(())
3008    /// }
3009    /// ```
3010    pub fn test_iam_permissions(
3011        &self,
3012    ) -> super::builder::key_management_service::TestIamPermissions {
3013        super::builder::key_management_service::TestIamPermissions::new(self.inner.clone())
3014    }
3015
3016    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
3017    ///
3018    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
3019    ///
3020    /// # Example
3021    /// ```
3022    /// # use google_cloud_kms_v1::client::KeyManagementService;
3023    /// use google_cloud_kms_v1::Result;
3024    /// async fn sample(
3025    ///    client: &KeyManagementService
3026    /// ) -> Result<()> {
3027    ///     let response = client.get_operation()
3028    ///         /* set fields */
3029    ///         .send().await?;
3030    ///     println!("response {:?}", response);
3031    ///     Ok(())
3032    /// }
3033    /// ```
3034    pub fn get_operation(&self) -> super::builder::key_management_service::GetOperation {
3035        super::builder::key_management_service::GetOperation::new(self.inner.clone())
3036    }
3037}