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/// # tokio_test::block_on(async {
24/// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
25/// let client = ServiceUsage::builder().build().await?;
26/// // use `client` to make requests to the Service Usage API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Enables services that service consumers want to use on Google Cloud Platform,
33/// lists the available or enabled services, or disables services that service
34/// consumers no longer use.
35///
36/// See [Service Usage API](https://cloud.google.com/service-usage/docs/overview)
37///
38/// # Configuration
39///
40/// To configure `ServiceUsage` use the `with_*` methods in the type returned
41/// by [builder()][ServiceUsage::builder]. The default configuration should
42/// work for most applications. Common configuration changes include
43///
44/// * [with_endpoint()]: by default this client uses the global default endpoint
45/// (`https://serviceusage.googleapis.com`). Applications using regional
46/// endpoints or running in restricted networks (e.g. a network configured
47// with [Private Google Access with VPC Service Controls]) may want to
48/// override this default.
49/// * [with_credentials()]: by default this client uses
50/// [Application Default Credentials]. Applications using custom
51/// authentication may need to override this default.
52///
53/// [with_endpoint()]: super::builder::service_usage::ClientBuilder::with_endpoint
54/// [with_credentials()]: super::builder::service_usage::ClientBuilder::credentials
55/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
56/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
57///
58/// # Pooling and Cloning
59///
60/// `ServiceUsage` holds a connection pool internally, it is advised to
61/// create one and the reuse it. You do not need to wrap `ServiceUsage` in
62/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
63/// already uses an `Arc` internally.
64#[derive(Clone, Debug)]
65pub struct ServiceUsage {
66 inner: std::sync::Arc<dyn super::stub::dynamic::ServiceUsage>,
67}
68
69impl ServiceUsage {
70 /// Returns a builder for [ServiceUsage].
71 ///
72 /// ```
73 /// # tokio_test::block_on(async {
74 /// # use google_cloud_api_serviceusage_v1::client::ServiceUsage;
75 /// let client = ServiceUsage::builder().build().await?;
76 /// # gax::client_builder::Result::<()>::Ok(()) });
77 /// ```
78 pub fn builder() -> super::builder::service_usage::ClientBuilder {
79 gax::client_builder::internal::new_builder(super::builder::service_usage::client::Factory)
80 }
81
82 /// Creates a new client from the provided stub.
83 ///
84 /// The most common case for calling this function is in tests mocking the
85 /// client's behavior.
86 pub fn from_stub<T>(stub: T) -> Self
87 where
88 T: super::stub::ServiceUsage + 'static,
89 {
90 Self {
91 inner: std::sync::Arc::new(stub),
92 }
93 }
94
95 pub(crate) async fn new(
96 config: gaxi::options::ClientConfig,
97 ) -> gax::client_builder::Result<Self> {
98 let inner = Self::build_inner(config).await?;
99 Ok(Self { inner })
100 }
101
102 async fn build_inner(
103 conf: gaxi::options::ClientConfig,
104 ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::ServiceUsage>> {
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::ServiceUsage> {
114 super::transport::ServiceUsage::new(conf).await
115 }
116
117 async fn build_with_tracing(
118 conf: gaxi::options::ClientConfig,
119 ) -> gax::client_builder::Result<impl super::stub::ServiceUsage> {
120 Self::build_transport(conf)
121 .await
122 .map(super::tracing::ServiceUsage::new)
123 }
124
125 /// Enable a service so that it can be used with a project.
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 enable_service(&self) -> super::builder::service_usage::EnableService {
137 super::builder::service_usage::EnableService::new(self.inner.clone())
138 }
139
140 /// Disable a service so that it can no longer be used with a project.
141 /// This prevents unintended usage that may cause unexpected billing
142 /// charges or security leaks.
143 ///
144 /// It is not valid to call the disable method on a service that is not
145 /// currently enabled. Callers will receive a `FAILED_PRECONDITION` status if
146 /// the target service is not currently enabled.
147 ///
148 /// # Long running operations
149 ///
150 /// This method is used to start, and/or poll a [long-running Operation].
151 /// The [Working with long-running operations] chapter in the [user guide]
152 /// covers these operations in detail.
153 ///
154 /// [long-running operation]: https://google.aip.dev/151
155 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
156 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
157 pub fn disable_service(&self) -> super::builder::service_usage::DisableService {
158 super::builder::service_usage::DisableService::new(self.inner.clone())
159 }
160
161 /// Returns the service configuration and enabled state for a given service.
162 pub fn get_service(&self) -> super::builder::service_usage::GetService {
163 super::builder::service_usage::GetService::new(self.inner.clone())
164 }
165
166 /// List all services available to the specified project, and the current
167 /// state of those services with respect to the project. The list includes
168 /// all public services, all services for which the calling user has the
169 /// `servicemanagement.services.bind` permission, and all services that have
170 /// already been enabled on the project. The list can be filtered to
171 /// only include services in a specific state, for example to only include
172 /// services enabled on the project.
173 ///
174 /// WARNING: If you need to query enabled services frequently or across
175 /// an organization, you should use
176 /// [Cloud Asset Inventory
177 /// API](https://cloud.google.com/asset-inventory/docs/apis), which provides
178 /// higher throughput and richer filtering capability.
179 pub fn list_services(&self) -> super::builder::service_usage::ListServices {
180 super::builder::service_usage::ListServices::new(self.inner.clone())
181 }
182
183 /// Enable multiple services on a project. The operation is atomic: if enabling
184 /// any service fails, then the entire batch fails, and no state changes occur.
185 /// To enable a single service, use the `EnableService` method instead.
186 ///
187 /// # Long running operations
188 ///
189 /// This method is used to start, and/or poll a [long-running Operation].
190 /// The [Working with long-running operations] chapter in the [user guide]
191 /// covers these operations in detail.
192 ///
193 /// [long-running operation]: https://google.aip.dev/151
194 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
195 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
196 pub fn batch_enable_services(&self) -> super::builder::service_usage::BatchEnableServices {
197 super::builder::service_usage::BatchEnableServices::new(self.inner.clone())
198 }
199
200 /// Returns the service configurations and enabled states for a given list of
201 /// services.
202 pub fn batch_get_services(&self) -> super::builder::service_usage::BatchGetServices {
203 super::builder::service_usage::BatchGetServices::new(self.inner.clone())
204 }
205
206 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
207 ///
208 /// [google.longrunning.Operations]: longrunning::client::Operations
209 pub fn list_operations(&self) -> super::builder::service_usage::ListOperations {
210 super::builder::service_usage::ListOperations::new(self.inner.clone())
211 }
212
213 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
214 ///
215 /// [google.longrunning.Operations]: longrunning::client::Operations
216 pub fn get_operation(&self) -> super::builder::service_usage::GetOperation {
217 super::builder::service_usage::GetOperation::new(self.inner.clone())
218 }
219}