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