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