google_cloud_api_serviceusage_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 Service Usage API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
24/// use google_cloud_gax::paginator::ItemPaginator as _;
25/// # async fn sample() -> Result<(), Box<dyn std::error::Error>> {
26/// let client = ServiceUsage::builder().build().await?;
27/// let parent = "parent_value";
28/// let mut list = client.list_services()
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/// Enables services that service consumers want to use on Google Cloud Platform,
40/// lists the available or enabled services, or disables services that service
41/// consumers no longer use.
42///
43/// See [Service Usage API](https://cloud.google.com/service-usage/docs/overview)
44///
45/// # Configuration
46///
47/// To configure `ServiceUsage` use the `with_*` methods in the type returned
48/// by [builder()][ServiceUsage::builder]. The default configuration should
49/// work for most applications. Common configuration changes include
50///
51/// * [with_endpoint()]: by default this client uses the global default endpoint
52/// (`https://serviceusage.googleapis.com`). Applications using regional
53/// endpoints or running in restricted networks (e.g. a network configured
54// with [Private Google Access with VPC Service Controls]) may want to
55/// override this default.
56/// * [with_credentials()]: by default this client uses
57/// [Application Default Credentials]. Applications using custom
58/// authentication may need to override this default.
59///
60/// [with_endpoint()]: super::builder::service_usage::ClientBuilder::with_endpoint
61/// [with_credentials()]: super::builder::service_usage::ClientBuilder::with_credentials
62/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
63/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
64///
65/// # Pooling and Cloning
66///
67/// `ServiceUsage` holds a connection pool internally, it is advised to
68/// create one and reuse it. You do not need to wrap `ServiceUsage` in
69/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
70/// already uses an `Arc` internally.
71#[derive(Clone, Debug)]
72pub struct ServiceUsage {
73 inner: std::sync::Arc<dyn super::stub::dynamic::ServiceUsage>,
74}
75
76impl ServiceUsage {
77 /// Returns a builder for [ServiceUsage].
78 ///
79 /// ```
80 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
81 /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
82 /// let client = ServiceUsage::builder().build().await?;
83 /// # Ok(()) }
84 /// ```
85 pub fn builder() -> super::builder::service_usage::ClientBuilder {
86 crate::new_client_builder(super::builder::service_usage::client::Factory)
87 }
88
89 /// Creates a new client from the provided stub.
90 ///
91 /// The most common case for calling this function is in tests mocking the
92 /// client's behavior.
93 pub fn from_stub<T>(stub: T) -> Self
94 where
95 T: super::stub::ServiceUsage + 'static,
96 {
97 Self {
98 inner: std::sync::Arc::new(stub),
99 }
100 }
101
102 pub(crate) async fn new(
103 config: gaxi::options::ClientConfig,
104 ) -> crate::ClientBuilderResult<Self> {
105 let inner = Self::build_inner(config).await?;
106 Ok(Self { inner })
107 }
108
109 async fn build_inner(
110 conf: gaxi::options::ClientConfig,
111 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::ServiceUsage>> {
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::ServiceUsage> {
121 super::transport::ServiceUsage::new(conf).await
122 }
123
124 async fn build_with_tracing(
125 conf: gaxi::options::ClientConfig,
126 ) -> crate::ClientBuilderResult<impl super::stub::ServiceUsage> {
127 Self::build_transport(conf)
128 .await
129 .map(super::tracing::ServiceUsage::new)
130 }
131
132 /// Enable a service so that it can be used with a project.
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_api_serviceusage_v1::client::ServiceUsage;
147 /// use google_cloud_lro::Poller;
148 /// use google_cloud_api_serviceusage_v1::Result;
149 /// async fn sample(
150 /// client: &ServiceUsage
151 /// ) -> Result<()> {
152 /// let response = client.enable_service()
153 /// /* set fields */
154 /// .poller().until_done().await?;
155 /// println!("response {:?}", response);
156 /// Ok(())
157 /// }
158 /// ```
159 pub fn enable_service(&self) -> super::builder::service_usage::EnableService {
160 super::builder::service_usage::EnableService::new(self.inner.clone())
161 }
162
163 /// Disable a service so that it can no longer be used with a project.
164 /// This prevents unintended usage that may cause unexpected billing
165 /// charges or security leaks.
166 ///
167 /// It is not valid to call the disable method on a service that is not
168 /// currently enabled. Callers will receive a `FAILED_PRECONDITION` status if
169 /// the target service is not currently enabled.
170 ///
171 /// # Long running operations
172 ///
173 /// This method is used to start, and/or poll a [long-running Operation].
174 /// The [Working with long-running operations] chapter in the [user guide]
175 /// covers these operations in detail.
176 ///
177 /// [long-running operation]: https://google.aip.dev/151
178 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
179 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
180 ///
181 /// # Example
182 /// ```
183 /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
184 /// use google_cloud_lro::Poller;
185 /// use google_cloud_api_serviceusage_v1::Result;
186 /// async fn sample(
187 /// client: &ServiceUsage
188 /// ) -> Result<()> {
189 /// let response = client.disable_service()
190 /// /* set fields */
191 /// .poller().until_done().await?;
192 /// println!("response {:?}", response);
193 /// Ok(())
194 /// }
195 /// ```
196 pub fn disable_service(&self) -> super::builder::service_usage::DisableService {
197 super::builder::service_usage::DisableService::new(self.inner.clone())
198 }
199
200 /// Returns the service configuration and enabled state for a given service.
201 ///
202 /// # Example
203 /// ```
204 /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
205 /// use google_cloud_api_serviceusage_v1::Result;
206 /// async fn sample(
207 /// client: &ServiceUsage
208 /// ) -> Result<()> {
209 /// let response = client.get_service()
210 /// /* set fields */
211 /// .send().await?;
212 /// println!("response {:?}", response);
213 /// Ok(())
214 /// }
215 /// ```
216 pub fn get_service(&self) -> super::builder::service_usage::GetService {
217 super::builder::service_usage::GetService::new(self.inner.clone())
218 }
219
220 /// List all services available to the specified project, and the current
221 /// state of those services with respect to the project. The list includes
222 /// all public services, all services for which the calling user has the
223 /// `servicemanagement.services.bind` permission, and all services that have
224 /// already been enabled on the project. The list can be filtered to
225 /// only include services in a specific state, for example to only include
226 /// services enabled on the project.
227 ///
228 /// WARNING: If you need to query enabled services frequently or across
229 /// an organization, you should use
230 /// [Cloud Asset Inventory
231 /// API](https://cloud.google.com/asset-inventory/docs/apis), which provides
232 /// higher throughput and richer filtering capability.
233 ///
234 /// # Example
235 /// ```
236 /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
237 /// use google_cloud_gax::paginator::ItemPaginator as _;
238 /// use google_cloud_api_serviceusage_v1::Result;
239 /// async fn sample(
240 /// client: &ServiceUsage, parent: &str
241 /// ) -> Result<()> {
242 /// let mut list = client.list_services()
243 /// .set_parent(parent)
244 /// .by_item();
245 /// while let Some(item) = list.next().await.transpose()? {
246 /// println!("{:?}", item);
247 /// }
248 /// Ok(())
249 /// }
250 /// ```
251 pub fn list_services(&self) -> super::builder::service_usage::ListServices {
252 super::builder::service_usage::ListServices::new(self.inner.clone())
253 }
254
255 /// Enable multiple services on a project. The operation is atomic: if enabling
256 /// any service fails, then the entire batch fails, and no state changes occur.
257 /// To enable a single service, use the `EnableService` method instead.
258 ///
259 /// # Long running operations
260 ///
261 /// This method is used to start, and/or poll a [long-running Operation].
262 /// The [Working with long-running operations] chapter in the [user guide]
263 /// covers these operations in detail.
264 ///
265 /// [long-running operation]: https://google.aip.dev/151
266 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
267 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
268 ///
269 /// # Example
270 /// ```
271 /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
272 /// use google_cloud_lro::Poller;
273 /// use google_cloud_api_serviceusage_v1::Result;
274 /// async fn sample(
275 /// client: &ServiceUsage
276 /// ) -> Result<()> {
277 /// let response = client.batch_enable_services()
278 /// /* set fields */
279 /// .poller().until_done().await?;
280 /// println!("response {:?}", response);
281 /// Ok(())
282 /// }
283 /// ```
284 pub fn batch_enable_services(&self) -> super::builder::service_usage::BatchEnableServices {
285 super::builder::service_usage::BatchEnableServices::new(self.inner.clone())
286 }
287
288 /// Returns the service configurations and enabled states for a given list of
289 /// services.
290 ///
291 /// # Example
292 /// ```
293 /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
294 /// use google_cloud_api_serviceusage_v1::Result;
295 /// async fn sample(
296 /// client: &ServiceUsage
297 /// ) -> Result<()> {
298 /// let response = client.batch_get_services()
299 /// /* set fields */
300 /// .send().await?;
301 /// println!("response {:?}", response);
302 /// Ok(())
303 /// }
304 /// ```
305 pub fn batch_get_services(&self) -> super::builder::service_usage::BatchGetServices {
306 super::builder::service_usage::BatchGetServices::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_api_serviceusage_v1::client::ServiceUsage;
316 /// use google_cloud_gax::paginator::ItemPaginator as _;
317 /// use google_cloud_api_serviceusage_v1::Result;
318 /// async fn sample(
319 /// client: &ServiceUsage
320 /// ) -> Result<()> {
321 /// let mut list = client.list_operations()
322 /// /* set fields */
323 /// .by_item();
324 /// while let Some(item) = list.next().await.transpose()? {
325 /// println!("{:?}", item);
326 /// }
327 /// Ok(())
328 /// }
329 /// ```
330 pub fn list_operations(&self) -> super::builder::service_usage::ListOperations {
331 super::builder::service_usage::ListOperations::new(self.inner.clone())
332 }
333
334 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
335 ///
336 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
337 ///
338 /// # Example
339 /// ```
340 /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
341 /// use google_cloud_api_serviceusage_v1::Result;
342 /// async fn sample(
343 /// client: &ServiceUsage
344 /// ) -> Result<()> {
345 /// let response = client.get_operation()
346 /// /* set fields */
347 /// .send().await?;
348 /// println!("response {:?}", response);
349 /// Ok(())
350 /// }
351 /// ```
352 pub fn get_operation(&self) -> super::builder::service_usage::GetOperation {
353 super::builder::service_usage::GetOperation::new(self.inner.clone())
354 }
355}