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() -> Result<(), Box<dyn std::error::Error>> {
26///     let client = StorageBatchOperations::builder().build().await?;
27///     let parent = "parent_value";
28///     let mut list = client.list_jobs()
29///         .set_parent(parent)
30///         .by_item();
31///     while let Some(item) = list.next().await.transpose()? {
32///         println!("{:?}", item);
33///     }
34/// # Ok(()) }
35/// ```
36///
37/// # Service Description
38///
39/// Storage Batch Operations offers a managed experience to perform batch
40/// operations on millions of Cloud Storage objects in a serverless fashion. With
41/// this service, you can automate and simplify large scale API operations
42/// performed on Cloud Storage objects.
43///
44/// # Configuration
45///
46/// To configure `StorageBatchOperations` use the `with_*` methods in the type returned
47/// by [builder()][StorageBatchOperations::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://storagebatchoperations.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::storage_batch_operations::ClientBuilder::with_endpoint
60/// [with_credentials()]: super::builder::storage_batch_operations::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/// `StorageBatchOperations` holds a connection pool internally, it is advised to
67/// create one and reuse it. You do not need to wrap `StorageBatchOperations` 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 StorageBatchOperations {
72    inner: std::sync::Arc<dyn super::stub::dynamic::StorageBatchOperations>,
73}
74
75impl StorageBatchOperations {
76    /// Returns a builder for [StorageBatchOperations].
77    ///
78    /// ```
79    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
80    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
81    /// let client = StorageBatchOperations::builder().build().await?;
82    /// # Ok(()) }
83    /// ```
84    pub fn builder() -> super::builder::storage_batch_operations::ClientBuilder {
85        crate::new_client_builder(super::builder::storage_batch_operations::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: T) -> Self
93    where
94        T: super::stub::StorageBatchOperations + 'static,
95    {
96        Self {
97            inner: std::sync::Arc::new(stub),
98        }
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::StorageBatchOperations>>
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::StorageBatchOperations> {
121        super::transport::StorageBatchOperations::new(conf).await
122    }
123
124    async fn build_with_tracing(
125        conf: gaxi::options::ClientConfig,
126    ) -> crate::ClientBuilderResult<impl super::stub::StorageBatchOperations> {
127        Self::build_transport(conf)
128            .await
129            .map(super::tracing::StorageBatchOperations::new)
130    }
131
132    /// Lists Jobs in a given project.
133    ///
134    /// # Example
135    /// ```
136    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
137    /// use google_cloud_gax::paginator::ItemPaginator as _;
138    /// use google_cloud_storagebatchoperations_v1::Result;
139    /// async fn sample(
140    ///    client: &StorageBatchOperations, parent: &str
141    /// ) -> Result<()> {
142    ///     let mut list = client.list_jobs()
143    ///         .set_parent(parent)
144    ///         .by_item();
145    ///     while let Some(item) = list.next().await.transpose()? {
146    ///         println!("{:?}", item);
147    ///     }
148    ///     Ok(())
149    /// }
150    /// ```
151    pub fn list_jobs(&self) -> super::builder::storage_batch_operations::ListJobs {
152        super::builder::storage_batch_operations::ListJobs::new(self.inner.clone())
153    }
154
155    /// Gets a batch job.
156    ///
157    /// # Example
158    /// ```
159    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
160    /// use google_cloud_storagebatchoperations_v1::Result;
161    /// async fn sample(
162    ///    client: &StorageBatchOperations, name: &str
163    /// ) -> Result<()> {
164    ///     let response = client.get_job()
165    ///         .set_name(name)
166    ///         .send().await?;
167    ///     println!("response {:?}", response);
168    ///     Ok(())
169    /// }
170    /// ```
171    pub fn get_job(&self) -> super::builder::storage_batch_operations::GetJob {
172        super::builder::storage_batch_operations::GetJob::new(self.inner.clone())
173    }
174
175    /// Creates a batch job.
176    ///
177    /// # Long running operations
178    ///
179    /// This method is used to start, and/or poll a [long-running Operation].
180    /// The [Working with long-running operations] chapter in the [user guide]
181    /// covers these operations in detail.
182    ///
183    /// [long-running operation]: https://google.aip.dev/151
184    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
185    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
186    ///
187    /// # Example
188    /// ```
189    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
190    /// use google_cloud_lro::Poller;
191    /// use google_cloud_storagebatchoperations_v1::model::Job;
192    /// use google_cloud_storagebatchoperations_v1::Result;
193    /// async fn sample(
194    ///    client: &StorageBatchOperations, parent: &str
195    /// ) -> Result<()> {
196    ///     let response = client.create_job()
197    ///         .set_parent(parent)
198    ///         .set_job_id("job_id_value")
199    ///         .set_job(
200    ///             Job::new()/* set fields */
201    ///         )
202    ///         .poller().until_done().await?;
203    ///     println!("response {:?}", response);
204    ///     Ok(())
205    /// }
206    /// ```
207    pub fn create_job(&self) -> super::builder::storage_batch_operations::CreateJob {
208        super::builder::storage_batch_operations::CreateJob::new(self.inner.clone())
209    }
210
211    /// Deletes a batch job.
212    ///
213    /// # Example
214    /// ```
215    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
216    /// use google_cloud_storagebatchoperations_v1::Result;
217    /// async fn sample(
218    ///    client: &StorageBatchOperations, name: &str
219    /// ) -> Result<()> {
220    ///     client.delete_job()
221    ///         .set_name(name)
222    ///         .send().await?;
223    ///     Ok(())
224    /// }
225    /// ```
226    pub fn delete_job(&self) -> super::builder::storage_batch_operations::DeleteJob {
227        super::builder::storage_batch_operations::DeleteJob::new(self.inner.clone())
228    }
229
230    /// Cancels a batch job.
231    ///
232    /// # Example
233    /// ```
234    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
235    /// use google_cloud_storagebatchoperations_v1::Result;
236    /// async fn sample(
237    ///    client: &StorageBatchOperations
238    /// ) -> Result<()> {
239    ///     let response = client.cancel_job()
240    ///         /* set fields */
241    ///         .send().await?;
242    ///     println!("response {:?}", response);
243    ///     Ok(())
244    /// }
245    /// ```
246    pub fn cancel_job(&self) -> super::builder::storage_batch_operations::CancelJob {
247        super::builder::storage_batch_operations::CancelJob::new(self.inner.clone())
248    }
249
250    /// Lists BucketOperations in a given project and job.
251    ///
252    /// # Example
253    /// ```
254    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
255    /// use google_cloud_gax::paginator::ItemPaginator as _;
256    /// use google_cloud_storagebatchoperations_v1::Result;
257    /// async fn sample(
258    ///    client: &StorageBatchOperations, parent: &str
259    /// ) -> Result<()> {
260    ///     let mut list = client.list_bucket_operations()
261    ///         .set_parent(parent)
262    ///         .by_item();
263    ///     while let Some(item) = list.next().await.transpose()? {
264    ///         println!("{:?}", item);
265    ///     }
266    ///     Ok(())
267    /// }
268    /// ```
269    pub fn list_bucket_operations(
270        &self,
271    ) -> super::builder::storage_batch_operations::ListBucketOperations {
272        super::builder::storage_batch_operations::ListBucketOperations::new(self.inner.clone())
273    }
274
275    /// Gets a BucketOperation.
276    ///
277    /// # Example
278    /// ```
279    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
280    /// use google_cloud_storagebatchoperations_v1::Result;
281    /// async fn sample(
282    ///    client: &StorageBatchOperations, name: &str
283    /// ) -> Result<()> {
284    ///     let response = client.get_bucket_operation()
285    ///         .set_name(name)
286    ///         .send().await?;
287    ///     println!("response {:?}", response);
288    ///     Ok(())
289    /// }
290    /// ```
291    pub fn get_bucket_operation(
292        &self,
293    ) -> super::builder::storage_batch_operations::GetBucketOperation {
294        super::builder::storage_batch_operations::GetBucketOperation::new(self.inner.clone())
295    }
296
297    /// Lists information about the supported locations for this service.
298    ///
299    /// # Example
300    /// ```
301    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
302    /// use google_cloud_gax::paginator::ItemPaginator as _;
303    /// use google_cloud_storagebatchoperations_v1::Result;
304    /// async fn sample(
305    ///    client: &StorageBatchOperations
306    /// ) -> Result<()> {
307    ///     let mut list = client.list_locations()
308    ///         /* set fields */
309    ///         .by_item();
310    ///     while let Some(item) = list.next().await.transpose()? {
311    ///         println!("{:?}", item);
312    ///     }
313    ///     Ok(())
314    /// }
315    /// ```
316    pub fn list_locations(&self) -> super::builder::storage_batch_operations::ListLocations {
317        super::builder::storage_batch_operations::ListLocations::new(self.inner.clone())
318    }
319
320    /// Gets information about a location.
321    ///
322    /// # Example
323    /// ```
324    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
325    /// use google_cloud_storagebatchoperations_v1::Result;
326    /// async fn sample(
327    ///    client: &StorageBatchOperations
328    /// ) -> Result<()> {
329    ///     let response = client.get_location()
330    ///         /* set fields */
331    ///         .send().await?;
332    ///     println!("response {:?}", response);
333    ///     Ok(())
334    /// }
335    /// ```
336    pub fn get_location(&self) -> super::builder::storage_batch_operations::GetLocation {
337        super::builder::storage_batch_operations::GetLocation::new(self.inner.clone())
338    }
339
340    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
341    ///
342    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
343    ///
344    /// # Example
345    /// ```
346    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
347    /// use google_cloud_gax::paginator::ItemPaginator as _;
348    /// use google_cloud_storagebatchoperations_v1::Result;
349    /// async fn sample(
350    ///    client: &StorageBatchOperations
351    /// ) -> Result<()> {
352    ///     let mut list = client.list_operations()
353    ///         /* set fields */
354    ///         .by_item();
355    ///     while let Some(item) = list.next().await.transpose()? {
356    ///         println!("{:?}", item);
357    ///     }
358    ///     Ok(())
359    /// }
360    /// ```
361    pub fn list_operations(&self) -> super::builder::storage_batch_operations::ListOperations {
362        super::builder::storage_batch_operations::ListOperations::new(self.inner.clone())
363    }
364
365    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
366    ///
367    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
368    ///
369    /// # Example
370    /// ```
371    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
372    /// use google_cloud_storagebatchoperations_v1::Result;
373    /// async fn sample(
374    ///    client: &StorageBatchOperations
375    /// ) -> Result<()> {
376    ///     let response = client.get_operation()
377    ///         /* set fields */
378    ///         .send().await?;
379    ///     println!("response {:?}", response);
380    ///     Ok(())
381    /// }
382    /// ```
383    pub fn get_operation(&self) -> super::builder::storage_batch_operations::GetOperation {
384        super::builder::storage_batch_operations::GetOperation::new(self.inner.clone())
385    }
386
387    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
388    ///
389    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
390    ///
391    /// # Example
392    /// ```
393    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
394    /// use google_cloud_storagebatchoperations_v1::Result;
395    /// async fn sample(
396    ///    client: &StorageBatchOperations
397    /// ) -> Result<()> {
398    ///     client.delete_operation()
399    ///         /* set fields */
400    ///         .send().await?;
401    ///     Ok(())
402    /// }
403    /// ```
404    pub fn delete_operation(&self) -> super::builder::storage_batch_operations::DeleteOperation {
405        super::builder::storage_batch_operations::DeleteOperation::new(self.inner.clone())
406    }
407
408    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
409    ///
410    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
411    ///
412    /// # Example
413    /// ```
414    /// # use google_cloud_storagebatchoperations_v1::client::StorageBatchOperations;
415    /// use google_cloud_storagebatchoperations_v1::Result;
416    /// async fn sample(
417    ///    client: &StorageBatchOperations
418    /// ) -> Result<()> {
419    ///     client.cancel_operation()
420    ///         /* set fields */
421    ///         .send().await?;
422    ///     Ok(())
423    /// }
424    /// ```
425    pub fn cancel_operation(&self) -> super::builder::storage_batch_operations::CancelOperation {
426        super::builder::storage_batch_operations::CancelOperation::new(self.inner.clone())
427    }
428}