Skip to main content

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