google_cloud_api_servicecontrol_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 Control API.
22///
23/// # Example
24/// ```
25/// # use google_cloud_api_servicecontrol_v1::client::QuotaController;
26/// async fn sample(
27/// ) -> anyhow::Result<()> {
28/// let client = QuotaController::builder().build().await?;
29/// let response = client.allocate_quota()
30/// /* set fields */
31/// .send().await?;
32/// println!("response {:?}", response);
33/// Ok(())
34/// }
35/// ```
36///
37/// # Service Description
38///
39/// [Google Quota Control API](https://cloud.google.com/service-control/overview)
40///
41/// Allows clients to allocate and release quota against a [managed
42/// service](https://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService).
43///
44/// # Configuration
45///
46/// To configure `QuotaController` use the `with_*` methods in the type returned
47/// by [builder()][QuotaController::builder]. The default configuration should
48/// work for most applications. Common configuration changes include
49///
50/// * [with_endpoint()]: by default this client uses the global default endpoint
51/// (`https://servicecontrol.googleapis.com`). Applications using regional
52/// endpoints or running in restricted networks (e.g. a network configured
53/// with [Private Google Access with VPC Service Controls]) may want to
54/// override this default.
55/// * [with_credentials()]: by default this client uses
56/// [Application Default Credentials]. Applications using custom
57/// authentication may need to override this default.
58///
59/// [with_endpoint()]: super::builder::quota_controller::ClientBuilder::with_endpoint
60/// [with_credentials()]: super::builder::quota_controller::ClientBuilder::with_credentials
61/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
62/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
63///
64/// # Pooling and Cloning
65///
66/// `QuotaController` holds a connection pool internally, it is advised to
67/// create one and reuse it. You do not need to wrap `QuotaController` in
68/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
69/// already uses an `Arc` internally.
70#[derive(Clone, Debug)]
71pub struct QuotaController {
72 inner: std::sync::Arc<dyn super::stub::dynamic::QuotaController>,
73}
74
75impl QuotaController {
76 /// Returns a builder for [QuotaController].
77 ///
78 /// ```
79 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
80 /// # use google_cloud_api_servicecontrol_v1::client::QuotaController;
81 /// let client = QuotaController::builder().build().await?;
82 /// # Ok(()) }
83 /// ```
84 pub fn builder() -> super::builder::quota_controller::ClientBuilder {
85 crate::new_client_builder(super::builder::quota_controller::client::Factory)
86 }
87
88 /// Creates a new client from the provided stub.
89 ///
90 /// The most common case for calling this function is in tests mocking the
91 /// client's behavior.
92 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
93 where
94 T: super::stub::QuotaController + 'static,
95 {
96 Self { inner: stub.into() }
97 }
98
99 pub(crate) async fn new(
100 config: gaxi::options::ClientConfig,
101 ) -> crate::ClientBuilderResult<Self> {
102 let inner = Self::build_inner(config).await?;
103 Ok(Self { inner })
104 }
105
106 async fn build_inner(
107 conf: gaxi::options::ClientConfig,
108 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::QuotaController>> {
109 if gaxi::options::tracing_enabled(&conf) {
110 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
111 }
112 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
113 }
114
115 async fn build_transport(
116 conf: gaxi::options::ClientConfig,
117 ) -> crate::ClientBuilderResult<impl super::stub::QuotaController> {
118 super::transport::QuotaController::new(conf).await
119 }
120
121 async fn build_with_tracing(
122 conf: gaxi::options::ClientConfig,
123 ) -> crate::ClientBuilderResult<impl super::stub::QuotaController> {
124 Self::build_transport(conf)
125 .await
126 .map(super::tracing::QuotaController::new)
127 }
128
129 /// Attempts to allocate quota for the specified consumer. It should be called
130 /// before the operation is executed.
131 ///
132 /// This method requires the `servicemanagement.services.quota`
133 /// permission on the specified service. For more information, see
134 /// [Cloud IAM](https://cloud.google.com/iam).
135 ///
136 /// **NOTE:** The client **must** fail-open on server errors `INTERNAL`,
137 /// `UNKNOWN`, `DEADLINE_EXCEEDED`, and `UNAVAILABLE`. To ensure system
138 /// reliability, the server may inject these errors to prohibit any hard
139 /// dependency on the quota functionality.
140 ///
141 /// # Example
142 /// ```
143 /// # use google_cloud_api_servicecontrol_v1::client::QuotaController;
144 /// use google_cloud_api_servicecontrol_v1::Result;
145 /// async fn sample(
146 /// client: &QuotaController
147 /// ) -> Result<()> {
148 /// let response = client.allocate_quota()
149 /// /* set fields */
150 /// .send().await?;
151 /// println!("response {:?}", response);
152 /// Ok(())
153 /// }
154 /// ```
155 pub fn allocate_quota(&self) -> super::builder::quota_controller::AllocateQuota {
156 super::builder::quota_controller::AllocateQuota::new(self.inner.clone())
157 }
158}
159
160/// Implements a client for the Service Control API.
161///
162/// # Example
163/// ```
164/// # use google_cloud_api_servicecontrol_v1::client::ServiceController;
165/// async fn sample(
166/// ) -> anyhow::Result<()> {
167/// let client = ServiceController::builder().build().await?;
168/// let response = client.check()
169/// /* set fields */
170/// .send().await?;
171/// println!("response {:?}", response);
172/// Ok(())
173/// }
174/// ```
175///
176/// # Service Description
177///
178/// [Google Service Control
179/// API](https://cloud.google.com/service-control/overview)
180///
181/// Lets clients check and report operations against a [managed
182/// service](https://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService).
183///
184/// # Configuration
185///
186/// To configure `ServiceController` use the `with_*` methods in the type returned
187/// by [builder()][ServiceController::builder]. The default configuration should
188/// work for most applications. Common configuration changes include
189///
190/// * [with_endpoint()]: by default this client uses the global default endpoint
191/// (`https://servicecontrol.googleapis.com`). Applications using regional
192/// endpoints or running in restricted networks (e.g. a network configured
193/// with [Private Google Access with VPC Service Controls]) may want to
194/// override this default.
195/// * [with_credentials()]: by default this client uses
196/// [Application Default Credentials]. Applications using custom
197/// authentication may need to override this default.
198///
199/// [with_endpoint()]: super::builder::service_controller::ClientBuilder::with_endpoint
200/// [with_credentials()]: super::builder::service_controller::ClientBuilder::with_credentials
201/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
202/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
203///
204/// # Pooling and Cloning
205///
206/// `ServiceController` holds a connection pool internally, it is advised to
207/// create one and reuse it. You do not need to wrap `ServiceController` in
208/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
209/// already uses an `Arc` internally.
210#[derive(Clone, Debug)]
211pub struct ServiceController {
212 inner: std::sync::Arc<dyn super::stub::dynamic::ServiceController>,
213}
214
215impl ServiceController {
216 /// Returns a builder for [ServiceController].
217 ///
218 /// ```
219 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
220 /// # use google_cloud_api_servicecontrol_v1::client::ServiceController;
221 /// let client = ServiceController::builder().build().await?;
222 /// # Ok(()) }
223 /// ```
224 pub fn builder() -> super::builder::service_controller::ClientBuilder {
225 crate::new_client_builder(super::builder::service_controller::client::Factory)
226 }
227
228 /// Creates a new client from the provided stub.
229 ///
230 /// The most common case for calling this function is in tests mocking the
231 /// client's behavior.
232 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
233 where
234 T: super::stub::ServiceController + 'static,
235 {
236 Self { inner: stub.into() }
237 }
238
239 pub(crate) async fn new(
240 config: gaxi::options::ClientConfig,
241 ) -> crate::ClientBuilderResult<Self> {
242 let inner = Self::build_inner(config).await?;
243 Ok(Self { inner })
244 }
245
246 async fn build_inner(
247 conf: gaxi::options::ClientConfig,
248 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::ServiceController>>
249 {
250 if gaxi::options::tracing_enabled(&conf) {
251 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
252 }
253 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
254 }
255
256 async fn build_transport(
257 conf: gaxi::options::ClientConfig,
258 ) -> crate::ClientBuilderResult<impl super::stub::ServiceController> {
259 super::transport::ServiceController::new(conf).await
260 }
261
262 async fn build_with_tracing(
263 conf: gaxi::options::ClientConfig,
264 ) -> crate::ClientBuilderResult<impl super::stub::ServiceController> {
265 Self::build_transport(conf)
266 .await
267 .map(super::tracing::ServiceController::new)
268 }
269
270 /// Checks whether an operation on a service should be allowed to proceed
271 /// based on the configuration of the service and related policies. It must be
272 /// called before the operation is executed.
273 ///
274 /// If feasible, the client should cache the check results and reuse them for
275 /// 60 seconds. In case of any server errors, the client should rely on the
276 /// cached results for much longer time to avoid outage.
277 /// WARNING: There is general 60s delay for the configuration and policy
278 /// propagation, therefore callers MUST NOT depend on the `Check` method having
279 /// the latest policy information.
280 ///
281 /// NOTE: the [CheckRequest][google.api.servicecontrol.v1.CheckRequest] has the
282 /// size limit (wire-format byte size) of 1MB.
283 ///
284 /// This method requires the `servicemanagement.services.check` permission
285 /// on the specified service. For more information, see
286 /// [Cloud IAM](https://cloud.google.com/iam).
287 ///
288 /// [google.api.servicecontrol.v1.CheckRequest]: crate::model::CheckRequest
289 ///
290 /// # Example
291 /// ```
292 /// # use google_cloud_api_servicecontrol_v1::client::ServiceController;
293 /// use google_cloud_api_servicecontrol_v1::Result;
294 /// async fn sample(
295 /// client: &ServiceController
296 /// ) -> Result<()> {
297 /// let response = client.check()
298 /// /* set fields */
299 /// .send().await?;
300 /// println!("response {:?}", response);
301 /// Ok(())
302 /// }
303 /// ```
304 pub fn check(&self) -> super::builder::service_controller::Check {
305 super::builder::service_controller::Check::new(self.inner.clone())
306 }
307
308 /// Reports operation results to Google Service Control, such as logs and
309 /// metrics. It should be called after an operation is completed.
310 ///
311 /// If feasible, the client should aggregate reporting data for up to 5
312 /// seconds to reduce API traffic. Limiting aggregation to 5 seconds is to
313 /// reduce data loss during client crashes. Clients should carefully choose
314 /// the aggregation time window to avoid data loss risk more than 0.01%
315 /// for business and compliance reasons.
316 ///
317 /// NOTE: the [ReportRequest][google.api.servicecontrol.v1.ReportRequest] has
318 /// the size limit (wire-format byte size) of 1MB.
319 ///
320 /// This method requires the `servicemanagement.services.report` permission
321 /// on the specified service. For more information, see
322 /// [Google Cloud IAM](https://cloud.google.com/iam).
323 ///
324 /// [google.api.servicecontrol.v1.ReportRequest]: crate::model::ReportRequest
325 ///
326 /// # Example
327 /// ```
328 /// # use google_cloud_api_servicecontrol_v1::client::ServiceController;
329 /// use google_cloud_api_servicecontrol_v1::Result;
330 /// async fn sample(
331 /// client: &ServiceController
332 /// ) -> Result<()> {
333 /// let response = client.report()
334 /// /* set fields */
335 /// .send().await?;
336 /// println!("response {:?}", response);
337 /// Ok(())
338 /// }
339 /// ```
340 pub fn report(&self) -> super::builder::service_controller::Report {
341 super::builder::service_controller::Report::new(self.inner.clone())
342 }
343}