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::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() -> Result<(), Box<dyn std::error::Error>> {
26///     let client = VpcAccessService::builder().build().await?;
27///     let parent = "parent_value";
28///     let mut list = client.list_connectors()
29///         .set_parent(parent)
30///         .by_item();
31///     while let Some(item) = list.next().await.transpose()? {
32///         println!("{:?}", item);
33///     }
34/// # Ok(()) }
35/// ```
36///
37/// # Service Description
38///
39/// Serverless VPC Access API allows users to create and manage connectors for
40/// App Engine, Cloud Functions and Cloud Run to have internal connections to
41/// Virtual Private Cloud networks.
42///
43/// # Configuration
44///
45/// To configure `VpcAccessService` use the `with_*` methods in the type returned
46/// by [builder()][VpcAccessService::builder]. The default configuration should
47/// work for most applications. Common configuration changes include
48///
49/// * [with_endpoint()]: by default this client uses the global default endpoint
50///   (`https://vpcaccess.googleapis.com`). Applications using regional
51///   endpoints or running in restricted networks (e.g. a network configured
52//    with [Private Google Access with VPC Service Controls]) may want to
53///   override this default.
54/// * [with_credentials()]: by default this client uses
55///   [Application Default Credentials]. Applications using custom
56///   authentication may need to override this default.
57///
58/// [with_endpoint()]: super::builder::vpc_access_service::ClientBuilder::with_endpoint
59/// [with_credentials()]: super::builder::vpc_access_service::ClientBuilder::with_credentials
60/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
61/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
62///
63/// # Pooling and Cloning
64///
65/// `VpcAccessService` holds a connection pool internally, it is advised to
66/// create one and reuse it. You do not need to wrap `VpcAccessService` in
67/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
68/// already uses an `Arc` internally.
69#[derive(Clone, Debug)]
70pub struct VpcAccessService {
71    inner: std::sync::Arc<dyn super::stub::dynamic::VpcAccessService>,
72}
73
74impl VpcAccessService {
75    /// Returns a builder for [VpcAccessService].
76    ///
77    /// ```
78    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
79    /// # use google_cloud_vpcaccess_v1::client::VpcAccessService;
80    /// let client = VpcAccessService::builder().build().await?;
81    /// # Ok(()) }
82    /// ```
83    pub fn builder() -> super::builder::vpc_access_service::ClientBuilder {
84        crate::new_client_builder(super::builder::vpc_access_service::client::Factory)
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::VpcAccessService + '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    ) -> 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, name: &str
176    /// ) -> Result<()> {
177    ///     let response = client.get_connector()
178    ///         .set_name(name)
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, name: &str
231    /// ) -> Result<()> {
232    ///     client.delete_connector()
233    ///         .set_name(name)
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}