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/// # tokio_test::block_on(async {
24/// # use google_cloud_bigquery_connection_v1::client::ConnectionService;
25/// let client = ConnectionService::builder().build().await?;
26/// // use `client` to make requests to the BigQuery Connection API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Manages external data source connections and credentials.
33///
34/// # Configuration
35///
36/// To configure `ConnectionService` use the `with_*` methods in the type returned
37/// by [builder()][ConnectionService::builder]. The default configuration should
38/// work for most applications. Common configuration changes include
39///
40/// * [with_endpoint()]: by default this client uses the global default endpoint
41/// (`https://bigqueryconnection.googleapis.com`). Applications using regional
42/// endpoints or running in restricted networks (e.g. a network configured
43// with [Private Google Access with VPC Service Controls]) may want to
44/// override this default.
45/// * [with_credentials()]: by default this client uses
46/// [Application Default Credentials]. Applications using custom
47/// authentication may need to override this default.
48///
49/// [with_endpoint()]: super::builder::connection_service::ClientBuilder::with_endpoint
50/// [with_credentials()]: super::builder::connection_service::ClientBuilder::credentials
51/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
52/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
53///
54/// # Pooling and Cloning
55///
56/// `ConnectionService` holds a connection pool internally, it is advised to
57/// create one and the reuse it. You do not need to wrap `ConnectionService` in
58/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
59/// already uses an `Arc` internally.
60#[derive(Clone, Debug)]
61pub struct ConnectionService {
62 inner: std::sync::Arc<dyn super::stub::dynamic::ConnectionService>,
63}
64
65impl ConnectionService {
66 /// Returns a builder for [ConnectionService].
67 ///
68 /// ```
69 /// # tokio_test::block_on(async {
70 /// # use google_cloud_bigquery_connection_v1::client::ConnectionService;
71 /// let client = ConnectionService::builder().build().await?;
72 /// # gax::client_builder::Result::<()>::Ok(()) });
73 /// ```
74 pub fn builder() -> super::builder::connection_service::ClientBuilder {
75 gax::client_builder::internal::new_builder(
76 super::builder::connection_service::client::Factory,
77 )
78 }
79
80 /// Creates a new client from the provided stub.
81 ///
82 /// The most common case for calling this function is in tests mocking the
83 /// client's behavior.
84 pub fn from_stub<T>(stub: T) -> Self
85 where
86 T: super::stub::ConnectionService + 'static,
87 {
88 Self {
89 inner: std::sync::Arc::new(stub),
90 }
91 }
92
93 pub(crate) async fn new(
94 config: gaxi::options::ClientConfig,
95 ) -> gax::client_builder::Result<Self> {
96 let inner = Self::build_inner(config).await?;
97 Ok(Self { inner })
98 }
99
100 async fn build_inner(
101 conf: gaxi::options::ClientConfig,
102 ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::ConnectionService>>
103 {
104 if gaxi::options::tracing_enabled(&conf) {
105 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
106 }
107 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
108 }
109
110 async fn build_transport(
111 conf: gaxi::options::ClientConfig,
112 ) -> gax::client_builder::Result<impl super::stub::ConnectionService> {
113 super::transport::ConnectionService::new(conf).await
114 }
115
116 async fn build_with_tracing(
117 conf: gaxi::options::ClientConfig,
118 ) -> gax::client_builder::Result<impl super::stub::ConnectionService> {
119 Self::build_transport(conf)
120 .await
121 .map(super::tracing::ConnectionService::new)
122 }
123
124 /// Creates a new connection.
125 pub fn create_connection(&self) -> super::builder::connection_service::CreateConnection {
126 super::builder::connection_service::CreateConnection::new(self.inner.clone())
127 }
128
129 /// Returns specified connection.
130 pub fn get_connection(&self) -> super::builder::connection_service::GetConnection {
131 super::builder::connection_service::GetConnection::new(self.inner.clone())
132 }
133
134 /// Returns a list of connections in the given project.
135 pub fn list_connections(&self) -> super::builder::connection_service::ListConnections {
136 super::builder::connection_service::ListConnections::new(self.inner.clone())
137 }
138
139 /// Updates the specified connection. For security reasons, also resets
140 /// credential if connection properties are in the update field mask.
141 pub fn update_connection(&self) -> super::builder::connection_service::UpdateConnection {
142 super::builder::connection_service::UpdateConnection::new(self.inner.clone())
143 }
144
145 /// Deletes connection and associated credential.
146 pub fn delete_connection(&self) -> super::builder::connection_service::DeleteConnection {
147 super::builder::connection_service::DeleteConnection::new(self.inner.clone())
148 }
149
150 /// Gets the access control policy for a resource.
151 /// Returns an empty policy if the resource exists and does not have a policy
152 /// set.
153 pub fn get_iam_policy(&self) -> super::builder::connection_service::GetIamPolicy {
154 super::builder::connection_service::GetIamPolicy::new(self.inner.clone())
155 }
156
157 /// Sets the access control policy on the specified resource. Replaces any
158 /// existing policy.
159 ///
160 /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors.
161 pub fn set_iam_policy(&self) -> super::builder::connection_service::SetIamPolicy {
162 super::builder::connection_service::SetIamPolicy::new(self.inner.clone())
163 }
164
165 /// Returns permissions that a caller has on the specified resource.
166 /// If the resource does not exist, this will return an empty set of
167 /// permissions, not a `NOT_FOUND` error.
168 ///
169 /// Note: This operation is designed to be used for building permission-aware
170 /// UIs and command-line tools, not for authorization checking. This operation
171 /// may "fail open" without warning.
172 pub fn test_iam_permissions(&self) -> super::builder::connection_service::TestIamPermissions {
173 super::builder::connection_service::TestIamPermissions::new(self.inner.clone())
174 }
175}