Skip to main content

google_cloud_storagebatchoperations_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 Storage Batch Operations API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
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 = StorageBatchOperations::builder().build().await?;
30///     let mut list = client.list_jobs()
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/// Storage Batch Operations offers a managed experience to perform batch
43/// operations on millions of Cloud Storage objects in a serverless fashion. With
44/// this service, you can automate and simplify large scale API operations
45/// performed on Cloud Storage objects.
46///
47/// # Configuration
48///
49/// To configure `StorageBatchOperations` use the `with_*` methods in the type returned
50/// by [builder()][StorageBatchOperations::builder]. The default configuration should
51/// work for most applications. Common configuration changes include
52///
53/// * [with_endpoint()]: by default this client uses the global default endpoint
54///   (`https://storagebatchoperations.googleapis.com`). Applications using regional
55///   endpoints or running in restricted networks (e.g. a network configured
56//    with [Private Google Access with VPC Service Controls]) may want to
57///   override this default.
58/// * [with_credentials()]: by default this client uses
59///   [Application Default Credentials]. Applications using custom
60///   authentication may need to override this default.
61///
62/// [with_endpoint()]: super::builder::storage_batch_operations::ClientBuilder::with_endpoint
63/// [with_credentials()]: super::builder::storage_batch_operations::ClientBuilder::with_credentials
64/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
65/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
66///
67/// # Pooling and Cloning
68///
69/// `StorageBatchOperations` holds a connection pool internally, it is advised to
70/// create one and reuse it. You do not need to wrap `StorageBatchOperations` in
71/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
72/// already uses an `Arc` internally.
73#[derive(Clone, Debug)]
74pub struct StorageBatchOperations {
75    inner: std::sync::Arc<dyn super::stub::dynamic::StorageBatchOperations>,
76}
77
78impl StorageBatchOperations {
79    /// Returns a builder for [StorageBatchOperations].
80    ///
81    /// ```
82    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
83    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
84    /// let client = StorageBatchOperations::builder().build().await?;
85    /// # Ok(()) }
86    /// ```
87    pub fn builder() -> super::builder::storage_batch_operations::ClientBuilder {
88        crate::new_client_builder(super::builder::storage_batch_operations::client::Factory)
89    }
90
91    /// Creates a new client from the provided stub.
92    ///
93    /// The most common case for calling this function is in tests mocking the
94    /// client's behavior.
95    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
96    where
97        T: super::stub::StorageBatchOperations + 'static,
98    {
99        Self { inner: stub.into() }
100    }
101
102    pub(crate) async fn new(
103        config: gaxi::options::ClientConfig,
104    ) -> crate::ClientBuilderResult<Self> {
105        let inner = Self::build_inner(config).await?;
106        Ok(Self { inner })
107    }
108
109    async fn build_inner(
110        conf: gaxi::options::ClientConfig,
111    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::StorageBatchOperations>>
112    {
113        if gaxi::options::tracing_enabled(&conf) {
114            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
115        }
116        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
117    }
118
119    async fn build_transport(
120        conf: gaxi::options::ClientConfig,
121    ) -> crate::ClientBuilderResult<impl super::stub::StorageBatchOperations> {
122        super::transport::StorageBatchOperations::new(conf).await
123    }
124
125    async fn build_with_tracing(
126        conf: gaxi::options::ClientConfig,
127    ) -> crate::ClientBuilderResult<impl super::stub::StorageBatchOperations> {
128        Self::build_transport(conf)
129            .await
130            .map(super::tracing::StorageBatchOperations::new)
131    }
132
133    /// Lists Jobs in a given project.
134    ///
135    /// # Example
136    /// ```
137    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
138    /// use google_cloud_gax::paginator::ItemPaginator as _;
139    /// use google_cloud_storagebatchoperations_v1::Result;
140    /// async fn sample(
141    ///    client: &StorageBatchOperations, project_id: &str, location_id: &str
142    /// ) -> Result<()> {
143    ///     let mut list = client.list_jobs()
144    ///         .set_parent(format!("projects/{project_id}/locations/{location_id}"))
145    ///         .by_item();
146    ///     while let Some(item) = list.next().await.transpose()? {
147    ///         println!("{:?}", item);
148    ///     }
149    ///     Ok(())
150    /// }
151    /// ```
152    pub fn list_jobs(&self) -> super::builder::storage_batch_operations::ListJobs {
153        super::builder::storage_batch_operations::ListJobs::new(self.inner.clone())
154    }
155
156    /// Gets a batch job.
157    ///
158    /// # Example
159    /// ```
160    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
161    /// use google_cloud_storagebatchoperations_v1::Result;
162    /// async fn sample(
163    ///    client: &StorageBatchOperations, project_id: &str, location_id: &str, job_id: &str
164    /// ) -> Result<()> {
165    ///     let response = client.get_job()
166    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/jobs/{job_id}"))
167    ///         .send().await?;
168    ///     println!("response {:?}", response);
169    ///     Ok(())
170    /// }
171    /// ```
172    pub fn get_job(&self) -> super::builder::storage_batch_operations::GetJob {
173        super::builder::storage_batch_operations::GetJob::new(self.inner.clone())
174    }
175
176    /// Creates a batch job.
177    ///
178    /// # Long running operations
179    ///
180    /// This method is used to start, and/or poll a [long-running Operation].
181    /// The [Working with long-running operations] chapter in the [user guide]
182    /// covers these operations in detail.
183    ///
184    /// [long-running operation]: https://google.aip.dev/151
185    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
186    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
187    ///
188    /// # Example
189    /// ```
190    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
191    /// use google_cloud_lro::Poller;
192    /// use google_cloud_storagebatchoperations_v1::model::Job;
193    /// use google_cloud_storagebatchoperations_v1::Result;
194    /// async fn sample(
195    ///    client: &StorageBatchOperations, project_id: &str, location_id: &str
196    /// ) -> Result<()> {
197    ///     let response = client.create_job()
198    ///         .set_parent(format!("projects/{project_id}/locations/{location_id}"))
199    ///         .set_job_id("job_id_value")
200    ///         .set_job(
201    ///             Job::new()/* set fields */
202    ///         )
203    ///         .poller().until_done().await?;
204    ///     println!("response {:?}", response);
205    ///     Ok(())
206    /// }
207    /// ```
208    pub fn create_job(&self) -> super::builder::storage_batch_operations::CreateJob {
209        super::builder::storage_batch_operations::CreateJob::new(self.inner.clone())
210    }
211
212    /// Deletes a batch job.
213    ///
214    /// # Example
215    /// ```
216    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
217    /// use google_cloud_storagebatchoperations_v1::Result;
218    /// async fn sample(
219    ///    client: &StorageBatchOperations, project_id: &str, location_id: &str, job_id: &str
220    /// ) -> Result<()> {
221    ///     client.delete_job()
222    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/jobs/{job_id}"))
223    ///         .send().await?;
224    ///     Ok(())
225    /// }
226    /// ```
227    pub fn delete_job(&self) -> super::builder::storage_batch_operations::DeleteJob {
228        super::builder::storage_batch_operations::DeleteJob::new(self.inner.clone())
229    }
230
231    /// Cancels a batch job.
232    ///
233    /// # Example
234    /// ```
235    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
236    /// use google_cloud_storagebatchoperations_v1::Result;
237    /// async fn sample(
238    ///    client: &StorageBatchOperations
239    /// ) -> Result<()> {
240    ///     let response = client.cancel_job()
241    ///         /* set fields */
242    ///         .send().await?;
243    ///     println!("response {:?}", response);
244    ///     Ok(())
245    /// }
246    /// ```
247    pub fn cancel_job(&self) -> super::builder::storage_batch_operations::CancelJob {
248        super::builder::storage_batch_operations::CancelJob::new(self.inner.clone())
249    }
250
251    /// Lists BucketOperations in a given project and job.
252    ///
253    /// # Example
254    /// ```
255    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
256    /// use google_cloud_gax::paginator::ItemPaginator as _;
257    /// use google_cloud_storagebatchoperations_v1::Result;
258    /// async fn sample(
259    ///    client: &StorageBatchOperations, project_id: &str, location_id: &str, job_id: &str
260    /// ) -> Result<()> {
261    ///     let mut list = client.list_bucket_operations()
262    ///         .set_parent(format!("projects/{project_id}/locations/{location_id}/jobs/{job_id}"))
263    ///         .by_item();
264    ///     while let Some(item) = list.next().await.transpose()? {
265    ///         println!("{:?}", item);
266    ///     }
267    ///     Ok(())
268    /// }
269    /// ```
270    pub fn list_bucket_operations(
271        &self,
272    ) -> super::builder::storage_batch_operations::ListBucketOperations {
273        super::builder::storage_batch_operations::ListBucketOperations::new(self.inner.clone())
274    }
275
276    /// Gets a BucketOperation.
277    ///
278    /// # Example
279    /// ```
280    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
281    /// use google_cloud_storagebatchoperations_v1::Result;
282    /// async fn sample(
283    ///    client: &StorageBatchOperations, project_id: &str, location_id: &str, job_id: &str, bucket_operation_id: &str
284    /// ) -> Result<()> {
285    ///     let response = client.get_bucket_operation()
286    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/jobs/{job_id}/bucketOperations/{bucket_operation_id}"))
287    ///         .send().await?;
288    ///     println!("response {:?}", response);
289    ///     Ok(())
290    /// }
291    /// ```
292    pub fn get_bucket_operation(
293        &self,
294    ) -> super::builder::storage_batch_operations::GetBucketOperation {
295        super::builder::storage_batch_operations::GetBucketOperation::new(self.inner.clone())
296    }
297
298    /// Lists information about the supported locations for this service.
299    ///
300    /// # Example
301    /// ```
302    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
303    /// use google_cloud_gax::paginator::ItemPaginator as _;
304    /// use google_cloud_storagebatchoperations_v1::Result;
305    /// async fn sample(
306    ///    client: &StorageBatchOperations
307    /// ) -> Result<()> {
308    ///     let mut list = client.list_locations()
309    ///         /* set fields */
310    ///         .by_item();
311    ///     while let Some(item) = list.next().await.transpose()? {
312    ///         println!("{:?}", item);
313    ///     }
314    ///     Ok(())
315    /// }
316    /// ```
317    pub fn list_locations(&self) -> super::builder::storage_batch_operations::ListLocations {
318        super::builder::storage_batch_operations::ListLocations::new(self.inner.clone())
319    }
320
321    /// Gets information about a location.
322    ///
323    /// # Example
324    /// ```
325    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
326    /// use google_cloud_storagebatchoperations_v1::Result;
327    /// async fn sample(
328    ///    client: &StorageBatchOperations
329    /// ) -> Result<()> {
330    ///     let response = client.get_location()
331    ///         /* set fields */
332    ///         .send().await?;
333    ///     println!("response {:?}", response);
334    ///     Ok(())
335    /// }
336    /// ```
337    pub fn get_location(&self) -> super::builder::storage_batch_operations::GetLocation {
338        super::builder::storage_batch_operations::GetLocation::new(self.inner.clone())
339    }
340
341    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
342    ///
343    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
344    ///
345    /// # Example
346    /// ```
347    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
348    /// use google_cloud_gax::paginator::ItemPaginator as _;
349    /// use google_cloud_storagebatchoperations_v1::Result;
350    /// async fn sample(
351    ///    client: &StorageBatchOperations
352    /// ) -> Result<()> {
353    ///     let mut list = client.list_operations()
354    ///         /* set fields */
355    ///         .by_item();
356    ///     while let Some(item) = list.next().await.transpose()? {
357    ///         println!("{:?}", item);
358    ///     }
359    ///     Ok(())
360    /// }
361    /// ```
362    pub fn list_operations(&self) -> super::builder::storage_batch_operations::ListOperations {
363        super::builder::storage_batch_operations::ListOperations::new(self.inner.clone())
364    }
365
366    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
367    ///
368    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
369    ///
370    /// # Example
371    /// ```
372    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
373    /// use google_cloud_storagebatchoperations_v1::Result;
374    /// async fn sample(
375    ///    client: &StorageBatchOperations
376    /// ) -> Result<()> {
377    ///     let response = client.get_operation()
378    ///         /* set fields */
379    ///         .send().await?;
380    ///     println!("response {:?}", response);
381    ///     Ok(())
382    /// }
383    /// ```
384    pub fn get_operation(&self) -> super::builder::storage_batch_operations::GetOperation {
385        super::builder::storage_batch_operations::GetOperation::new(self.inner.clone())
386    }
387
388    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
389    ///
390    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
391    ///
392    /// # Example
393    /// ```
394    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
395    /// use google_cloud_storagebatchoperations_v1::Result;
396    /// async fn sample(
397    ///    client: &StorageBatchOperations
398    /// ) -> Result<()> {
399    ///     client.delete_operation()
400    ///         /* set fields */
401    ///         .send().await?;
402    ///     Ok(())
403    /// }
404    /// ```
405    pub fn delete_operation(&self) -> super::builder::storage_batch_operations::DeleteOperation {
406        super::builder::storage_batch_operations::DeleteOperation::new(self.inner.clone())
407    }
408
409    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
410    ///
411    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
412    ///
413    /// # Example
414    /// ```
415    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
416    /// use google_cloud_storagebatchoperations_v1::Result;
417    /// async fn sample(
418    ///    client: &StorageBatchOperations
419    /// ) -> Result<()> {
420    ///     client.cancel_operation()
421    ///         /* set fields */
422    ///         .send().await?;
423    ///     Ok(())
424    /// }
425    /// ```
426    pub fn cancel_operation(&self) -> super::builder::storage_batch_operations::CancelOperation {
427        super::builder::storage_batch_operations::CancelOperation::new(self.inner.clone())
428    }
429}