google_cloud_workloadidentity_v1/client.rs
1// Copyright 2026 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 Workload Identity API.
22///
23/// # Example
24/// ```
25/// # use google_cloud_workloadidentity_v1::client::WorkloadIdentity;
26/// use google_cloud_lro::Poller;
27/// async fn sample(
28/// ) -> anyhow::Result<()> {
29/// let client = WorkloadIdentity::builder().build().await?;
30/// let response = client.generate_service_agents()
31/// /* set fields */
32/// .poller().until_done().await?;
33/// println!("response {:?}", response);
34/// Ok(())
35/// }
36/// ```
37///
38/// # Service Description
39///
40/// Service describing handlers for resources
41///
42/// # Configuration
43///
44/// To configure `WorkloadIdentity` use the `with_*` methods in the type returned
45/// by [builder()][WorkloadIdentity::builder]. The default configuration should
46/// work for most applications. Common configuration changes include
47///
48/// * [with_endpoint()]: by default this client uses the global default endpoint
49/// (`https://workloadidentity.googleapis.com`). Applications using regional
50/// endpoints or running in restricted networks (e.g. a network configured
51/// with [Private Google Access with VPC Service Controls]) may want to
52/// override this default.
53/// * [with_credentials()]: by default this client uses
54/// [Application Default Credentials]. Applications using custom
55/// authentication may need to override this default.
56///
57/// [with_endpoint()]: super::builder::workload_identity::ClientBuilder::with_endpoint
58/// [with_credentials()]: super::builder::workload_identity::ClientBuilder::with_credentials
59/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
60/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
61///
62/// # Pooling and Cloning
63///
64/// `WorkloadIdentity` holds a connection pool internally, it is advised to
65/// create one and reuse it. You do not need to wrap `WorkloadIdentity` in
66/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
67/// already uses an `Arc` internally.
68#[derive(Clone, Debug)]
69pub struct WorkloadIdentity {
70 inner: std::sync::Arc<dyn super::stub::dynamic::WorkloadIdentity>,
71}
72
73impl WorkloadIdentity {
74 /// Returns a builder for [WorkloadIdentity].
75 ///
76 /// ```
77 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
78 /// # use google_cloud_workloadidentity_v1::client::WorkloadIdentity;
79 /// let client = WorkloadIdentity::builder().build().await?;
80 /// # Ok(()) }
81 /// ```
82 pub fn builder() -> super::builder::workload_identity::ClientBuilder {
83 crate::new_client_builder(super::builder::workload_identity::client::Factory)
84 }
85
86 /// Creates a new client from the provided stub.
87 ///
88 /// The most common case for calling this function is in tests mocking the
89 /// client's behavior.
90 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
91 where
92 T: super::stub::WorkloadIdentity + 'static,
93 {
94 Self { inner: stub.into() }
95 }
96
97 pub(crate) async fn new(
98 config: gaxi::options::ClientConfig,
99 ) -> crate::ClientBuilderResult<Self> {
100 let inner = Self::build_inner(config).await?;
101 Ok(Self { inner })
102 }
103
104 async fn build_inner(
105 conf: gaxi::options::ClientConfig,
106 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::WorkloadIdentity>>
107 {
108 if gaxi::options::tracing_enabled(&conf) {
109 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
110 }
111 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
112 }
113
114 async fn build_transport(
115 conf: gaxi::options::ClientConfig,
116 ) -> crate::ClientBuilderResult<impl super::stub::WorkloadIdentity> {
117 super::transport::WorkloadIdentity::new(conf).await
118 }
119
120 async fn build_with_tracing(
121 conf: gaxi::options::ClientConfig,
122 ) -> crate::ClientBuilderResult<impl super::stub::WorkloadIdentity> {
123 Self::build_transport(conf)
124 .await
125 .map(super::tracing::WorkloadIdentity::new)
126 }
127
128 /// Creates all service agents for a given resource, location and service
129 /// producer.
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_workloadidentity_v1::client::WorkloadIdentity;
144 /// use google_cloud_lro::Poller;
145 /// use google_cloud_workloadidentity_v1::Result;
146 /// async fn sample(
147 /// client: &WorkloadIdentity
148 /// ) -> Result<()> {
149 /// let response = client.generate_service_agents()
150 /// /* set fields */
151 /// .poller().until_done().await?;
152 /// println!("response {:?}", response);
153 /// Ok(())
154 /// }
155 /// ```
156 pub fn generate_service_agents(
157 &self,
158 ) -> super::builder::workload_identity::GenerateServiceAgents {
159 super::builder::workload_identity::GenerateServiceAgents::new(self.inner.clone())
160 }
161
162 /// Lists information about the supported locations for this service.
163 ///
164 /// This method lists locations based on the resource scope provided in
165 /// the [ListLocationsRequest.name][google.cloud.location.ListLocationsRequest.name] field: *
166 /// **Global locations**: If `name` is empty, the method lists the
167 /// public locations available to all projects. * **Project-specific
168 /// locations**: If `name` follows the format
169 /// `projects/{project}`, the method lists locations visible to that
170 /// specific project. This includes public, private, or other
171 /// project-specific locations enabled for the project.
172 ///
173 /// For gRPC and client library implementations, the resource name is
174 /// passed as the `name` field. For direct service calls, the resource
175 /// name is
176 /// incorporated into the request path based on the specific service
177 /// implementation and version.
178 ///
179 /// [google.cloud.location.ListLocationsRequest.name]: google_cloud_location::model::ListLocationsRequest::name
180 ///
181 /// # Example
182 /// ```
183 /// # use google_cloud_workloadidentity_v1::client::WorkloadIdentity;
184 /// use google_cloud_gax::paginator::ItemPaginator as _;
185 /// use google_cloud_workloadidentity_v1::Result;
186 /// async fn sample(
187 /// client: &WorkloadIdentity
188 /// ) -> Result<()> {
189 /// let mut list = client.list_locations()
190 /// /* set fields */
191 /// .by_item();
192 /// while let Some(item) = list.next().await.transpose()? {
193 /// println!("{:?}", item);
194 /// }
195 /// Ok(())
196 /// }
197 /// ```
198 pub fn list_locations(&self) -> super::builder::workload_identity::ListLocations {
199 super::builder::workload_identity::ListLocations::new(self.inner.clone())
200 }
201
202 /// Gets information about a location.
203 ///
204 /// # Example
205 /// ```
206 /// # use google_cloud_workloadidentity_v1::client::WorkloadIdentity;
207 /// use google_cloud_workloadidentity_v1::Result;
208 /// async fn sample(
209 /// client: &WorkloadIdentity
210 /// ) -> Result<()> {
211 /// let response = client.get_location()
212 /// /* set fields */
213 /// .send().await?;
214 /// println!("response {:?}", response);
215 /// Ok(())
216 /// }
217 /// ```
218 pub fn get_location(&self) -> super::builder::workload_identity::GetLocation {
219 super::builder::workload_identity::GetLocation::new(self.inner.clone())
220 }
221
222 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
223 ///
224 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
225 ///
226 /// # Example
227 /// ```
228 /// # use google_cloud_workloadidentity_v1::client::WorkloadIdentity;
229 /// use google_cloud_gax::paginator::ItemPaginator as _;
230 /// use google_cloud_workloadidentity_v1::Result;
231 /// async fn sample(
232 /// client: &WorkloadIdentity
233 /// ) -> Result<()> {
234 /// let mut list = client.list_operations()
235 /// /* set fields */
236 /// .by_item();
237 /// while let Some(item) = list.next().await.transpose()? {
238 /// println!("{:?}", item);
239 /// }
240 /// Ok(())
241 /// }
242 /// ```
243 pub fn list_operations(&self) -> super::builder::workload_identity::ListOperations {
244 super::builder::workload_identity::ListOperations::new(self.inner.clone())
245 }
246
247 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
248 ///
249 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
250 ///
251 /// # Example
252 /// ```
253 /// # use google_cloud_workloadidentity_v1::client::WorkloadIdentity;
254 /// use google_cloud_workloadidentity_v1::Result;
255 /// async fn sample(
256 /// client: &WorkloadIdentity
257 /// ) -> Result<()> {
258 /// let response = client.get_operation()
259 /// /* set fields */
260 /// .send().await?;
261 /// println!("response {:?}", response);
262 /// Ok(())
263 /// }
264 /// ```
265 pub fn get_operation(&self) -> super::builder::workload_identity::GetOperation {
266 super::builder::workload_identity::GetOperation::new(self.inner.clone())
267 }
268
269 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
270 ///
271 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
272 ///
273 /// # Example
274 /// ```
275 /// # use google_cloud_workloadidentity_v1::client::WorkloadIdentity;
276 /// use google_cloud_workloadidentity_v1::Result;
277 /// async fn sample(
278 /// client: &WorkloadIdentity
279 /// ) -> Result<()> {
280 /// client.delete_operation()
281 /// /* set fields */
282 /// .send().await?;
283 /// Ok(())
284 /// }
285 /// ```
286 pub fn delete_operation(&self) -> super::builder::workload_identity::DeleteOperation {
287 super::builder::workload_identity::DeleteOperation::new(self.inner.clone())
288 }
289
290 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
291 ///
292 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
293 ///
294 /// # Example
295 /// ```
296 /// # use google_cloud_workloadidentity_v1::client::WorkloadIdentity;
297 /// use google_cloud_workloadidentity_v1::Result;
298 /// async fn sample(
299 /// client: &WorkloadIdentity
300 /// ) -> Result<()> {
301 /// client.cancel_operation()
302 /// /* set fields */
303 /// .send().await?;
304 /// Ok(())
305 /// }
306 /// ```
307 pub fn cancel_operation(&self) -> super::builder::workload_identity::CancelOperation {
308 super::builder::workload_identity::CancelOperation::new(self.inner.clone())
309 }
310}