google_cloud_vpcaccess_v1/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 Serverless VPC Access API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_vpcaccess_v1::client::VpcAccessService;
24/// use google_cloud_gax::paginator::ItemPaginator as _;
25/// async fn sample(
26/// parent: &str,
27/// ) -> anyhow::Result<()> {
28/// let client = VpcAccessService::builder().build().await?;
29/// let mut list = client.list_connectors()
30/// .set_parent(parent)
31/// .by_item();
32/// while let Some(item) = list.next().await.transpose()? {
33/// println!("{:?}", item);
34/// }
35/// Ok(())
36/// }
37/// ```
38///
39/// # Service Description
40///
41/// Serverless VPC Access API allows users to create and manage connectors for
42/// App Engine, Cloud Functions and Cloud Run to have internal connections to
43/// Virtual Private Cloud networks.
44///
45/// # Configuration
46///
47/// To configure `VpcAccessService` use the `with_*` methods in the type returned
48/// by [builder()][VpcAccessService::builder]. The default configuration should
49/// work for most applications. Common configuration changes include
50///
51/// * [with_endpoint()]: by default this client uses the global default endpoint
52/// (`https://vpcaccess.googleapis.com`). Applications using regional
53/// endpoints or running in restricted networks (e.g. a network configured
54/// with [Private Google Access with VPC Service Controls]) may want to
55/// override this default.
56/// * [with_credentials()]: by default this client uses
57/// [Application Default Credentials]. Applications using custom
58/// authentication may need to override this default.
59///
60/// [with_endpoint()]: super::builder::vpc_access_service::ClientBuilder::with_endpoint
61/// [with_credentials()]: super::builder::vpc_access_service::ClientBuilder::with_credentials
62/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
63/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
64///
65/// # Pooling and Cloning
66///
67/// `VpcAccessService` holds a connection pool internally, it is advised to
68/// create one and reuse it. You do not need to wrap `VpcAccessService` in
69/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
70/// already uses an `Arc` internally.
71#[derive(Clone, Debug)]
72pub struct VpcAccessService {
73 inner: std::sync::Arc<dyn super::stub::dynamic::VpcAccessService>,
74}
75
76impl VpcAccessService {
77 /// Returns a builder for [VpcAccessService].
78 ///
79 /// ```
80 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
81 /// # use google_cloud_vpcaccess_v1::client::VpcAccessService;
82 /// let client = VpcAccessService::builder().build().await?;
83 /// # Ok(()) }
84 /// ```
85 pub fn builder() -> super::builder::vpc_access_service::ClientBuilder {
86 crate::new_client_builder(super::builder::vpc_access_service::client::Factory)
87 }
88
89 /// Creates a new client from the provided stub.
90 ///
91 /// The most common case for calling this function is in tests mocking the
92 /// client's behavior.
93 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
94 where
95 T: super::stub::VpcAccessService + 'static,
96 {
97 Self { inner: stub.into() }
98 }
99
100 pub(crate) async fn new(
101 config: gaxi::options::ClientConfig,
102 ) -> crate::ClientBuilderResult<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 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::VpcAccessService>>
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 ) -> crate::ClientBuilderResult<impl super::stub::VpcAccessService> {
120 super::transport::VpcAccessService::new(conf).await
121 }
122
123 async fn build_with_tracing(
124 conf: gaxi::options::ClientConfig,
125 ) -> crate::ClientBuilderResult<impl super::stub::VpcAccessService> {
126 Self::build_transport(conf)
127 .await
128 .map(super::tracing::VpcAccessService::new)
129 }
130
131 /// Creates a Serverless VPC Access connector, returns an operation.
132 ///
133 /// # Long running operations
134 ///
135 /// This method is used to start, and/or poll a [long-running Operation].
136 /// The [Working with long-running operations] chapter in the [user guide]
137 /// covers these operations in detail.
138 ///
139 /// [long-running operation]: https://google.aip.dev/151
140 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
141 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
142 ///
143 /// # Example
144 /// ```
145 /// # use google_cloud_vpcaccess_v1::client::VpcAccessService;
146 /// use google_cloud_lro::Poller;
147 /// use google_cloud_vpcaccess_v1::model::Connector;
148 /// use google_cloud_vpcaccess_v1::Result;
149 /// async fn sample(
150 /// client: &VpcAccessService, parent: &str
151 /// ) -> Result<()> {
152 /// let response = client.create_connector()
153 /// .set_parent(parent)
154 /// .set_connector_id("connector_id_value")
155 /// .set_connector(
156 /// Connector::new()/* set fields */
157 /// )
158 /// .poller().until_done().await?;
159 /// println!("response {:?}", response);
160 /// Ok(())
161 /// }
162 /// ```
163 pub fn create_connector(&self) -> super::builder::vpc_access_service::CreateConnector {
164 super::builder::vpc_access_service::CreateConnector::new(self.inner.clone())
165 }
166
167 /// Gets a Serverless VPC Access connector. Returns NOT_FOUND if the resource
168 /// does not exist.
169 ///
170 /// # Example
171 /// ```
172 /// # use google_cloud_vpcaccess_v1::client::VpcAccessService;
173 /// use google_cloud_vpcaccess_v1::Result;
174 /// async fn sample(
175 /// client: &VpcAccessService, project_id: &str, location_id: &str, connector_id: &str
176 /// ) -> Result<()> {
177 /// let response = client.get_connector()
178 /// .set_name(format!("projects/{project_id}/locations/{location_id}/connectors/{connector_id}"))
179 /// .send().await?;
180 /// println!("response {:?}", response);
181 /// Ok(())
182 /// }
183 /// ```
184 pub fn get_connector(&self) -> super::builder::vpc_access_service::GetConnector {
185 super::builder::vpc_access_service::GetConnector::new(self.inner.clone())
186 }
187
188 /// Lists Serverless VPC Access connectors.
189 ///
190 /// # Example
191 /// ```
192 /// # use google_cloud_vpcaccess_v1::client::VpcAccessService;
193 /// use google_cloud_gax::paginator::ItemPaginator as _;
194 /// use google_cloud_vpcaccess_v1::Result;
195 /// async fn sample(
196 /// client: &VpcAccessService, parent: &str
197 /// ) -> Result<()> {
198 /// let mut list = client.list_connectors()
199 /// .set_parent(parent)
200 /// .by_item();
201 /// while let Some(item) = list.next().await.transpose()? {
202 /// println!("{:?}", item);
203 /// }
204 /// Ok(())
205 /// }
206 /// ```
207 pub fn list_connectors(&self) -> super::builder::vpc_access_service::ListConnectors {
208 super::builder::vpc_access_service::ListConnectors::new(self.inner.clone())
209 }
210
211 /// Deletes a Serverless VPC Access connector. Returns NOT_FOUND if the
212 /// resource does not exist.
213 ///
214 /// # Long running operations
215 ///
216 /// This method is used to start, and/or poll a [long-running Operation].
217 /// The [Working with long-running operations] chapter in the [user guide]
218 /// covers these operations in detail.
219 ///
220 /// [long-running operation]: https://google.aip.dev/151
221 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
222 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
223 ///
224 /// # Example
225 /// ```
226 /// # use google_cloud_vpcaccess_v1::client::VpcAccessService;
227 /// use google_cloud_lro::Poller;
228 /// use google_cloud_vpcaccess_v1::Result;
229 /// async fn sample(
230 /// client: &VpcAccessService, project_id: &str, location_id: &str, connector_id: &str
231 /// ) -> Result<()> {
232 /// client.delete_connector()
233 /// .set_name(format!("projects/{project_id}/locations/{location_id}/connectors/{connector_id}"))
234 /// .poller().until_done().await?;
235 /// Ok(())
236 /// }
237 /// ```
238 pub fn delete_connector(&self) -> super::builder::vpc_access_service::DeleteConnector {
239 super::builder::vpc_access_service::DeleteConnector::new(self.inner.clone())
240 }
241
242 /// Lists information about the supported locations for this service.
243 ///
244 /// # Example
245 /// ```
246 /// # use google_cloud_vpcaccess_v1::client::VpcAccessService;
247 /// use google_cloud_gax::paginator::ItemPaginator as _;
248 /// use google_cloud_vpcaccess_v1::Result;
249 /// async fn sample(
250 /// client: &VpcAccessService
251 /// ) -> Result<()> {
252 /// let mut list = client.list_locations()
253 /// /* set fields */
254 /// .by_item();
255 /// while let Some(item) = list.next().await.transpose()? {
256 /// println!("{:?}", item);
257 /// }
258 /// Ok(())
259 /// }
260 /// ```
261 pub fn list_locations(&self) -> super::builder::vpc_access_service::ListLocations {
262 super::builder::vpc_access_service::ListLocations::new(self.inner.clone())
263 }
264
265 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
266 ///
267 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
268 ///
269 /// # Example
270 /// ```
271 /// # use google_cloud_vpcaccess_v1::client::VpcAccessService;
272 /// use google_cloud_gax::paginator::ItemPaginator as _;
273 /// use google_cloud_vpcaccess_v1::Result;
274 /// async fn sample(
275 /// client: &VpcAccessService
276 /// ) -> Result<()> {
277 /// let mut list = client.list_operations()
278 /// /* set fields */
279 /// .by_item();
280 /// while let Some(item) = list.next().await.transpose()? {
281 /// println!("{:?}", item);
282 /// }
283 /// Ok(())
284 /// }
285 /// ```
286 pub fn list_operations(&self) -> super::builder::vpc_access_service::ListOperations {
287 super::builder::vpc_access_service::ListOperations::new(self.inner.clone())
288 }
289
290 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
291 ///
292 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
293 ///
294 /// # Example
295 /// ```
296 /// # use google_cloud_vpcaccess_v1::client::VpcAccessService;
297 /// use google_cloud_vpcaccess_v1::Result;
298 /// async fn sample(
299 /// client: &VpcAccessService
300 /// ) -> Result<()> {
301 /// let response = client.get_operation()
302 /// /* set fields */
303 /// .send().await?;
304 /// println!("response {:?}", response);
305 /// Ok(())
306 /// }
307 /// ```
308 pub fn get_operation(&self) -> super::builder::vpc_access_service::GetOperation {
309 super::builder::vpc_access_service::GetOperation::new(self.inner.clone())
310 }
311}