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