Skip to main content

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](/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 API](/service-control/overview)
179///
180/// Lets clients check and report operations against a [managed
181/// service](https://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService).
182///
183/// # Configuration
184///
185/// To configure `ServiceController` use the `with_*` methods in the type returned
186/// by [builder()][ServiceController::builder]. The default configuration should
187/// work for most applications. Common configuration changes include
188///
189/// * [with_endpoint()]: by default this client uses the global default endpoint
190///   (`https://servicecontrol.googleapis.com`). Applications using regional
191///   endpoints or running in restricted networks (e.g. a network configured
192///   with [Private Google Access with VPC Service Controls]) may want to
193///   override this default.
194/// * [with_credentials()]: by default this client uses
195///   [Application Default Credentials]. Applications using custom
196///   authentication may need to override this default.
197///
198/// [with_endpoint()]: super::builder::service_controller::ClientBuilder::with_endpoint
199/// [with_credentials()]: super::builder::service_controller::ClientBuilder::with_credentials
200/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
201/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
202///
203/// # Pooling and Cloning
204///
205/// `ServiceController` holds a connection pool internally, it is advised to
206/// create one and reuse it. You do not need to wrap `ServiceController` in
207/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
208/// already uses an `Arc` internally.
209#[derive(Clone, Debug)]
210pub struct ServiceController {
211    inner: std::sync::Arc<dyn super::stub::dynamic::ServiceController>,
212}
213
214impl ServiceController {
215    /// Returns a builder for [ServiceController].
216    ///
217    /// ```
218    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
219    /// # use google_cloud_api_servicecontrol_v1::client::ServiceController;
220    /// let client = ServiceController::builder().build().await?;
221    /// # Ok(()) }
222    /// ```
223    pub fn builder() -> super::builder::service_controller::ClientBuilder {
224        crate::new_client_builder(super::builder::service_controller::client::Factory)
225    }
226
227    /// Creates a new client from the provided stub.
228    ///
229    /// The most common case for calling this function is in tests mocking the
230    /// client's behavior.
231    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
232    where
233        T: super::stub::ServiceController + 'static,
234    {
235        Self { inner: stub.into() }
236    }
237
238    pub(crate) async fn new(
239        config: gaxi::options::ClientConfig,
240    ) -> crate::ClientBuilderResult<Self> {
241        let inner = Self::build_inner(config).await?;
242        Ok(Self { inner })
243    }
244
245    async fn build_inner(
246        conf: gaxi::options::ClientConfig,
247    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::ServiceController>>
248    {
249        if gaxi::options::tracing_enabled(&conf) {
250            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
251        }
252        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
253    }
254
255    async fn build_transport(
256        conf: gaxi::options::ClientConfig,
257    ) -> crate::ClientBuilderResult<impl super::stub::ServiceController> {
258        super::transport::ServiceController::new(conf).await
259    }
260
261    async fn build_with_tracing(
262        conf: gaxi::options::ClientConfig,
263    ) -> crate::ClientBuilderResult<impl super::stub::ServiceController> {
264        Self::build_transport(conf)
265            .await
266            .map(super::tracing::ServiceController::new)
267    }
268
269    /// Checks whether an operation on a service should be allowed to proceed
270    /// based on the configuration of the service and related policies. It must be
271    /// called before the operation is executed.
272    ///
273    /// If feasible, the client should cache the check results and reuse them for
274    /// 60 seconds. In case of any server errors, the client should rely on the
275    /// cached results for much longer time to avoid outage.
276    /// WARNING: There is general 60s delay for the configuration and policy
277    /// propagation, therefore callers MUST NOT depend on the `Check` method having
278    /// the latest policy information.
279    ///
280    /// NOTE: the [CheckRequest][google.api.servicecontrol.v1.CheckRequest] has
281    /// the size limit (wire-format byte size) of 1MB.
282    ///
283    /// This method requires the `servicemanagement.services.check` permission
284    /// on the specified service. For more information, see
285    /// [Cloud IAM](https://cloud.google.com/iam).
286    ///
287    /// [google.api.servicecontrol.v1.CheckRequest]: crate::model::CheckRequest
288    ///
289    /// # Example
290    /// ```
291    /// # use google_cloud_api_servicecontrol_v1::client::ServiceController;
292    /// use google_cloud_api_servicecontrol_v1::Result;
293    /// async fn sample(
294    ///    client: &ServiceController
295    /// ) -> Result<()> {
296    ///     let response = client.check()
297    ///         /* set fields */
298    ///         .send().await?;
299    ///     println!("response {:?}", response);
300    ///     Ok(())
301    /// }
302    /// ```
303    pub fn check(&self) -> super::builder::service_controller::Check {
304        super::builder::service_controller::Check::new(self.inner.clone())
305    }
306
307    /// Reports operation results to Google Service Control, such as logs and
308    /// metrics. It should be called after an operation is completed.
309    ///
310    /// If feasible, the client should aggregate reporting data for up to 5
311    /// seconds to reduce API traffic. Limiting aggregation to 5 seconds is to
312    /// reduce data loss during client crashes. Clients should carefully choose
313    /// the aggregation time window to avoid data loss risk more than 0.01%
314    /// for business and compliance reasons.
315    ///
316    /// NOTE: the [ReportRequest][google.api.servicecontrol.v1.ReportRequest] has
317    /// the size limit (wire-format byte size) of 1MB.
318    ///
319    /// This method requires the `servicemanagement.services.report` permission
320    /// on the specified service. For more information, see
321    /// [Google Cloud IAM](https://cloud.google.com/iam).
322    ///
323    /// [google.api.servicecontrol.v1.ReportRequest]: crate::model::ReportRequest
324    ///
325    /// # Example
326    /// ```
327    /// # use google_cloud_api_servicecontrol_v1::client::ServiceController;
328    /// use google_cloud_api_servicecontrol_v1::Result;
329    /// async fn sample(
330    ///    client: &ServiceController
331    /// ) -> Result<()> {
332    ///     let response = client.report()
333    ///         /* set fields */
334    ///         .send().await?;
335    ///     println!("response {:?}", response);
336    ///     Ok(())
337    /// }
338    /// ```
339    pub fn report(&self) -> super::builder::service_controller::Report {
340        super::builder::service_controller::Report::new(self.inner.clone())
341    }
342}