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