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