Skip to main content

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