Skip to main content

google_cloud_api_servicecontrol_v2/
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_v2::client::ServiceController;
25/// let client = ServiceController::builder().build().await?;
26/// // use `client` to make requests to the Service Control API.
27/// # Ok(()) }
28/// ```
29///
30/// # Service Description
31///
32/// [Service Control API
33/// v2](https://cloud.google.com/service-infrastructure/docs/service-control/access-control)
34///
35/// This API provides admission control and telemetry reporting for services
36/// that are integrated with [Service
37/// Infrastructure](https://cloud.google.com/service-infrastructure).
38///
39/// # Configuration
40///
41/// To configure `ServiceController` use the `with_*` methods in the type returned
42/// by [builder()][ServiceController::builder]. The default configuration should
43/// work for most applications. Common configuration changes include
44///
45/// * [with_endpoint()]: by default this client uses the global default endpoint
46///   (`https://servicecontrol.googleapis.com`). Applications using regional
47///   endpoints or running in restricted networks (e.g. a network configured
48//    with [Private Google Access with VPC Service Controls]) may want to
49///   override this default.
50/// * [with_credentials()]: by default this client uses
51///   [Application Default Credentials]. Applications using custom
52///   authentication may need to override this default.
53///
54/// [with_endpoint()]: super::builder::service_controller::ClientBuilder::with_endpoint
55/// [with_credentials()]: super::builder::service_controller::ClientBuilder::credentials
56/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
57/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
58///
59/// # Pooling and Cloning
60///
61/// `ServiceController` holds a connection pool internally, it is advised to
62/// create one and the reuse it.  You do not need to wrap `ServiceController` in
63/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
64/// already uses an `Arc` internally.
65#[derive(Clone, Debug)]
66pub struct ServiceController {
67    inner: std::sync::Arc<dyn super::stub::dynamic::ServiceController>,
68}
69
70impl ServiceController {
71    /// Returns a builder for [ServiceController].
72    ///
73    /// ```
74    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
75    /// # use google_cloud_api_servicecontrol_v2::client::ServiceController;
76    /// let client = ServiceController::builder().build().await?;
77    /// # Ok(()) }
78    /// ```
79    pub fn builder() -> super::builder::service_controller::ClientBuilder {
80        crate::new_client_builder(super::builder::service_controller::client::Factory)
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::ServiceController + '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    ) -> crate::ClientBuilderResult<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    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::ServiceController>>
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    ) -> crate::ClientBuilderResult<impl super::stub::ServiceController> {
116        super::transport::ServiceController::new(conf).await
117    }
118
119    async fn build_with_tracing(
120        conf: gaxi::options::ClientConfig,
121    ) -> crate::ClientBuilderResult<impl super::stub::ServiceController> {
122        Self::build_transport(conf)
123            .await
124            .map(super::tracing::ServiceController::new)
125    }
126
127    /// This method provides admission control for services that are integrated
128    /// with [Service
129    /// Infrastructure](https://cloud.google.com/service-infrastructure). It checks
130    /// whether an operation should be allowed based on the service configuration
131    /// and relevant policies. It must be called before the operation is executed.
132    /// For more information, see
133    /// [Admission
134    /// Control](https://cloud.google.com/service-infrastructure/docs/admission-control).
135    ///
136    /// NOTE: The admission control has an expected policy propagation delay of
137    /// 60s. The caller **must** not depend on the most recent policy changes.
138    ///
139    /// NOTE: The admission control has a hard limit of 1 referenced resources
140    /// per call. If an operation refers to more than 1 resources, the caller
141    /// must call the Check method multiple times.
142    ///
143    /// This method requires the `servicemanagement.services.check` permission
144    /// on the specified service. For more information, see
145    /// [Service Control API Access
146    /// Control](https://cloud.google.com/service-infrastructure/docs/service-control/access-control).
147    pub fn check(&self) -> super::builder::service_controller::Check {
148        super::builder::service_controller::Check::new(self.inner.clone())
149    }
150
151    /// This method provides telemetry reporting for services that are integrated
152    /// with [Service
153    /// Infrastructure](https://cloud.google.com/service-infrastructure). It
154    /// reports a list of operations that have occurred on a service. It must be
155    /// called after the operations have been executed. For more information, see
156    /// [Telemetry
157    /// Reporting](https://cloud.google.com/service-infrastructure/docs/telemetry-reporting).
158    ///
159    /// NOTE: The telemetry reporting has a hard limit of 100 operations and 1MB
160    /// per Report call.
161    ///
162    /// This method requires the `servicemanagement.services.report` permission
163    /// on the specified service. For more information, see
164    /// [Service Control API Access
165    /// Control](https://cloud.google.com/service-infrastructure/docs/service-control/access-control).
166    pub fn report(&self) -> super::builder::service_controller::Report {
167        super::builder::service_controller::Report::new(self.inner.clone())
168    }
169}