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