google_cloud_build_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 Cloud Build API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_build_v1::client::CloudBuild;
25/// let client = CloudBuild::builder().build().await?;
26/// // use `client` to make requests to the Cloud Build API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Creates and manages builds on Google Cloud Platform.
33///
34/// The main concept used by this API is a `Build`, which describes the location
35/// of the source to build, how to build the source, and where to store the
36/// built artifacts, if any.
37///
38/// A user can list previously-requested builds or get builds by their ID to
39/// determine the status of the build.
40///
41/// # Configuration
42///
43/// To configure `CloudBuild` use the `with_*` methods in the type returned
44/// by [builder()][CloudBuild::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://cloudbuild.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::cloud_build::ClientBuilder::with_endpoint
57/// [with_credentials()]: super::builder::cloud_build::ClientBuilder::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/// `CloudBuild` holds a connection pool internally, it is advised to
64/// create one and the reuse it. You do not need to wrap `CloudBuild` 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 CloudBuild {
69 inner: std::sync::Arc<dyn super::stub::dynamic::CloudBuild>,
70}
71
72impl CloudBuild {
73 /// Returns a builder for [CloudBuild].
74 ///
75 /// ```
76 /// # tokio_test::block_on(async {
77 /// # use google_cloud_build_v1::client::CloudBuild;
78 /// let client = CloudBuild::builder().build().await?;
79 /// # gax::client_builder::Result::<()>::Ok(()) });
80 /// ```
81 pub fn builder() -> super::builder::cloud_build::ClientBuilder {
82 gax::client_builder::internal::new_builder(super::builder::cloud_build::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::CloudBuild + '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 ) -> gax::client_builder::Result<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 ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::CloudBuild>> {
108 if gaxi::options::tracing_enabled(&conf) {
109 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
110 }
111 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
112 }
113
114 async fn build_transport(
115 conf: gaxi::options::ClientConfig,
116 ) -> gax::client_builder::Result<impl super::stub::CloudBuild> {
117 super::transport::CloudBuild::new(conf).await
118 }
119
120 async fn build_with_tracing(
121 conf: gaxi::options::ClientConfig,
122 ) -> gax::client_builder::Result<impl super::stub::CloudBuild> {
123 Self::build_transport(conf)
124 .await
125 .map(super::tracing::CloudBuild::new)
126 }
127
128 /// Starts a build with the specified configuration.
129 ///
130 /// This method returns a long-running `Operation`, which includes the build
131 /// ID. Pass the build ID to `GetBuild` to determine the build status (such as
132 /// `SUCCESS` or `FAILURE`).
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 pub fn create_build(&self) -> super::builder::cloud_build::CreateBuild {
144 super::builder::cloud_build::CreateBuild::new(self.inner.clone())
145 }
146
147 /// Returns information about a previously requested build.
148 ///
149 /// The `Build` that is returned includes its status (such as `SUCCESS`,
150 /// `FAILURE`, or `WORKING`), and timing information.
151 pub fn get_build(&self) -> super::builder::cloud_build::GetBuild {
152 super::builder::cloud_build::GetBuild::new(self.inner.clone())
153 }
154
155 /// Lists previously requested builds.
156 ///
157 /// Previously requested builds may still be in-progress, or may have finished
158 /// successfully or unsuccessfully.
159 pub fn list_builds(&self) -> super::builder::cloud_build::ListBuilds {
160 super::builder::cloud_build::ListBuilds::new(self.inner.clone())
161 }
162
163 /// Cancels a build in progress.
164 pub fn cancel_build(&self) -> super::builder::cloud_build::CancelBuild {
165 super::builder::cloud_build::CancelBuild::new(self.inner.clone())
166 }
167
168 /// Creates a new build based on the specified build.
169 ///
170 /// This method creates a new build using the original build request, which may
171 /// or may not result in an identical build.
172 ///
173 /// For triggered builds:
174 ///
175 /// * Triggered builds resolve to a precise revision; therefore a retry of a
176 /// triggered build will result in a build that uses the same revision.
177 ///
178 /// For non-triggered builds that specify `RepoSource`:
179 ///
180 /// * If the original build built from the tip of a branch, the retried build
181 /// will build from the tip of that branch, which may not be the same revision
182 /// as the original build.
183 /// * If the original build specified a commit sha or revision ID, the retried
184 /// build will use the identical source.
185 ///
186 /// For builds that specify `StorageSource`:
187 ///
188 /// * If the original build pulled source from Cloud Storage without
189 /// specifying the generation of the object, the new build will use the current
190 /// object, which may be different from the original build source.
191 /// * If the original build pulled source from Cloud Storage and specified the
192 /// generation of the object, the new build will attempt to use the same
193 /// object, which may or may not be available depending on the bucket's
194 /// lifecycle management settings.
195 ///
196 /// # Long running operations
197 ///
198 /// This method is used to start, and/or poll a [long-running Operation].
199 /// The [Working with long-running operations] chapter in the [user guide]
200 /// covers these operations in detail.
201 ///
202 /// [long-running operation]: https://google.aip.dev/151
203 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
204 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
205 pub fn retry_build(&self) -> super::builder::cloud_build::RetryBuild {
206 super::builder::cloud_build::RetryBuild::new(self.inner.clone())
207 }
208
209 /// Approves or rejects a pending build.
210 ///
211 /// If approved, the returned long-running operation (LRO) will be analogous to
212 /// the LRO returned from a CreateBuild call.
213 ///
214 /// If rejected, the returned LRO will be immediately done.
215 ///
216 /// # Long running operations
217 ///
218 /// This method is used to start, and/or poll a [long-running Operation].
219 /// The [Working with long-running operations] chapter in the [user guide]
220 /// covers these operations in detail.
221 ///
222 /// [long-running operation]: https://google.aip.dev/151
223 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
224 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
225 pub fn approve_build(&self) -> super::builder::cloud_build::ApproveBuild {
226 super::builder::cloud_build::ApproveBuild::new(self.inner.clone())
227 }
228
229 /// Creates a new `BuildTrigger`.
230 pub fn create_build_trigger(&self) -> super::builder::cloud_build::CreateBuildTrigger {
231 super::builder::cloud_build::CreateBuildTrigger::new(self.inner.clone())
232 }
233
234 /// Returns information about a `BuildTrigger`.
235 pub fn get_build_trigger(&self) -> super::builder::cloud_build::GetBuildTrigger {
236 super::builder::cloud_build::GetBuildTrigger::new(self.inner.clone())
237 }
238
239 /// Lists existing `BuildTrigger`s.
240 pub fn list_build_triggers(&self) -> super::builder::cloud_build::ListBuildTriggers {
241 super::builder::cloud_build::ListBuildTriggers::new(self.inner.clone())
242 }
243
244 /// Deletes a `BuildTrigger` by its project ID and trigger ID.
245 pub fn delete_build_trigger(&self) -> super::builder::cloud_build::DeleteBuildTrigger {
246 super::builder::cloud_build::DeleteBuildTrigger::new(self.inner.clone())
247 }
248
249 /// Updates a `BuildTrigger` by its project ID and trigger ID.
250 pub fn update_build_trigger(&self) -> super::builder::cloud_build::UpdateBuildTrigger {
251 super::builder::cloud_build::UpdateBuildTrigger::new(self.inner.clone())
252 }
253
254 /// Runs a `BuildTrigger` at a particular source revision.
255 ///
256 /// To run a regional or global trigger, use the POST request
257 /// that includes the location endpoint in the path (ex.
258 /// v1/projects/{projectId}/locations/{region}/triggers/{triggerId}:run). The
259 /// POST request that does not include the location endpoint in the path can
260 /// only be used when running global triggers.
261 ///
262 /// # Long running operations
263 ///
264 /// This method is used to start, and/or poll a [long-running Operation].
265 /// The [Working with long-running operations] chapter in the [user guide]
266 /// covers these operations in detail.
267 ///
268 /// [long-running operation]: https://google.aip.dev/151
269 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
270 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
271 pub fn run_build_trigger(&self) -> super::builder::cloud_build::RunBuildTrigger {
272 super::builder::cloud_build::RunBuildTrigger::new(self.inner.clone())
273 }
274
275 /// ReceiveTriggerWebhook [Experimental] is called when the API receives a
276 /// webhook request targeted at a specific trigger.
277 pub fn receive_trigger_webhook(&self) -> super::builder::cloud_build::ReceiveTriggerWebhook {
278 super::builder::cloud_build::ReceiveTriggerWebhook::new(self.inner.clone())
279 }
280
281 /// Creates a `WorkerPool`.
282 ///
283 /// # Long running operations
284 ///
285 /// This method is used to start, and/or poll a [long-running Operation].
286 /// The [Working with long-running operations] chapter in the [user guide]
287 /// covers these operations in detail.
288 ///
289 /// [long-running operation]: https://google.aip.dev/151
290 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
291 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
292 pub fn create_worker_pool(&self) -> super::builder::cloud_build::CreateWorkerPool {
293 super::builder::cloud_build::CreateWorkerPool::new(self.inner.clone())
294 }
295
296 /// Returns details of a `WorkerPool`.
297 pub fn get_worker_pool(&self) -> super::builder::cloud_build::GetWorkerPool {
298 super::builder::cloud_build::GetWorkerPool::new(self.inner.clone())
299 }
300
301 /// Deletes a `WorkerPool`.
302 ///
303 /// # Long running operations
304 ///
305 /// This method is used to start, and/or poll a [long-running Operation].
306 /// The [Working with long-running operations] chapter in the [user guide]
307 /// covers these operations in detail.
308 ///
309 /// [long-running operation]: https://google.aip.dev/151
310 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
311 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
312 pub fn delete_worker_pool(&self) -> super::builder::cloud_build::DeleteWorkerPool {
313 super::builder::cloud_build::DeleteWorkerPool::new(self.inner.clone())
314 }
315
316 /// Updates a `WorkerPool`.
317 ///
318 /// # Long running operations
319 ///
320 /// This method is used to start, and/or poll a [long-running Operation].
321 /// The [Working with long-running operations] chapter in the [user guide]
322 /// covers these operations in detail.
323 ///
324 /// [long-running operation]: https://google.aip.dev/151
325 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
326 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
327 pub fn update_worker_pool(&self) -> super::builder::cloud_build::UpdateWorkerPool {
328 super::builder::cloud_build::UpdateWorkerPool::new(self.inner.clone())
329 }
330
331 /// Lists `WorkerPool`s.
332 pub fn list_worker_pools(&self) -> super::builder::cloud_build::ListWorkerPools {
333 super::builder::cloud_build::ListWorkerPools::new(self.inner.clone())
334 }
335
336 /// Returns the `DefaultServiceAccount` used by the project.
337 pub fn get_default_service_account(
338 &self,
339 ) -> super::builder::cloud_build::GetDefaultServiceAccount {
340 super::builder::cloud_build::GetDefaultServiceAccount::new(self.inner.clone())
341 }
342
343 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
344 ///
345 /// [google.longrunning.Operations]: longrunning::client::Operations
346 pub fn get_operation(&self) -> super::builder::cloud_build::GetOperation {
347 super::builder::cloud_build::GetOperation::new(self.inner.clone())
348 }
349
350 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
351 ///
352 /// [google.longrunning.Operations]: longrunning::client::Operations
353 pub fn cancel_operation(&self) -> super::builder::cloud_build::CancelOperation {
354 super::builder::cloud_build::CancelOperation::new(self.inner.clone())
355 }
356}