google_cloud_bigquery_connection_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 BigQuery Connection API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_bigquery_connection_v1::client::ConnectionService;
24/// use google_cloud_gax::paginator::ItemPaginator as _;
25/// # async fn sample() -> Result<(), Box<dyn std::error::Error>> {
26/// let client = ConnectionService::builder().build().await?;
27/// let parent = "parent_value";
28/// let mut list = client.list_connections()
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/// Manages external data source connections and credentials.
40///
41/// # Configuration
42///
43/// To configure `ConnectionService` use the `with_*` methods in the type returned
44/// by [builder()][ConnectionService::builder]. The default configuration should
45/// work for most applications. Common configuration changes include
46///
47/// * [with_endpoint()]: by default this client uses the global default endpoint
48/// (`https://bigqueryconnection.googleapis.com`). Applications using regional
49/// endpoints or running in restricted networks (e.g. a network configured
50// with [Private Google Access with VPC Service Controls]) may want to
51/// override this default.
52/// * [with_credentials()]: by default this client uses
53/// [Application Default Credentials]. Applications using custom
54/// authentication may need to override this default.
55///
56/// [with_endpoint()]: super::builder::connection_service::ClientBuilder::with_endpoint
57/// [with_credentials()]: super::builder::connection_service::ClientBuilder::with_credentials
58/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
59/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
60///
61/// # Pooling and Cloning
62///
63/// `ConnectionService` holds a connection pool internally, it is advised to
64/// create one and reuse it. You do not need to wrap `ConnectionService` in
65/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
66/// already uses an `Arc` internally.
67#[derive(Clone, Debug)]
68pub struct ConnectionService {
69 inner: std::sync::Arc<dyn super::stub::dynamic::ConnectionService>,
70}
71
72impl ConnectionService {
73 /// Returns a builder for [ConnectionService].
74 ///
75 /// ```
76 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
77 /// # use google_cloud_bigquery_connection_v1::client::ConnectionService;
78 /// let client = ConnectionService::builder().build().await?;
79 /// # Ok(()) }
80 /// ```
81 pub fn builder() -> super::builder::connection_service::ClientBuilder {
82 crate::new_client_builder(super::builder::connection_service::client::Factory)
83 }
84
85 /// Creates a new client from the provided stub.
86 ///
87 /// The most common case for calling this function is in tests mocking the
88 /// client's behavior.
89 pub fn from_stub<T>(stub: T) -> Self
90 where
91 T: super::stub::ConnectionService + 'static,
92 {
93 Self {
94 inner: std::sync::Arc::new(stub),
95 }
96 }
97
98 pub(crate) async fn new(
99 config: gaxi::options::ClientConfig,
100 ) -> crate::ClientBuilderResult<Self> {
101 let inner = Self::build_inner(config).await?;
102 Ok(Self { inner })
103 }
104
105 async fn build_inner(
106 conf: gaxi::options::ClientConfig,
107 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::ConnectionService>>
108 {
109 if gaxi::options::tracing_enabled(&conf) {
110 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
111 }
112 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
113 }
114
115 async fn build_transport(
116 conf: gaxi::options::ClientConfig,
117 ) -> crate::ClientBuilderResult<impl super::stub::ConnectionService> {
118 super::transport::ConnectionService::new(conf).await
119 }
120
121 async fn build_with_tracing(
122 conf: gaxi::options::ClientConfig,
123 ) -> crate::ClientBuilderResult<impl super::stub::ConnectionService> {
124 Self::build_transport(conf)
125 .await
126 .map(super::tracing::ConnectionService::new)
127 }
128
129 /// Creates a new connection.
130 ///
131 /// # Example
132 /// ```
133 /// # use google_cloud_bigquery_connection_v1::client::ConnectionService;
134 /// use google_cloud_bigquery_connection_v1::model::Connection;
135 /// use google_cloud_bigquery_connection_v1::Result;
136 /// async fn sample(
137 /// client: &ConnectionService, parent: &str
138 /// ) -> Result<()> {
139 /// let response = client.create_connection()
140 /// .set_parent(parent)
141 /// .set_connection_id("connection_id_value")
142 /// .set_connection(
143 /// Connection::new()/* set fields */
144 /// )
145 /// .send().await?;
146 /// println!("response {:?}", response);
147 /// Ok(())
148 /// }
149 /// ```
150 pub fn create_connection(&self) -> super::builder::connection_service::CreateConnection {
151 super::builder::connection_service::CreateConnection::new(self.inner.clone())
152 }
153
154 /// Returns specified connection.
155 ///
156 /// # Example
157 /// ```
158 /// # use google_cloud_bigquery_connection_v1::client::ConnectionService;
159 /// use google_cloud_bigquery_connection_v1::Result;
160 /// async fn sample(
161 /// client: &ConnectionService, name: &str
162 /// ) -> Result<()> {
163 /// let response = client.get_connection()
164 /// .set_name(name)
165 /// .send().await?;
166 /// println!("response {:?}", response);
167 /// Ok(())
168 /// }
169 /// ```
170 pub fn get_connection(&self) -> super::builder::connection_service::GetConnection {
171 super::builder::connection_service::GetConnection::new(self.inner.clone())
172 }
173
174 /// Returns a list of connections in the given project.
175 ///
176 /// # Example
177 /// ```
178 /// # use google_cloud_bigquery_connection_v1::client::ConnectionService;
179 /// use google_cloud_gax::paginator::ItemPaginator as _;
180 /// use google_cloud_bigquery_connection_v1::Result;
181 /// async fn sample(
182 /// client: &ConnectionService, parent: &str
183 /// ) -> Result<()> {
184 /// let mut list = client.list_connections()
185 /// .set_parent(parent)
186 /// .by_item();
187 /// while let Some(item) = list.next().await.transpose()? {
188 /// println!("{:?}", item);
189 /// }
190 /// Ok(())
191 /// }
192 /// ```
193 pub fn list_connections(&self) -> super::builder::connection_service::ListConnections {
194 super::builder::connection_service::ListConnections::new(self.inner.clone())
195 }
196
197 /// Updates the specified connection. For security reasons, also resets
198 /// credential if connection properties are in the update field mask.
199 ///
200 /// # Example
201 /// ```
202 /// # use google_cloud_bigquery_connection_v1::client::ConnectionService;
203 /// # extern crate wkt as google_cloud_wkt;
204 /// use google_cloud_wkt::FieldMask;
205 /// use google_cloud_bigquery_connection_v1::model::Connection;
206 /// use google_cloud_bigquery_connection_v1::Result;
207 /// async fn sample(
208 /// client: &ConnectionService, name: &str
209 /// ) -> Result<()> {
210 /// let response = client.update_connection()
211 /// .set_connection(
212 /// Connection::new().set_name(name)/* set fields */
213 /// )
214 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
215 /// .send().await?;
216 /// println!("response {:?}", response);
217 /// Ok(())
218 /// }
219 /// ```
220 pub fn update_connection(&self) -> super::builder::connection_service::UpdateConnection {
221 super::builder::connection_service::UpdateConnection::new(self.inner.clone())
222 }
223
224 /// Deletes connection and associated credential.
225 ///
226 /// # Example
227 /// ```
228 /// # use google_cloud_bigquery_connection_v1::client::ConnectionService;
229 /// use google_cloud_bigquery_connection_v1::Result;
230 /// async fn sample(
231 /// client: &ConnectionService, name: &str
232 /// ) -> Result<()> {
233 /// client.delete_connection()
234 /// .set_name(name)
235 /// .send().await?;
236 /// Ok(())
237 /// }
238 /// ```
239 pub fn delete_connection(&self) -> super::builder::connection_service::DeleteConnection {
240 super::builder::connection_service::DeleteConnection::new(self.inner.clone())
241 }
242
243 /// Gets the access control policy for a resource.
244 /// Returns an empty policy if the resource exists and does not have a policy
245 /// set.
246 ///
247 /// # Example
248 /// ```
249 /// # use google_cloud_bigquery_connection_v1::client::ConnectionService;
250 /// use google_cloud_bigquery_connection_v1::Result;
251 /// async fn sample(
252 /// client: &ConnectionService
253 /// ) -> Result<()> {
254 /// let response = client.get_iam_policy()
255 /// /* set fields */
256 /// .send().await?;
257 /// println!("response {:?}", response);
258 /// Ok(())
259 /// }
260 /// ```
261 pub fn get_iam_policy(&self) -> super::builder::connection_service::GetIamPolicy {
262 super::builder::connection_service::GetIamPolicy::new(self.inner.clone())
263 }
264
265 /// Sets the access control policy on the specified resource. Replaces any
266 /// existing policy.
267 ///
268 /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors.
269 ///
270 /// # Example
271 /// ```
272 /// # use google_cloud_bigquery_connection_v1::client::ConnectionService;
273 /// use google_cloud_bigquery_connection_v1::Result;
274 /// async fn sample(
275 /// client: &ConnectionService
276 /// ) -> Result<()> {
277 /// let response = client.set_iam_policy()
278 /// /* set fields */
279 /// .send().await?;
280 /// println!("response {:?}", response);
281 /// Ok(())
282 /// }
283 /// ```
284 pub fn set_iam_policy(&self) -> super::builder::connection_service::SetIamPolicy {
285 super::builder::connection_service::SetIamPolicy::new(self.inner.clone())
286 }
287
288 /// Returns permissions that a caller has on the specified resource.
289 /// If the resource does not exist, this will return an empty set of
290 /// permissions, not a `NOT_FOUND` error.
291 ///
292 /// Note: This operation is designed to be used for building permission-aware
293 /// UIs and command-line tools, not for authorization checking. This operation
294 /// may "fail open" without warning.
295 ///
296 /// # Example
297 /// ```
298 /// # use google_cloud_bigquery_connection_v1::client::ConnectionService;
299 /// use google_cloud_bigquery_connection_v1::Result;
300 /// async fn sample(
301 /// client: &ConnectionService
302 /// ) -> Result<()> {
303 /// let response = client.test_iam_permissions()
304 /// /* set fields */
305 /// .send().await?;
306 /// println!("response {:?}", response);
307 /// Ok(())
308 /// }
309 /// ```
310 pub fn test_iam_permissions(&self) -> super::builder::connection_service::TestIamPermissions {
311 super::builder::connection_service::TestIamPermissions::new(self.inner.clone())
312 }
313}