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::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 Cloud Build API.
22///
23/// # Example
24/// ```
25/// # use google_cloud_build_v2::client::RepositoryManager;
26/// use google_cloud_gax::paginator::ItemPaginator as _;
27/// async fn sample(
28/// project_id: &str,
29/// location_id: &str,
30/// ) -> anyhow::Result<()> {
31/// let client = RepositoryManager::builder().build().await?;
32/// let mut list = client.list_connections()
33/// .set_parent(format!("projects/{project_id}/locations/{location_id}"))
34/// .by_item();
35/// while let Some(item) = list.next().await.transpose()? {
36/// println!("{:?}", item);
37/// }
38/// Ok(())
39/// }
40/// ```
41///
42/// # Service Description
43///
44/// Manages connections to source code repositories.
45///
46/// # Configuration
47///
48/// To configure `RepositoryManager` use the `with_*` methods in the type returned
49/// by [builder()][RepositoryManager::builder]. The default configuration should
50/// work for most applications. Common configuration changes include
51///
52/// * [with_endpoint()]: by default this client uses the global default endpoint
53/// (`https://cloudbuild.googleapis.com`). Applications using regional
54/// endpoints or running in restricted networks (e.g. a network configured
55/// with [Private Google Access with VPC Service Controls]) may want to
56/// override this default.
57/// * [with_credentials()]: by default this client uses
58/// [Application Default Credentials]. Applications using custom
59/// authentication may need to override this default.
60///
61/// [with_endpoint()]: super::builder::repository_manager::ClientBuilder::with_endpoint
62/// [with_credentials()]: super::builder::repository_manager::ClientBuilder::with_credentials
63/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
64/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
65///
66/// # Pooling and Cloning
67///
68/// `RepositoryManager` holds a connection pool internally, it is advised to
69/// create one and reuse it. You do not need to wrap `RepositoryManager` in
70/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
71/// already uses an `Arc` internally.
72#[derive(Clone, Debug)]
73pub struct RepositoryManager {
74 inner: std::sync::Arc<dyn super::stub::dynamic::RepositoryManager>,
75}
76
77impl RepositoryManager {
78 /// Returns a builder for [RepositoryManager].
79 ///
80 /// ```
81 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
82 /// # use google_cloud_build_v2::client::RepositoryManager;
83 /// let client = RepositoryManager::builder().build().await?;
84 /// # Ok(()) }
85 /// ```
86 pub fn builder() -> super::builder::repository_manager::ClientBuilder {
87 crate::new_client_builder(super::builder::repository_manager::client::Factory)
88 }
89
90 /// Creates a new client from the provided stub.
91 ///
92 /// The most common case for calling this function is in tests mocking the
93 /// client's behavior.
94 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
95 where
96 T: super::stub::RepositoryManager + 'static,
97 {
98 Self { inner: stub.into() }
99 }
100
101 pub(crate) async fn new(
102 config: gaxi::options::ClientConfig,
103 ) -> crate::ClientBuilderResult<Self> {
104 let inner = Self::build_inner(config).await?;
105 Ok(Self { inner })
106 }
107
108 async fn build_inner(
109 conf: gaxi::options::ClientConfig,
110 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::RepositoryManager>>
111 {
112 if gaxi::options::tracing_enabled(&conf) {
113 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
114 }
115 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
116 }
117
118 async fn build_transport(
119 conf: gaxi::options::ClientConfig,
120 ) -> crate::ClientBuilderResult<impl super::stub::RepositoryManager> {
121 super::transport::RepositoryManager::new(conf).await
122 }
123
124 async fn build_with_tracing(
125 conf: gaxi::options::ClientConfig,
126 ) -> crate::ClientBuilderResult<impl super::stub::RepositoryManager> {
127 Self::build_transport(conf)
128 .await
129 .map(super::tracing::RepositoryManager::new)
130 }
131
132 /// Creates a Connection.
133 ///
134 /// # Long running operations
135 ///
136 /// This method is used to start, and/or poll a [long-running Operation].
137 /// The [Working with long-running operations] chapter in the [user guide]
138 /// covers these operations in detail.
139 ///
140 /// [long-running operation]: https://google.aip.dev/151
141 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
142 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
143 ///
144 /// # Example
145 /// ```
146 /// # use google_cloud_build_v2::client::RepositoryManager;
147 /// use google_cloud_lro::Poller;
148 /// use google_cloud_build_v2::model::Connection;
149 /// use google_cloud_build_v2::Result;
150 /// async fn sample(
151 /// client: &RepositoryManager, project_id: &str, location_id: &str
152 /// ) -> Result<()> {
153 /// let response = client.create_connection()
154 /// .set_parent(format!("projects/{project_id}/locations/{location_id}"))
155 /// .set_connection_id("connection_id_value")
156 /// .set_connection(
157 /// Connection::new()/* set fields */
158 /// )
159 /// .poller().until_done().await?;
160 /// println!("response {:?}", response);
161 /// Ok(())
162 /// }
163 /// ```
164 pub fn create_connection(&self) -> super::builder::repository_manager::CreateConnection {
165 super::builder::repository_manager::CreateConnection::new(self.inner.clone())
166 }
167
168 /// Gets details of a single connection.
169 ///
170 /// # Example
171 /// ```
172 /// # use google_cloud_build_v2::client::RepositoryManager;
173 /// use google_cloud_build_v2::Result;
174 /// async fn sample(
175 /// client: &RepositoryManager, project_id: &str, location_id: &str, connection_id: &str
176 /// ) -> Result<()> {
177 /// let response = client.get_connection()
178 /// .set_name(format!("projects/{project_id}/locations/{location_id}/connections/{connection_id}"))
179 /// .send().await?;
180 /// println!("response {:?}", response);
181 /// Ok(())
182 /// }
183 /// ```
184 pub fn get_connection(&self) -> super::builder::repository_manager::GetConnection {
185 super::builder::repository_manager::GetConnection::new(self.inner.clone())
186 }
187
188 /// Lists Connections in a given project and location.
189 ///
190 /// # Example
191 /// ```
192 /// # use google_cloud_build_v2::client::RepositoryManager;
193 /// use google_cloud_gax::paginator::ItemPaginator as _;
194 /// use google_cloud_build_v2::Result;
195 /// async fn sample(
196 /// client: &RepositoryManager, project_id: &str, location_id: &str
197 /// ) -> Result<()> {
198 /// let mut list = client.list_connections()
199 /// .set_parent(format!("projects/{project_id}/locations/{location_id}"))
200 /// .by_item();
201 /// while let Some(item) = list.next().await.transpose()? {
202 /// println!("{:?}", item);
203 /// }
204 /// Ok(())
205 /// }
206 /// ```
207 pub fn list_connections(&self) -> super::builder::repository_manager::ListConnections {
208 super::builder::repository_manager::ListConnections::new(self.inner.clone())
209 }
210
211 /// Updates a single connection.
212 ///
213 /// # Long running operations
214 ///
215 /// This method is used to start, and/or poll a [long-running Operation].
216 /// The [Working with long-running operations] chapter in the [user guide]
217 /// covers these operations in detail.
218 ///
219 /// [long-running operation]: https://google.aip.dev/151
220 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
221 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
222 ///
223 /// # Example
224 /// ```
225 /// # use google_cloud_build_v2::client::RepositoryManager;
226 /// use google_cloud_lro::Poller;
227 /// # extern crate wkt as google_cloud_wkt;
228 /// use google_cloud_wkt::FieldMask;
229 /// use google_cloud_build_v2::model::Connection;
230 /// use google_cloud_build_v2::Result;
231 /// async fn sample(
232 /// client: &RepositoryManager, project_id: &str, location_id: &str, connection_id: &str
233 /// ) -> Result<()> {
234 /// let response = client.update_connection()
235 /// .set_connection(
236 /// Connection::new().set_name(format!("projects/{project_id}/locations/{location_id}/connections/{connection_id}"))/* set fields */
237 /// )
238 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
239 /// .poller().until_done().await?;
240 /// println!("response {:?}", response);
241 /// Ok(())
242 /// }
243 /// ```
244 pub fn update_connection(&self) -> super::builder::repository_manager::UpdateConnection {
245 super::builder::repository_manager::UpdateConnection::new(self.inner.clone())
246 }
247
248 /// Deletes a single connection.
249 ///
250 /// # Long running operations
251 ///
252 /// This method is used to start, and/or poll a [long-running Operation].
253 /// The [Working with long-running operations] chapter in the [user guide]
254 /// covers these operations in detail.
255 ///
256 /// [long-running operation]: https://google.aip.dev/151
257 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
258 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
259 ///
260 /// # Example
261 /// ```
262 /// # use google_cloud_build_v2::client::RepositoryManager;
263 /// use google_cloud_lro::Poller;
264 /// use google_cloud_build_v2::Result;
265 /// async fn sample(
266 /// client: &RepositoryManager, project_id: &str, location_id: &str, connection_id: &str
267 /// ) -> Result<()> {
268 /// client.delete_connection()
269 /// .set_name(format!("projects/{project_id}/locations/{location_id}/connections/{connection_id}"))
270 /// .poller().until_done().await?;
271 /// Ok(())
272 /// }
273 /// ```
274 pub fn delete_connection(&self) -> super::builder::repository_manager::DeleteConnection {
275 super::builder::repository_manager::DeleteConnection::new(self.inner.clone())
276 }
277
278 /// Creates a Repository.
279 ///
280 /// # Long running operations
281 ///
282 /// This method is used to start, and/or poll a [long-running Operation].
283 /// The [Working with long-running operations] chapter in the [user guide]
284 /// covers these operations in detail.
285 ///
286 /// [long-running operation]: https://google.aip.dev/151
287 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
288 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
289 ///
290 /// # Example
291 /// ```
292 /// # use google_cloud_build_v2::client::RepositoryManager;
293 /// use google_cloud_lro::Poller;
294 /// use google_cloud_build_v2::model::Repository;
295 /// use google_cloud_build_v2::Result;
296 /// async fn sample(
297 /// client: &RepositoryManager, project_id: &str, location_id: &str, connection_id: &str
298 /// ) -> Result<()> {
299 /// let response = client.create_repository()
300 /// .set_parent(format!("projects/{project_id}/locations/{location_id}/connections/{connection_id}"))
301 /// .set_repository_id("repository_id_value")
302 /// .set_repository(
303 /// Repository::new()/* set fields */
304 /// )
305 /// .poller().until_done().await?;
306 /// println!("response {:?}", response);
307 /// Ok(())
308 /// }
309 /// ```
310 pub fn create_repository(&self) -> super::builder::repository_manager::CreateRepository {
311 super::builder::repository_manager::CreateRepository::new(self.inner.clone())
312 }
313
314 /// Creates multiple repositories inside a connection.
315 ///
316 /// # Long running operations
317 ///
318 /// This method is used to start, and/or poll a [long-running Operation].
319 /// The [Working with long-running operations] chapter in the [user guide]
320 /// covers these operations in detail.
321 ///
322 /// [long-running operation]: https://google.aip.dev/151
323 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
324 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
325 ///
326 /// # Example
327 /// ```
328 /// # use google_cloud_build_v2::client::RepositoryManager;
329 /// use google_cloud_lro::Poller;
330 /// use google_cloud_build_v2::Result;
331 /// async fn sample(
332 /// client: &RepositoryManager
333 /// ) -> Result<()> {
334 /// let response = client.batch_create_repositories()
335 /// /* set fields */
336 /// .poller().until_done().await?;
337 /// println!("response {:?}", response);
338 /// Ok(())
339 /// }
340 /// ```
341 pub fn batch_create_repositories(
342 &self,
343 ) -> super::builder::repository_manager::BatchCreateRepositories {
344 super::builder::repository_manager::BatchCreateRepositories::new(self.inner.clone())
345 }
346
347 /// Gets details of a single repository.
348 ///
349 /// # Example
350 /// ```
351 /// # use google_cloud_build_v2::client::RepositoryManager;
352 /// use google_cloud_build_v2::Result;
353 /// async fn sample(
354 /// client: &RepositoryManager, project_id: &str, location_id: &str, connection_id: &str, repository_id: &str
355 /// ) -> Result<()> {
356 /// let response = client.get_repository()
357 /// .set_name(format!("projects/{project_id}/locations/{location_id}/connections/{connection_id}/repositories/{repository_id}"))
358 /// .send().await?;
359 /// println!("response {:?}", response);
360 /// Ok(())
361 /// }
362 /// ```
363 pub fn get_repository(&self) -> super::builder::repository_manager::GetRepository {
364 super::builder::repository_manager::GetRepository::new(self.inner.clone())
365 }
366
367 /// Lists Repositories in a given connection.
368 ///
369 /// # Example
370 /// ```
371 /// # use google_cloud_build_v2::client::RepositoryManager;
372 /// use google_cloud_gax::paginator::ItemPaginator as _;
373 /// use google_cloud_build_v2::Result;
374 /// async fn sample(
375 /// client: &RepositoryManager, project_id: &str, location_id: &str, connection_id: &str
376 /// ) -> Result<()> {
377 /// let mut list = client.list_repositories()
378 /// .set_parent(format!("projects/{project_id}/locations/{location_id}/connections/{connection_id}"))
379 /// .by_item();
380 /// while let Some(item) = list.next().await.transpose()? {
381 /// println!("{:?}", item);
382 /// }
383 /// Ok(())
384 /// }
385 /// ```
386 pub fn list_repositories(&self) -> super::builder::repository_manager::ListRepositories {
387 super::builder::repository_manager::ListRepositories::new(self.inner.clone())
388 }
389
390 /// Deletes a single repository.
391 ///
392 /// # Long running operations
393 ///
394 /// This method is used to start, and/or poll a [long-running Operation].
395 /// The [Working with long-running operations] chapter in the [user guide]
396 /// covers these operations in detail.
397 ///
398 /// [long-running operation]: https://google.aip.dev/151
399 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
400 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
401 ///
402 /// # Example
403 /// ```
404 /// # use google_cloud_build_v2::client::RepositoryManager;
405 /// use google_cloud_lro::Poller;
406 /// use google_cloud_build_v2::Result;
407 /// async fn sample(
408 /// client: &RepositoryManager, project_id: &str, location_id: &str, connection_id: &str, repository_id: &str
409 /// ) -> Result<()> {
410 /// client.delete_repository()
411 /// .set_name(format!("projects/{project_id}/locations/{location_id}/connections/{connection_id}/repositories/{repository_id}"))
412 /// .poller().until_done().await?;
413 /// Ok(())
414 /// }
415 /// ```
416 pub fn delete_repository(&self) -> super::builder::repository_manager::DeleteRepository {
417 super::builder::repository_manager::DeleteRepository::new(self.inner.clone())
418 }
419
420 /// Fetches read/write token of a given repository.
421 ///
422 /// # Example
423 /// ```
424 /// # use google_cloud_build_v2::client::RepositoryManager;
425 /// use google_cloud_build_v2::Result;
426 /// async fn sample(
427 /// client: &RepositoryManager
428 /// ) -> Result<()> {
429 /// let response = client.fetch_read_write_token()
430 /// /* set fields */
431 /// .send().await?;
432 /// println!("response {:?}", response);
433 /// Ok(())
434 /// }
435 /// ```
436 pub fn fetch_read_write_token(
437 &self,
438 ) -> super::builder::repository_manager::FetchReadWriteToken {
439 super::builder::repository_manager::FetchReadWriteToken::new(self.inner.clone())
440 }
441
442 /// Fetches read token of a given repository.
443 ///
444 /// # Example
445 /// ```
446 /// # use google_cloud_build_v2::client::RepositoryManager;
447 /// use google_cloud_build_v2::Result;
448 /// async fn sample(
449 /// client: &RepositoryManager
450 /// ) -> Result<()> {
451 /// let response = client.fetch_read_token()
452 /// /* set fields */
453 /// .send().await?;
454 /// println!("response {:?}", response);
455 /// Ok(())
456 /// }
457 /// ```
458 pub fn fetch_read_token(&self) -> super::builder::repository_manager::FetchReadToken {
459 super::builder::repository_manager::FetchReadToken::new(self.inner.clone())
460 }
461
462 /// FetchLinkableRepositories get repositories from SCM that are
463 /// accessible and could be added to the connection.
464 ///
465 /// # Example
466 /// ```
467 /// # use google_cloud_build_v2::client::RepositoryManager;
468 /// use google_cloud_gax::paginator::ItemPaginator as _;
469 /// use google_cloud_build_v2::Result;
470 /// async fn sample(
471 /// client: &RepositoryManager
472 /// ) -> Result<()> {
473 /// let mut list = client.fetch_linkable_repositories()
474 /// /* set fields */
475 /// .by_item();
476 /// while let Some(item) = list.next().await.transpose()? {
477 /// println!("{:?}", item);
478 /// }
479 /// Ok(())
480 /// }
481 /// ```
482 pub fn fetch_linkable_repositories(
483 &self,
484 ) -> super::builder::repository_manager::FetchLinkableRepositories {
485 super::builder::repository_manager::FetchLinkableRepositories::new(self.inner.clone())
486 }
487
488 /// Fetch the list of branches or tags for a given repository.
489 ///
490 /// # Example
491 /// ```
492 /// # use google_cloud_build_v2::client::RepositoryManager;
493 /// use google_cloud_build_v2::Result;
494 /// async fn sample(
495 /// client: &RepositoryManager
496 /// ) -> Result<()> {
497 /// let response = client.fetch_git_refs()
498 /// /* set fields */
499 /// .send().await?;
500 /// println!("response {:?}", response);
501 /// Ok(())
502 /// }
503 /// ```
504 pub fn fetch_git_refs(&self) -> super::builder::repository_manager::FetchGitRefs {
505 super::builder::repository_manager::FetchGitRefs::new(self.inner.clone())
506 }
507
508 /// Sets the access control policy on the specified resource. Replaces
509 /// any existing policy.
510 ///
511 /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
512 /// errors.
513 ///
514 /// # Example
515 /// ```
516 /// # use google_cloud_build_v2::client::RepositoryManager;
517 /// use google_cloud_build_v2::Result;
518 /// async fn sample(
519 /// client: &RepositoryManager
520 /// ) -> Result<()> {
521 /// let response = client.set_iam_policy()
522 /// /* set fields */
523 /// .send().await?;
524 /// println!("response {:?}", response);
525 /// Ok(())
526 /// }
527 /// ```
528 pub fn set_iam_policy(&self) -> super::builder::repository_manager::SetIamPolicy {
529 super::builder::repository_manager::SetIamPolicy::new(self.inner.clone())
530 }
531
532 /// Gets the access control policy for a resource. Returns an empty policy
533 /// if the resource exists and does not have a policy set.
534 ///
535 /// # Example
536 /// ```
537 /// # use google_cloud_build_v2::client::RepositoryManager;
538 /// use google_cloud_build_v2::Result;
539 /// async fn sample(
540 /// client: &RepositoryManager
541 /// ) -> Result<()> {
542 /// let response = client.get_iam_policy()
543 /// /* set fields */
544 /// .send().await?;
545 /// println!("response {:?}", response);
546 /// Ok(())
547 /// }
548 /// ```
549 pub fn get_iam_policy(&self) -> super::builder::repository_manager::GetIamPolicy {
550 super::builder::repository_manager::GetIamPolicy::new(self.inner.clone())
551 }
552
553 /// Returns permissions that a caller has on the specified resource. If the
554 /// resource does not exist, this will return an empty set of
555 /// permissions, not a `NOT_FOUND` error.
556 ///
557 /// Note: This operation is designed to be used for building
558 /// permission-aware UIs and command-line tools, not for authorization
559 /// checking. This operation may "fail open" without warning.
560 ///
561 /// # Example
562 /// ```
563 /// # use google_cloud_build_v2::client::RepositoryManager;
564 /// use google_cloud_build_v2::Result;
565 /// async fn sample(
566 /// client: &RepositoryManager
567 /// ) -> Result<()> {
568 /// let response = client.test_iam_permissions()
569 /// /* set fields */
570 /// .send().await?;
571 /// println!("response {:?}", response);
572 /// Ok(())
573 /// }
574 /// ```
575 pub fn test_iam_permissions(&self) -> super::builder::repository_manager::TestIamPermissions {
576 super::builder::repository_manager::TestIamPermissions::new(self.inner.clone())
577 }
578
579 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
580 ///
581 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
582 ///
583 /// # Example
584 /// ```
585 /// # use google_cloud_build_v2::client::RepositoryManager;
586 /// use google_cloud_build_v2::Result;
587 /// async fn sample(
588 /// client: &RepositoryManager
589 /// ) -> Result<()> {
590 /// let response = client.get_operation()
591 /// /* set fields */
592 /// .send().await?;
593 /// println!("response {:?}", response);
594 /// Ok(())
595 /// }
596 /// ```
597 pub fn get_operation(&self) -> super::builder::repository_manager::GetOperation {
598 super::builder::repository_manager::GetOperation::new(self.inner.clone())
599 }
600
601 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
602 ///
603 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
604 ///
605 /// # Example
606 /// ```
607 /// # use google_cloud_build_v2::client::RepositoryManager;
608 /// use google_cloud_build_v2::Result;
609 /// async fn sample(
610 /// client: &RepositoryManager
611 /// ) -> Result<()> {
612 /// client.cancel_operation()
613 /// /* set fields */
614 /// .send().await?;
615 /// Ok(())
616 /// }
617 /// ```
618 pub fn cancel_operation(&self) -> super::builder::repository_manager::CancelOperation {
619 super::builder::repository_manager::CancelOperation::new(self.inner.clone())
620 }
621}