Skip to main content

google_cloud_assuredworkloads_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::bare_urls)]
17#![allow(rustdoc::broken_intra_doc_links)]
18#![allow(rustdoc::invalid_html_tags)]
19#![allow(rustdoc::redundant_explicit_links)]
20
21/// Implements a client for the Assured Workloads API.
22///
23/// # Example
24/// ```
25/// # use google_cloud_assuredworkloads_v1::client::AssuredWorkloadsService;
26/// use google_cloud_gax::paginator::ItemPaginator as _;
27/// async fn sample(
28///    organization_id: &str,
29///    location_id: &str,
30/// ) -> anyhow::Result<()> {
31///     let client = AssuredWorkloadsService::builder().build().await?;
32///     let mut list = client.list_workloads()
33///         .set_parent(format!("organizations/{organization_id}/locations/{location_id}"))
34///         .by_item();
35///     while let Some(item) = list.next().await.transpose()? {
36///         println!("{:?}", item);
37///     }
38///     Ok(())
39/// }
40/// ```
41///
42/// # Service Description
43///
44/// Service to manage AssuredWorkloads.
45///
46/// # Configuration
47///
48/// To configure `AssuredWorkloadsService` use the `with_*` methods in the type returned
49/// by [builder()][AssuredWorkloadsService::builder]. The default configuration should
50/// work for most applications. Common configuration changes include
51///
52/// * [with_endpoint()]: by default this client uses the global default endpoint
53///   (`https://assuredworkloads.googleapis.com`). Applications using regional
54///   endpoints or running in restricted networks (e.g. a network configured
55///   with [Private Google Access with VPC Service Controls]) may want to
56///   override this default.
57/// * [with_credentials()]: by default this client uses
58///   [Application Default Credentials]. Applications using custom
59///   authentication may need to override this default.
60///
61/// [with_endpoint()]: super::builder::assured_workloads_service::ClientBuilder::with_endpoint
62/// [with_credentials()]: super::builder::assured_workloads_service::ClientBuilder::with_credentials
63/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
64/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
65///
66/// # Pooling and Cloning
67///
68/// `AssuredWorkloadsService` holds a connection pool internally, it is advised to
69/// create one and reuse it. You do not need to wrap `AssuredWorkloadsService` in
70/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
71/// already uses an `Arc` internally.
72#[derive(Clone, Debug)]
73pub struct AssuredWorkloadsService {
74    inner: std::sync::Arc<dyn super::stub::dynamic::AssuredWorkloadsService>,
75}
76
77impl AssuredWorkloadsService {
78    /// Returns a builder for [AssuredWorkloadsService].
79    ///
80    /// ```
81    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
82    /// # use google_cloud_assuredworkloads_v1::client::AssuredWorkloadsService;
83    /// let client = AssuredWorkloadsService::builder().build().await?;
84    /// # Ok(()) }
85    /// ```
86    pub fn builder() -> super::builder::assured_workloads_service::ClientBuilder {
87        crate::new_client_builder(super::builder::assured_workloads_service::client::Factory)
88    }
89
90    /// Creates a new client from the provided stub.
91    ///
92    /// The most common case for calling this function is in tests mocking the
93    /// client's behavior.
94    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
95    where
96        T: super::stub::AssuredWorkloadsService + 'static,
97    {
98        Self { inner: stub.into() }
99    }
100
101    pub(crate) async fn new(
102        config: gaxi::options::ClientConfig,
103    ) -> crate::ClientBuilderResult<Self> {
104        let inner = Self::build_inner(config).await?;
105        Ok(Self { inner })
106    }
107
108    async fn build_inner(
109        conf: gaxi::options::ClientConfig,
110    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::AssuredWorkloadsService>>
111    {
112        if gaxi::options::tracing_enabled(&conf) {
113            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
114        }
115        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
116    }
117
118    async fn build_transport(
119        conf: gaxi::options::ClientConfig,
120    ) -> crate::ClientBuilderResult<impl super::stub::AssuredWorkloadsService> {
121        super::transport::AssuredWorkloadsService::new(conf).await
122    }
123
124    async fn build_with_tracing(
125        conf: gaxi::options::ClientConfig,
126    ) -> crate::ClientBuilderResult<impl super::stub::AssuredWorkloadsService> {
127        Self::build_transport(conf)
128            .await
129            .map(super::tracing::AssuredWorkloadsService::new)
130    }
131
132    /// Creates Assured Workload.
133    ///
134    /// # Long running operations
135    ///
136    /// This method is used to start, and/or poll a [long-running Operation].
137    /// The [Working with long-running operations] chapter in the [user guide]
138    /// covers these operations in detail.
139    ///
140    /// [long-running operation]: https://google.aip.dev/151
141    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
142    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
143    ///
144    /// # Example
145    /// ```
146    /// # use google_cloud_assuredworkloads_v1::client::AssuredWorkloadsService;
147    /// use google_cloud_lro::Poller;
148    /// use google_cloud_assuredworkloads_v1::model::Workload;
149    /// use google_cloud_assuredworkloads_v1::Result;
150    /// async fn sample(
151    ///    client: &AssuredWorkloadsService, organization_id: &str, location_id: &str
152    /// ) -> Result<()> {
153    ///     let response = client.create_workload()
154    ///         .set_parent(format!("organizations/{organization_id}/locations/{location_id}"))
155    ///         .set_workload(
156    ///             Workload::new()/* set fields */
157    ///         )
158    ///         .poller().until_done().await?;
159    ///     println!("response {:?}", response);
160    ///     Ok(())
161    /// }
162    /// ```
163    pub fn create_workload(&self) -> super::builder::assured_workloads_service::CreateWorkload {
164        super::builder::assured_workloads_service::CreateWorkload::new(self.inner.clone())
165    }
166
167    /// Updates an existing workload.
168    /// Currently allows updating of workload display_name and labels.
169    /// For force updates don't set etag field in the Workload.
170    /// Only one update operation per workload can be in progress.
171    ///
172    /// # Example
173    /// ```
174    /// # use google_cloud_assuredworkloads_v1::client::AssuredWorkloadsService;
175    /// # extern crate wkt as google_cloud_wkt;
176    /// use google_cloud_wkt::FieldMask;
177    /// use google_cloud_assuredworkloads_v1::model::Workload;
178    /// use google_cloud_assuredworkloads_v1::Result;
179    /// async fn sample(
180    ///    client: &AssuredWorkloadsService, organization_id: &str, location_id: &str, workload_id: &str
181    /// ) -> Result<()> {
182    ///     let response = client.update_workload()
183    ///         .set_workload(
184    ///             Workload::new().set_name(format!("organizations/{organization_id}/locations/{location_id}/workloads/{workload_id}"))/* set fields */
185    ///         )
186    ///         .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
187    ///         .send().await?;
188    ///     println!("response {:?}", response);
189    ///     Ok(())
190    /// }
191    /// ```
192    pub fn update_workload(&self) -> super::builder::assured_workloads_service::UpdateWorkload {
193        super::builder::assured_workloads_service::UpdateWorkload::new(self.inner.clone())
194    }
195
196    /// Restrict the list of resources allowed in the Workload environment.
197    /// The current list of allowed products can be found at
198    /// <https://cloud.google.com/assured-workloads/docs/supported-products>
199    /// In addition to assuredworkloads.workload.update permission, the user should
200    /// also have orgpolicy.policy.set permission on the folder resource
201    /// to use this functionality.
202    ///
203    /// # Example
204    /// ```
205    /// # use google_cloud_assuredworkloads_v1::client::AssuredWorkloadsService;
206    /// use google_cloud_assuredworkloads_v1::Result;
207    /// async fn sample(
208    ///    client: &AssuredWorkloadsService
209    /// ) -> Result<()> {
210    ///     let response = client.restrict_allowed_resources()
211    ///         /* set fields */
212    ///         .send().await?;
213    ///     println!("response {:?}", response);
214    ///     Ok(())
215    /// }
216    /// ```
217    pub fn restrict_allowed_resources(
218        &self,
219    ) -> super::builder::assured_workloads_service::RestrictAllowedResources {
220        super::builder::assured_workloads_service::RestrictAllowedResources::new(self.inner.clone())
221    }
222
223    /// Deletes the workload. Make sure that workload's direct children are already
224    /// in a deleted state, otherwise the request will fail with a
225    /// FAILED_PRECONDITION error.
226    ///
227    /// # Example
228    /// ```
229    /// # use google_cloud_assuredworkloads_v1::client::AssuredWorkloadsService;
230    /// use google_cloud_assuredworkloads_v1::Result;
231    /// async fn sample(
232    ///    client: &AssuredWorkloadsService, organization_id: &str, location_id: &str, workload_id: &str
233    /// ) -> Result<()> {
234    ///     client.delete_workload()
235    ///         .set_name(format!("organizations/{organization_id}/locations/{location_id}/workloads/{workload_id}"))
236    ///         .send().await?;
237    ///     Ok(())
238    /// }
239    /// ```
240    pub fn delete_workload(&self) -> super::builder::assured_workloads_service::DeleteWorkload {
241        super::builder::assured_workloads_service::DeleteWorkload::new(self.inner.clone())
242    }
243
244    /// Gets Assured Workload associated with a CRM Node
245    ///
246    /// # Example
247    /// ```
248    /// # use google_cloud_assuredworkloads_v1::client::AssuredWorkloadsService;
249    /// use google_cloud_assuredworkloads_v1::Result;
250    /// async fn sample(
251    ///    client: &AssuredWorkloadsService, organization_id: &str, location_id: &str, workload_id: &str
252    /// ) -> Result<()> {
253    ///     let response = client.get_workload()
254    ///         .set_name(format!("organizations/{organization_id}/locations/{location_id}/workloads/{workload_id}"))
255    ///         .send().await?;
256    ///     println!("response {:?}", response);
257    ///     Ok(())
258    /// }
259    /// ```
260    pub fn get_workload(&self) -> super::builder::assured_workloads_service::GetWorkload {
261        super::builder::assured_workloads_service::GetWorkload::new(self.inner.clone())
262    }
263
264    /// Lists Assured Workloads under a CRM Node.
265    ///
266    /// # Example
267    /// ```
268    /// # use google_cloud_assuredworkloads_v1::client::AssuredWorkloadsService;
269    /// use google_cloud_gax::paginator::ItemPaginator as _;
270    /// use google_cloud_assuredworkloads_v1::Result;
271    /// async fn sample(
272    ///    client: &AssuredWorkloadsService, organization_id: &str, location_id: &str
273    /// ) -> Result<()> {
274    ///     let mut list = client.list_workloads()
275    ///         .set_parent(format!("organizations/{organization_id}/locations/{location_id}"))
276    ///         .by_item();
277    ///     while let Some(item) = list.next().await.transpose()? {
278    ///         println!("{:?}", item);
279    ///     }
280    ///     Ok(())
281    /// }
282    /// ```
283    pub fn list_workloads(&self) -> super::builder::assured_workloads_service::ListWorkloads {
284        super::builder::assured_workloads_service::ListWorkloads::new(self.inner.clone())
285    }
286
287    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
288    ///
289    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
290    ///
291    /// # Example
292    /// ```
293    /// # use google_cloud_assuredworkloads_v1::client::AssuredWorkloadsService;
294    /// use google_cloud_gax::paginator::ItemPaginator as _;
295    /// use google_cloud_assuredworkloads_v1::Result;
296    /// async fn sample(
297    ///    client: &AssuredWorkloadsService
298    /// ) -> Result<()> {
299    ///     let mut list = client.list_operations()
300    ///         /* set fields */
301    ///         .by_item();
302    ///     while let Some(item) = list.next().await.transpose()? {
303    ///         println!("{:?}", item);
304    ///     }
305    ///     Ok(())
306    /// }
307    /// ```
308    pub fn list_operations(&self) -> super::builder::assured_workloads_service::ListOperations {
309        super::builder::assured_workloads_service::ListOperations::new(self.inner.clone())
310    }
311
312    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
313    ///
314    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
315    ///
316    /// # Example
317    /// ```
318    /// # use google_cloud_assuredworkloads_v1::client::AssuredWorkloadsService;
319    /// use google_cloud_assuredworkloads_v1::Result;
320    /// async fn sample(
321    ///    client: &AssuredWorkloadsService
322    /// ) -> Result<()> {
323    ///     let response = client.get_operation()
324    ///         /* set fields */
325    ///         .send().await?;
326    ///     println!("response {:?}", response);
327    ///     Ok(())
328    /// }
329    /// ```
330    pub fn get_operation(&self) -> super::builder::assured_workloads_service::GetOperation {
331        super::builder::assured_workloads_service::GetOperation::new(self.inner.clone())
332    }
333}