Skip to main content

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