google_cloud_build_v2/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
19use crate::Result;
20use std::sync::Arc;
21
22/// Implements a client for the Cloud Build API.
23///
24/// # Example
25/// ```
26/// # tokio_test::block_on(async {
27/// # use google_cloud_build_v2::client::RepositoryManager;
28/// let client = RepositoryManager::builder().build().await?;
29/// // use `client` to make requests to the {Codec.APITitle}}.
30/// # gax::Result::<()>::Ok(()) });
31/// ```
32///
33/// # Service Description
34///
35/// Manages connections to source code repositories.
36///
37/// # Configuration
38///
39/// To configure `RepositoryManager` use the `with_*` methods in the type returned
40/// by [builder()][RepositoryManager::builder]. The default configuration should
41/// work for most applications. Common configuration changes include
42///
43/// * [with_endpoint()]: by default this client uses the global default endpoint
44/// (`https://cloudbuild.googleapis.com`). Applications using regional
45/// endpoints or running in restricted networks (e.g. a network configured
46// with [Private Google Access with VPC Service Controls]) may want to
47/// override this default.
48/// * [with_credentials()]: by default this client uses
49/// [Application Default Credentials]. Applications using custom
50/// authentication may need to override this default.
51///
52/// [with_endpoint()]: super::builder::repository_manager::ClientBuilder::with_endpoint
53/// [with_credentials()]: super::builder::repository_manager::ClientBuilder::credentials
54/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
55/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
56///
57/// # Pooling and Cloning
58///
59/// `RepositoryManager` holds a connection pool internally, it is advised to
60/// create one and the reuse it. You do not need to wrap `RepositoryManager` in
61/// an [Rc](std::rc::Rc) or [Arc] to reuse it, because it already uses an `Arc`
62/// internally.
63#[derive(Clone, Debug)]
64pub struct RepositoryManager {
65 inner: Arc<dyn super::stub::dynamic::RepositoryManager>,
66}
67
68impl RepositoryManager {
69 /// Returns a builder for [RepositoryManager].
70 ///
71 /// ```
72 /// # tokio_test::block_on(async {
73 /// # use google_cloud_build_v2::client::RepositoryManager;
74 /// let client = RepositoryManager::builder().build().await?;
75 /// # gax::Result::<()>::Ok(()) });
76 /// ```
77 pub fn builder() -> super::builder::repository_manager::ClientBuilder {
78 gax::client_builder::internal::new_builder(
79 super::builder::repository_manager::client::Factory,
80 )
81 }
82
83 /// Creates a new client from the provided stub.
84 ///
85 /// The most common case for calling this function is in tests mocking the
86 /// client's behavior.
87 pub fn from_stub<T>(stub: T) -> Self
88 where
89 T: super::stub::RepositoryManager + 'static,
90 {
91 Self {
92 inner: Arc::new(stub),
93 }
94 }
95
96 pub(crate) async fn new(config: gaxi::options::ClientConfig) -> Result<Self> {
97 let inner = Self::build_inner(config).await?;
98 Ok(Self { inner })
99 }
100
101 async fn build_inner(
102 conf: gaxi::options::ClientConfig,
103 ) -> Result<Arc<dyn super::stub::dynamic::RepositoryManager>> {
104 if gaxi::options::tracing_enabled(&conf) {
105 return Ok(Arc::new(Self::build_with_tracing(conf).await?));
106 }
107 Ok(Arc::new(Self::build_transport(conf).await?))
108 }
109
110 async fn build_transport(
111 conf: gaxi::options::ClientConfig,
112 ) -> Result<impl super::stub::RepositoryManager> {
113 super::transport::RepositoryManager::new(conf).await
114 }
115
116 async fn build_with_tracing(
117 conf: gaxi::options::ClientConfig,
118 ) -> Result<impl super::stub::RepositoryManager> {
119 Self::build_transport(conf)
120 .await
121 .map(super::tracing::RepositoryManager::new)
122 }
123
124 /// Creates a Connection.
125 ///
126 /// # Long running operations
127 ///
128 /// This method is used to start, and/or poll a [long-running Operation].
129 /// The [Working with long-running operations] chapter in the [user guide]
130 /// covers these operations in detail.
131 ///
132 /// [long-running operation]: https://google.aip.dev/151
133 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
134 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
135 pub fn create_connection(
136 &self,
137 parent: impl Into<std::string::String>,
138 ) -> super::builder::repository_manager::CreateConnection {
139 super::builder::repository_manager::CreateConnection::new(self.inner.clone())
140 .set_parent(parent.into())
141 }
142
143 /// Gets details of a single connection.
144 pub fn get_connection(
145 &self,
146 name: impl Into<std::string::String>,
147 ) -> super::builder::repository_manager::GetConnection {
148 super::builder::repository_manager::GetConnection::new(self.inner.clone())
149 .set_name(name.into())
150 }
151
152 /// Lists Connections in a given project and location.
153 pub fn list_connections(
154 &self,
155 parent: impl Into<std::string::String>,
156 ) -> super::builder::repository_manager::ListConnections {
157 super::builder::repository_manager::ListConnections::new(self.inner.clone())
158 .set_parent(parent.into())
159 }
160
161 /// Updates a single connection.
162 ///
163 /// # Long running operations
164 ///
165 /// This method is used to start, and/or poll a [long-running Operation].
166 /// The [Working with long-running operations] chapter in the [user guide]
167 /// covers these operations in detail.
168 ///
169 /// [long-running operation]: https://google.aip.dev/151
170 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
171 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
172 pub fn update_connection(
173 &self,
174 connection: impl Into<crate::model::Connection>,
175 ) -> super::builder::repository_manager::UpdateConnection {
176 super::builder::repository_manager::UpdateConnection::new(self.inner.clone())
177 .set_connection(connection.into())
178 }
179
180 /// Deletes a single connection.
181 ///
182 /// # Long running operations
183 ///
184 /// This method is used to start, and/or poll a [long-running Operation].
185 /// The [Working with long-running operations] chapter in the [user guide]
186 /// covers these operations in detail.
187 ///
188 /// [long-running operation]: https://google.aip.dev/151
189 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
190 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
191 pub fn delete_connection(
192 &self,
193 name: impl Into<std::string::String>,
194 ) -> super::builder::repository_manager::DeleteConnection {
195 super::builder::repository_manager::DeleteConnection::new(self.inner.clone())
196 .set_name(name.into())
197 }
198
199 /// Creates a Repository.
200 ///
201 /// # Long running operations
202 ///
203 /// This method is used to start, and/or poll a [long-running Operation].
204 /// The [Working with long-running operations] chapter in the [user guide]
205 /// covers these operations in detail.
206 ///
207 /// [long-running operation]: https://google.aip.dev/151
208 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
209 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
210 pub fn create_repository(
211 &self,
212 parent: impl Into<std::string::String>,
213 ) -> super::builder::repository_manager::CreateRepository {
214 super::builder::repository_manager::CreateRepository::new(self.inner.clone())
215 .set_parent(parent.into())
216 }
217
218 /// Creates multiple repositories inside a connection.
219 ///
220 /// # Long running operations
221 ///
222 /// This method is used to start, and/or poll a [long-running Operation].
223 /// The [Working with long-running operations] chapter in the [user guide]
224 /// covers these operations in detail.
225 ///
226 /// [long-running operation]: https://google.aip.dev/151
227 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
228 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
229 pub fn batch_create_repositories(
230 &self,
231 parent: impl Into<std::string::String>,
232 ) -> super::builder::repository_manager::BatchCreateRepositories {
233 super::builder::repository_manager::BatchCreateRepositories::new(self.inner.clone())
234 .set_parent(parent.into())
235 }
236
237 /// Gets details of a single repository.
238 pub fn get_repository(
239 &self,
240 name: impl Into<std::string::String>,
241 ) -> super::builder::repository_manager::GetRepository {
242 super::builder::repository_manager::GetRepository::new(self.inner.clone())
243 .set_name(name.into())
244 }
245
246 /// Lists Repositories in a given connection.
247 pub fn list_repositories(
248 &self,
249 parent: impl Into<std::string::String>,
250 ) -> super::builder::repository_manager::ListRepositories {
251 super::builder::repository_manager::ListRepositories::new(self.inner.clone())
252 .set_parent(parent.into())
253 }
254
255 /// Deletes a single repository.
256 ///
257 /// # Long running operations
258 ///
259 /// This method is used to start, and/or poll a [long-running Operation].
260 /// The [Working with long-running operations] chapter in the [user guide]
261 /// covers these operations in detail.
262 ///
263 /// [long-running operation]: https://google.aip.dev/151
264 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
265 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
266 pub fn delete_repository(
267 &self,
268 name: impl Into<std::string::String>,
269 ) -> super::builder::repository_manager::DeleteRepository {
270 super::builder::repository_manager::DeleteRepository::new(self.inner.clone())
271 .set_name(name.into())
272 }
273
274 /// Fetches read/write token of a given repository.
275 pub fn fetch_read_write_token(
276 &self,
277 repository: impl Into<std::string::String>,
278 ) -> super::builder::repository_manager::FetchReadWriteToken {
279 super::builder::repository_manager::FetchReadWriteToken::new(self.inner.clone())
280 .set_repository(repository.into())
281 }
282
283 /// Fetches read token of a given repository.
284 pub fn fetch_read_token(
285 &self,
286 repository: impl Into<std::string::String>,
287 ) -> super::builder::repository_manager::FetchReadToken {
288 super::builder::repository_manager::FetchReadToken::new(self.inner.clone())
289 .set_repository(repository.into())
290 }
291
292 /// FetchLinkableRepositories get repositories from SCM that are
293 /// accessible and could be added to the connection.
294 pub fn fetch_linkable_repositories(
295 &self,
296 connection: impl Into<std::string::String>,
297 ) -> super::builder::repository_manager::FetchLinkableRepositories {
298 super::builder::repository_manager::FetchLinkableRepositories::new(self.inner.clone())
299 .set_connection(connection.into())
300 }
301
302 /// Fetch the list of branches or tags for a given repository.
303 pub fn fetch_git_refs(
304 &self,
305 repository: impl Into<std::string::String>,
306 ) -> super::builder::repository_manager::FetchGitRefs {
307 super::builder::repository_manager::FetchGitRefs::new(self.inner.clone())
308 .set_repository(repository.into())
309 }
310
311 /// Sets the access control policy on the specified resource. Replaces
312 /// any existing policy.
313 ///
314 /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
315 /// errors.
316 pub fn set_iam_policy(
317 &self,
318 resource: impl Into<std::string::String>,
319 ) -> super::builder::repository_manager::SetIamPolicy {
320 super::builder::repository_manager::SetIamPolicy::new(self.inner.clone())
321 .set_resource(resource.into())
322 }
323
324 /// Gets the access control policy for a resource. Returns an empty policy
325 /// if the resource exists and does not have a policy set.
326 pub fn get_iam_policy(
327 &self,
328 resource: impl Into<std::string::String>,
329 ) -> super::builder::repository_manager::GetIamPolicy {
330 super::builder::repository_manager::GetIamPolicy::new(self.inner.clone())
331 .set_resource(resource.into())
332 }
333
334 /// Returns permissions that a caller has on the specified resource. If the
335 /// resource does not exist, this will return an empty set of
336 /// permissions, not a `NOT_FOUND` error.
337 ///
338 /// Note: This operation is designed to be used for building
339 /// permission-aware UIs and command-line tools, not for authorization
340 /// checking. This operation may "fail open" without warning.
341 pub fn test_iam_permissions(
342 &self,
343 resource: impl Into<std::string::String>,
344 ) -> super::builder::repository_manager::TestIamPermissions {
345 super::builder::repository_manager::TestIamPermissions::new(self.inner.clone())
346 .set_resource(resource.into())
347 }
348
349 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
350 ///
351 /// [google.longrunning.Operations]: longrunning::client::Operations
352 pub fn get_operation(
353 &self,
354 name: impl Into<std::string::String>,
355 ) -> super::builder::repository_manager::GetOperation {
356 super::builder::repository_manager::GetOperation::new(self.inner.clone())
357 .set_name(name.into())
358 }
359
360 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
361 ///
362 /// [google.longrunning.Operations]: longrunning::client::Operations
363 pub fn cancel_operation(
364 &self,
365 name: impl Into<std::string::String>,
366 ) -> super::builder::repository_manager::CancelOperation {
367 super::builder::repository_manager::CancelOperation::new(self.inner.clone())
368 .set_name(name.into())
369 }
370}