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