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/// # tokio_test::block_on(async {
24/// # use google_cloud_assuredworkloads_v1::client::AssuredWorkloadsService;
25/// let client = AssuredWorkloadsService::builder().build().await?;
26/// // use `client` to make requests to the Assured Workloads API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Service to manage AssuredWorkloads.
33///
34/// # Configuration
35///
36/// To configure `AssuredWorkloadsService` use the `with_*` methods in the type returned
37/// by [builder()][AssuredWorkloadsService::builder]. The default configuration should
38/// work for most applications. Common configuration changes include
39///
40/// * [with_endpoint()]: by default this client uses the global default endpoint
41///   (`https://assuredworkloads.googleapis.com`). Applications using regional
42///   endpoints or running in restricted networks (e.g. a network configured
43//    with [Private Google Access with VPC Service Controls]) may want to
44///   override this default.
45/// * [with_credentials()]: by default this client uses
46///   [Application Default Credentials]. Applications using custom
47///   authentication may need to override this default.
48///
49/// [with_endpoint()]: super::builder::assured_workloads_service::ClientBuilder::with_endpoint
50/// [with_credentials()]: super::builder::assured_workloads_service::ClientBuilder::credentials
51/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
52/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
53///
54/// # Pooling and Cloning
55///
56/// `AssuredWorkloadsService` holds a connection pool internally, it is advised to
57/// create one and the reuse it.  You do not need to wrap `AssuredWorkloadsService` in
58/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
59/// already uses an `Arc` internally.
60#[derive(Clone, Debug)]
61pub struct AssuredWorkloadsService {
62    inner: std::sync::Arc<dyn super::stub::dynamic::AssuredWorkloadsService>,
63}
64
65impl AssuredWorkloadsService {
66    /// Returns a builder for [AssuredWorkloadsService].
67    ///
68    /// ```
69    /// # tokio_test::block_on(async {
70    /// # use google_cloud_assuredworkloads_v1::client::AssuredWorkloadsService;
71    /// let client = AssuredWorkloadsService::builder().build().await?;
72    /// # gax::client_builder::Result::<()>::Ok(()) });
73    /// ```
74    pub fn builder() -> super::builder::assured_workloads_service::ClientBuilder {
75        gax::client_builder::internal::new_builder(
76            super::builder::assured_workloads_service::client::Factory,
77        )
78    }
79
80    /// Creates a new client from the provided stub.
81    ///
82    /// The most common case for calling this function is in tests mocking the
83    /// client's behavior.
84    pub fn from_stub<T>(stub: T) -> Self
85    where
86        T: super::stub::AssuredWorkloadsService + 'static,
87    {
88        Self {
89            inner: std::sync::Arc::new(stub),
90        }
91    }
92
93    pub(crate) async fn new(
94        config: gaxi::options::ClientConfig,
95    ) -> gax::client_builder::Result<Self> {
96        let inner = Self::build_inner(config).await?;
97        Ok(Self { inner })
98    }
99
100    async fn build_inner(
101        conf: gaxi::options::ClientConfig,
102    ) -> gax::client_builder::Result<
103        std::sync::Arc<dyn super::stub::dynamic::AssuredWorkloadsService>,
104    > {
105        if gaxi::options::tracing_enabled(&conf) {
106            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
107        }
108        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
109    }
110
111    async fn build_transport(
112        conf: gaxi::options::ClientConfig,
113    ) -> gax::client_builder::Result<impl super::stub::AssuredWorkloadsService> {
114        super::transport::AssuredWorkloadsService::new(conf).await
115    }
116
117    async fn build_with_tracing(
118        conf: gaxi::options::ClientConfig,
119    ) -> gax::client_builder::Result<impl super::stub::AssuredWorkloadsService> {
120        Self::build_transport(conf)
121            .await
122            .map(super::tracing::AssuredWorkloadsService::new)
123    }
124
125    /// Creates Assured Workload.
126    ///
127    /// # Long running operations
128    ///
129    /// This method is used to start, and/or poll a [long-running Operation].
130    /// The [Working with long-running operations] chapter in the [user guide]
131    /// covers these operations in detail.
132    ///
133    /// [long-running operation]: https://google.aip.dev/151
134    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
135    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
136    pub fn create_workload(&self) -> super::builder::assured_workloads_service::CreateWorkload {
137        super::builder::assured_workloads_service::CreateWorkload::new(self.inner.clone())
138    }
139
140    /// Updates an existing workload.
141    /// Currently allows updating of workload display_name and labels.
142    /// For force updates don't set etag field in the Workload.
143    /// Only one update operation per workload can be in progress.
144    pub fn update_workload(&self) -> super::builder::assured_workloads_service::UpdateWorkload {
145        super::builder::assured_workloads_service::UpdateWorkload::new(self.inner.clone())
146    }
147
148    /// Restrict the list of resources allowed in the Workload environment.
149    /// The current list of allowed products can be found at
150    /// <https://cloud.google.com/assured-workloads/docs/supported-products>
151    /// In addition to assuredworkloads.workload.update permission, the user should
152    /// also have orgpolicy.policy.set permission on the folder resource
153    /// to use this functionality.
154    pub fn restrict_allowed_resources(
155        &self,
156    ) -> super::builder::assured_workloads_service::RestrictAllowedResources {
157        super::builder::assured_workloads_service::RestrictAllowedResources::new(self.inner.clone())
158    }
159
160    /// Deletes the workload. Make sure that workload's direct children are already
161    /// in a deleted state, otherwise the request will fail with a
162    /// FAILED_PRECONDITION error.
163    pub fn delete_workload(&self) -> super::builder::assured_workloads_service::DeleteWorkload {
164        super::builder::assured_workloads_service::DeleteWorkload::new(self.inner.clone())
165    }
166
167    /// Gets Assured Workload associated with a CRM Node
168    pub fn get_workload(&self) -> super::builder::assured_workloads_service::GetWorkload {
169        super::builder::assured_workloads_service::GetWorkload::new(self.inner.clone())
170    }
171
172    /// Lists Assured Workloads under a CRM Node.
173    pub fn list_workloads(&self) -> super::builder::assured_workloads_service::ListWorkloads {
174        super::builder::assured_workloads_service::ListWorkloads::new(self.inner.clone())
175    }
176
177    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
178    ///
179    /// [google.longrunning.Operations]: longrunning::client::Operations
180    pub fn list_operations(&self) -> super::builder::assured_workloads_service::ListOperations {
181        super::builder::assured_workloads_service::ListOperations::new(self.inner.clone())
182    }
183
184    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
185    ///
186    /// [google.longrunning.Operations]: longrunning::client::Operations
187    pub fn get_operation(&self) -> super::builder::assured_workloads_service::GetOperation {
188        super::builder::assured_workloads_service::GetOperation::new(self.inner.clone())
189    }
190}