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/// Private Preview. This feature is only available for approved services.
36///
37/// This API provides admission control and telemetry reporting for services
38/// that are integrated with [Service
39/// Infrastructure](https://cloud.google.com/service-infrastructure).
40///
41/// # Configuration
42///
43/// To configure `ServiceController` use the `with_*` methods in the type returned
44/// by [builder()][ServiceController::builder]. The default configuration should
45/// work for most applications. Common configuration changes include
46///
47/// * [with_endpoint()]: by default this client uses the global default endpoint
48///   (`https://servicecontrol.googleapis.com`). Applications using regional
49///   endpoints or running in restricted networks (e.g. a network configured
50//    with [Private Google Access with VPC Service Controls]) may want to
51///   override this default.
52/// * [with_credentials()]: by default this client uses
53///   [Application Default Credentials]. Applications using custom
54///   authentication may need to override this default.
55///
56/// [with_endpoint()]: super::builder::service_controller::ClientBuilder::with_endpoint
57/// [with_credentials()]: super::builder::service_controller::ClientBuilder::credentials
58/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
59/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
60///
61/// # Pooling and Cloning
62///
63/// `ServiceController` holds a connection pool internally, it is advised to
64/// create one and the reuse it.  You do not need to wrap `ServiceController` in
65/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
66/// already uses an `Arc` internally.
67#[derive(Clone, Debug)]
68pub struct ServiceController {
69    inner: std::sync::Arc<dyn super::stub::dynamic::ServiceController>,
70}
71
72impl ServiceController {
73    /// Returns a builder for [ServiceController].
74    ///
75    /// ```
76    /// # tokio_test::block_on(async {
77    /// # use google_cloud_api_servicecontrol_v2::client::ServiceController;
78    /// let client = ServiceController::builder().build().await?;
79    /// # gax::client_builder::Result::<()>::Ok(()) });
80    /// ```
81    pub fn builder() -> super::builder::service_controller::ClientBuilder {
82        gax::client_builder::internal::new_builder(
83            super::builder::service_controller::client::Factory,
84        )
85    }
86
87    /// Creates a new client from the provided stub.
88    ///
89    /// The most common case for calling this function is in tests mocking the
90    /// client's behavior.
91    pub fn from_stub<T>(stub: T) -> Self
92    where
93        T: super::stub::ServiceController + 'static,
94    {
95        Self {
96            inner: std::sync::Arc::new(stub),
97        }
98    }
99
100    pub(crate) async fn new(
101        config: gaxi::options::ClientConfig,
102    ) -> gax::client_builder::Result<Self> {
103        let inner = Self::build_inner(config).await?;
104        Ok(Self { inner })
105    }
106
107    async fn build_inner(
108        conf: gaxi::options::ClientConfig,
109    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::ServiceController>>
110    {
111        if gaxi::options::tracing_enabled(&conf) {
112            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
113        }
114        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
115    }
116
117    async fn build_transport(
118        conf: gaxi::options::ClientConfig,
119    ) -> gax::client_builder::Result<impl super::stub::ServiceController> {
120        super::transport::ServiceController::new(conf).await
121    }
122
123    async fn build_with_tracing(
124        conf: gaxi::options::ClientConfig,
125    ) -> gax::client_builder::Result<impl super::stub::ServiceController> {
126        Self::build_transport(conf)
127            .await
128            .map(super::tracing::ServiceController::new)
129    }
130
131    /// Private Preview. This feature is only available for approved services.
132    ///
133    /// This method provides admission control for services that are integrated
134    /// with [Service
135    /// Infrastructure](https://cloud.google.com/service-infrastructure). It checks
136    /// whether an operation should be allowed based on the service configuration
137    /// and relevant policies. It must be called before the operation is executed.
138    /// For more information, see
139    /// [Admission
140    /// Control](https://cloud.google.com/service-infrastructure/docs/admission-control).
141    ///
142    /// NOTE: The admission control has an expected policy propagation delay of
143    /// 60s. The caller **must** not depend on the most recent policy changes.
144    ///
145    /// NOTE: The admission control has a hard limit of 1 referenced resources
146    /// per call. If an operation refers to more than 1 resources, the caller
147    /// must call the Check method multiple times.
148    ///
149    /// This method requires the `servicemanagement.services.check` permission
150    /// on the specified service. For more information, see
151    /// [Service Control API Access
152    /// Control](https://cloud.google.com/service-infrastructure/docs/service-control/access-control).
153    pub fn check(&self) -> super::builder::service_controller::Check {
154        super::builder::service_controller::Check::new(self.inner.clone())
155    }
156
157    /// Private Preview. This feature is only available for approved services.
158    ///
159    /// This method provides telemetry reporting for services that are integrated
160    /// with [Service
161    /// Infrastructure](https://cloud.google.com/service-infrastructure). It
162    /// reports a list of operations that have occurred on a service. It must be
163    /// called after the operations have been executed. For more information, see
164    /// [Telemetry
165    /// Reporting](https://cloud.google.com/service-infrastructure/docs/telemetry-reporting).
166    ///
167    /// NOTE: The telemetry reporting has a hard limit of 1000 operations and 1MB
168    /// per Report call. It is recommended to have no more than 100 operations per
169    /// call.
170    ///
171    /// This method requires the `servicemanagement.services.report` permission
172    /// on the specified service. For more information, see
173    /// [Service Control API Access
174    /// Control](https://cloud.google.com/service-infrastructure/docs/service-control/access-control).
175    pub fn report(&self) -> super::builder::service_controller::Report {
176        super::builder::service_controller::Report::new(self.inner.clone())
177    }
178}