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/// # tokio_test::block_on(async {
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/// # gax::client_builder::Result::<()>::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    /// # tokio_test::block_on(async {
75    /// # use google_cloud_api_servicecontrol_v2::client::ServiceController;
76    /// let client = ServiceController::builder().build().await?;
77    /// # gax::client_builder::Result::<()>::Ok(()) });
78    /// ```
79    pub fn builder() -> super::builder::service_controller::ClientBuilder {
80        gax::client_builder::internal::new_builder(
81            super::builder::service_controller::client::Factory,
82        )
83    }
84
85    /// Creates a new client from the provided stub.
86    ///
87    /// The most common case for calling this function is in tests mocking the
88    /// client's behavior.
89    pub fn from_stub<T>(stub: T) -> Self
90    where
91        T: super::stub::ServiceController + 'static,
92    {
93        Self {
94            inner: std::sync::Arc::new(stub),
95        }
96    }
97
98    pub(crate) async fn new(
99        config: gaxi::options::ClientConfig,
100    ) -> gax::client_builder::Result<Self> {
101        let inner = Self::build_inner(config).await?;
102        Ok(Self { inner })
103    }
104
105    async fn build_inner(
106        conf: gaxi::options::ClientConfig,
107    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::ServiceController>>
108    {
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    ) -> gax::client_builder::Result<impl super::stub::ServiceController> {
118        super::transport::ServiceController::new(conf).await
119    }
120
121    async fn build_with_tracing(
122        conf: gaxi::options::ClientConfig,
123    ) -> gax::client_builder::Result<impl super::stub::ServiceController> {
124        Self::build_transport(conf)
125            .await
126            .map(super::tracing::ServiceController::new)
127    }
128
129    /// This method provides admission control for services that are integrated
130    /// with [Service
131    /// Infrastructure](https://cloud.google.com/service-infrastructure). It checks
132    /// whether an operation should be allowed based on the service configuration
133    /// and relevant policies. It must be called before the operation is executed.
134    /// For more information, see
135    /// [Admission
136    /// Control](https://cloud.google.com/service-infrastructure/docs/admission-control).
137    ///
138    /// NOTE: The admission control has an expected policy propagation delay of
139    /// 60s. The caller **must** not depend on the most recent policy changes.
140    ///
141    /// NOTE: The admission control has a hard limit of 1 referenced resources
142    /// per call. If an operation refers to more than 1 resources, the caller
143    /// must call the Check method multiple times.
144    ///
145    /// This method requires the `servicemanagement.services.check` permission
146    /// on the specified service. For more information, see
147    /// [Service Control API Access
148    /// Control](https://cloud.google.com/service-infrastructure/docs/service-control/access-control).
149    pub fn check(&self) -> super::builder::service_controller::Check {
150        super::builder::service_controller::Check::new(self.inner.clone())
151    }
152
153    /// This method provides telemetry reporting for services that are integrated
154    /// with [Service
155    /// Infrastructure](https://cloud.google.com/service-infrastructure). It
156    /// reports a list of operations that have occurred on a service. It must be
157    /// called after the operations have been executed. For more information, see
158    /// [Telemetry
159    /// Reporting](https://cloud.google.com/service-infrastructure/docs/telemetry-reporting).
160    ///
161    /// NOTE: The telemetry reporting has a hard limit of 100 operations and 1MB
162    /// per Report call.
163    ///
164    /// This method requires the `servicemanagement.services.report` permission
165    /// on the specified service. For more information, see
166    /// [Service Control API Access
167    /// Control](https://cloud.google.com/service-infrastructure/docs/service-control/access-control).
168    pub fn report(&self) -> super::builder::service_controller::Report {
169        super::builder::service_controller::Report::new(self.inner.clone())
170    }
171}