Skip to main content

google_cloud_bigquery_datatransfer_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 BigQuery Data Transfer API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
24/// use google_cloud_gax::paginator::ItemPaginator as _;
25/// # async fn sample() -> Result<(), Box<dyn std::error::Error>> {
26///     let client = DataTransferService::builder().build().await?;
27///     let parent = "parent_value";
28///     let mut list = client.list_data_sources()
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/// This API allows users to manage their data transfers into BigQuery.
40///
41/// # Configuration
42///
43/// To configure `DataTransferService` use the `with_*` methods in the type returned
44/// by [builder()][DataTransferService::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://bigquerydatatransfer.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::data_transfer_service::ClientBuilder::with_endpoint
57/// [with_credentials()]: super::builder::data_transfer_service::ClientBuilder::with_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/// `DataTransferService` holds a connection pool internally, it is advised to
64/// create one and reuse it. You do not need to wrap `DataTransferService` 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 DataTransferService {
69    inner: std::sync::Arc<dyn super::stub::dynamic::DataTransferService>,
70}
71
72impl DataTransferService {
73    /// Returns a builder for [DataTransferService].
74    ///
75    /// ```
76    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
77    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
78    /// let client = DataTransferService::builder().build().await?;
79    /// # Ok(()) }
80    /// ```
81    pub fn builder() -> super::builder::data_transfer_service::ClientBuilder {
82        crate::new_client_builder(super::builder::data_transfer_service::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::DataTransferService + '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    ) -> crate::ClientBuilderResult<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    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::DataTransferService>>
108    {
109        if gaxi::options::tracing_enabled(&conf) {
110            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
111        }
112        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
113    }
114
115    async fn build_transport(
116        conf: gaxi::options::ClientConfig,
117    ) -> crate::ClientBuilderResult<impl super::stub::DataTransferService> {
118        super::transport::DataTransferService::new(conf).await
119    }
120
121    async fn build_with_tracing(
122        conf: gaxi::options::ClientConfig,
123    ) -> crate::ClientBuilderResult<impl super::stub::DataTransferService> {
124        Self::build_transport(conf)
125            .await
126            .map(super::tracing::DataTransferService::new)
127    }
128
129    /// Retrieves a supported data source and returns its settings.
130    ///
131    /// # Example
132    /// ```
133    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
134    /// use google_cloud_bigquery_datatransfer_v1::Result;
135    /// async fn sample(
136    ///    client: &DataTransferService, name: &str
137    /// ) -> Result<()> {
138    ///     let response = client.get_data_source()
139    ///         .set_name(name)
140    ///         .send().await?;
141    ///     println!("response {:?}", response);
142    ///     Ok(())
143    /// }
144    /// ```
145    pub fn get_data_source(&self) -> super::builder::data_transfer_service::GetDataSource {
146        super::builder::data_transfer_service::GetDataSource::new(self.inner.clone())
147    }
148
149    /// Lists supported data sources and returns their settings.
150    ///
151    /// # Example
152    /// ```
153    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
154    /// use google_cloud_gax::paginator::ItemPaginator as _;
155    /// use google_cloud_bigquery_datatransfer_v1::Result;
156    /// async fn sample(
157    ///    client: &DataTransferService, parent: &str
158    /// ) -> Result<()> {
159    ///     let mut list = client.list_data_sources()
160    ///         .set_parent(parent)
161    ///         .by_item();
162    ///     while let Some(item) = list.next().await.transpose()? {
163    ///         println!("{:?}", item);
164    ///     }
165    ///     Ok(())
166    /// }
167    /// ```
168    pub fn list_data_sources(&self) -> super::builder::data_transfer_service::ListDataSources {
169        super::builder::data_transfer_service::ListDataSources::new(self.inner.clone())
170    }
171
172    /// Creates a new data transfer configuration.
173    ///
174    /// # Example
175    /// ```
176    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
177    /// use google_cloud_bigquery_datatransfer_v1::model::TransferConfig;
178    /// use google_cloud_bigquery_datatransfer_v1::Result;
179    /// async fn sample(
180    ///    client: &DataTransferService, parent: &str
181    /// ) -> Result<()> {
182    ///     let response = client.create_transfer_config()
183    ///         .set_parent(parent)
184    ///         .set_transfer_config(
185    ///             TransferConfig::new()/* set fields */
186    ///         )
187    ///         .send().await?;
188    ///     println!("response {:?}", response);
189    ///     Ok(())
190    /// }
191    /// ```
192    pub fn create_transfer_config(
193        &self,
194    ) -> super::builder::data_transfer_service::CreateTransferConfig {
195        super::builder::data_transfer_service::CreateTransferConfig::new(self.inner.clone())
196    }
197
198    /// Updates a data transfer configuration.
199    /// All fields must be set, even if they are not updated.
200    ///
201    /// # Example
202    /// ```
203    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
204    /// # extern crate wkt as google_cloud_wkt;
205    /// use google_cloud_wkt::FieldMask;
206    /// use google_cloud_bigquery_datatransfer_v1::model::TransferConfig;
207    /// use google_cloud_bigquery_datatransfer_v1::Result;
208    /// async fn sample(
209    ///    client: &DataTransferService, name: &str
210    /// ) -> Result<()> {
211    ///     let response = client.update_transfer_config()
212    ///         .set_transfer_config(
213    ///             TransferConfig::new().set_name(name)/* set fields */
214    ///         )
215    ///         .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
216    ///         .send().await?;
217    ///     println!("response {:?}", response);
218    ///     Ok(())
219    /// }
220    /// ```
221    pub fn update_transfer_config(
222        &self,
223    ) -> super::builder::data_transfer_service::UpdateTransferConfig {
224        super::builder::data_transfer_service::UpdateTransferConfig::new(self.inner.clone())
225    }
226
227    /// Deletes a data transfer configuration, including any associated transfer
228    /// runs and logs.
229    ///
230    /// # Example
231    /// ```
232    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
233    /// use google_cloud_bigquery_datatransfer_v1::Result;
234    /// async fn sample(
235    ///    client: &DataTransferService, name: &str
236    /// ) -> Result<()> {
237    ///     client.delete_transfer_config()
238    ///         .set_name(name)
239    ///         .send().await?;
240    ///     Ok(())
241    /// }
242    /// ```
243    pub fn delete_transfer_config(
244        &self,
245    ) -> super::builder::data_transfer_service::DeleteTransferConfig {
246        super::builder::data_transfer_service::DeleteTransferConfig::new(self.inner.clone())
247    }
248
249    /// Returns information about a data transfer config.
250    ///
251    /// # Example
252    /// ```
253    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
254    /// use google_cloud_bigquery_datatransfer_v1::Result;
255    /// async fn sample(
256    ///    client: &DataTransferService, name: &str
257    /// ) -> Result<()> {
258    ///     let response = client.get_transfer_config()
259    ///         .set_name(name)
260    ///         .send().await?;
261    ///     println!("response {:?}", response);
262    ///     Ok(())
263    /// }
264    /// ```
265    pub fn get_transfer_config(&self) -> super::builder::data_transfer_service::GetTransferConfig {
266        super::builder::data_transfer_service::GetTransferConfig::new(self.inner.clone())
267    }
268
269    /// Returns information about all transfer configs owned by a project in the
270    /// specified location.
271    ///
272    /// # Example
273    /// ```
274    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
275    /// use google_cloud_gax::paginator::ItemPaginator as _;
276    /// use google_cloud_bigquery_datatransfer_v1::Result;
277    /// async fn sample(
278    ///    client: &DataTransferService, parent: &str
279    /// ) -> Result<()> {
280    ///     let mut list = client.list_transfer_configs()
281    ///         .set_parent(parent)
282    ///         .by_item();
283    ///     while let Some(item) = list.next().await.transpose()? {
284    ///         println!("{:?}", item);
285    ///     }
286    ///     Ok(())
287    /// }
288    /// ```
289    pub fn list_transfer_configs(
290        &self,
291    ) -> super::builder::data_transfer_service::ListTransferConfigs {
292        super::builder::data_transfer_service::ListTransferConfigs::new(self.inner.clone())
293    }
294
295    /// Creates transfer runs for a time range [start_time, end_time].
296    /// For each date - or whatever granularity the data source supports - in the
297    /// range, one transfer run is created.
298    /// Note that runs are created per UTC time in the time range.
299    /// DEPRECATED: use StartManualTransferRuns instead.
300    ///
301    /// # Example
302    /// ```
303    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
304    /// use google_cloud_bigquery_datatransfer_v1::Result;
305    /// async fn sample(
306    ///    client: &DataTransferService
307    /// ) -> Result<()> {
308    ///     let response = client.schedule_transfer_runs()
309    ///         /* set fields */
310    ///         .send().await?;
311    ///     println!("response {:?}", response);
312    ///     Ok(())
313    /// }
314    /// ```
315    #[deprecated]
316    pub fn schedule_transfer_runs(
317        &self,
318    ) -> super::builder::data_transfer_service::ScheduleTransferRuns {
319        super::builder::data_transfer_service::ScheduleTransferRuns::new(self.inner.clone())
320    }
321
322    /// Start manual transfer runs to be executed now with schedule_time equal to
323    /// current time. The transfer runs can be created for a time range where the
324    /// run_time is between start_time (inclusive) and end_time (exclusive), or for
325    /// a specific run_time.
326    ///
327    /// # Example
328    /// ```
329    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
330    /// use google_cloud_bigquery_datatransfer_v1::Result;
331    /// async fn sample(
332    ///    client: &DataTransferService
333    /// ) -> Result<()> {
334    ///     let response = client.start_manual_transfer_runs()
335    ///         /* set fields */
336    ///         .send().await?;
337    ///     println!("response {:?}", response);
338    ///     Ok(())
339    /// }
340    /// ```
341    pub fn start_manual_transfer_runs(
342        &self,
343    ) -> super::builder::data_transfer_service::StartManualTransferRuns {
344        super::builder::data_transfer_service::StartManualTransferRuns::new(self.inner.clone())
345    }
346
347    /// Returns information about the particular transfer run.
348    ///
349    /// # Example
350    /// ```
351    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
352    /// use google_cloud_bigquery_datatransfer_v1::Result;
353    /// async fn sample(
354    ///    client: &DataTransferService, name: &str
355    /// ) -> Result<()> {
356    ///     let response = client.get_transfer_run()
357    ///         .set_name(name)
358    ///         .send().await?;
359    ///     println!("response {:?}", response);
360    ///     Ok(())
361    /// }
362    /// ```
363    pub fn get_transfer_run(&self) -> super::builder::data_transfer_service::GetTransferRun {
364        super::builder::data_transfer_service::GetTransferRun::new(self.inner.clone())
365    }
366
367    /// Deletes the specified transfer run.
368    ///
369    /// # Example
370    /// ```
371    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
372    /// use google_cloud_bigquery_datatransfer_v1::Result;
373    /// async fn sample(
374    ///    client: &DataTransferService, name: &str
375    /// ) -> Result<()> {
376    ///     client.delete_transfer_run()
377    ///         .set_name(name)
378    ///         .send().await?;
379    ///     Ok(())
380    /// }
381    /// ```
382    pub fn delete_transfer_run(&self) -> super::builder::data_transfer_service::DeleteTransferRun {
383        super::builder::data_transfer_service::DeleteTransferRun::new(self.inner.clone())
384    }
385
386    /// Returns information about running and completed transfer runs.
387    ///
388    /// # Example
389    /// ```
390    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
391    /// use google_cloud_gax::paginator::ItemPaginator as _;
392    /// use google_cloud_bigquery_datatransfer_v1::Result;
393    /// async fn sample(
394    ///    client: &DataTransferService, parent: &str
395    /// ) -> Result<()> {
396    ///     let mut list = client.list_transfer_runs()
397    ///         .set_parent(parent)
398    ///         .by_item();
399    ///     while let Some(item) = list.next().await.transpose()? {
400    ///         println!("{:?}", item);
401    ///     }
402    ///     Ok(())
403    /// }
404    /// ```
405    pub fn list_transfer_runs(&self) -> super::builder::data_transfer_service::ListTransferRuns {
406        super::builder::data_transfer_service::ListTransferRuns::new(self.inner.clone())
407    }
408
409    /// Returns log messages for the transfer run.
410    ///
411    /// # Example
412    /// ```
413    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
414    /// use google_cloud_gax::paginator::ItemPaginator as _;
415    /// use google_cloud_bigquery_datatransfer_v1::Result;
416    /// async fn sample(
417    ///    client: &DataTransferService
418    /// ) -> Result<()> {
419    ///     let mut list = client.list_transfer_logs()
420    ///         /* set fields */
421    ///         .by_item();
422    ///     while let Some(item) = list.next().await.transpose()? {
423    ///         println!("{:?}", item);
424    ///     }
425    ///     Ok(())
426    /// }
427    /// ```
428    pub fn list_transfer_logs(&self) -> super::builder::data_transfer_service::ListTransferLogs {
429        super::builder::data_transfer_service::ListTransferLogs::new(self.inner.clone())
430    }
431
432    /// Returns true if valid credentials exist for the given data source and
433    /// requesting user.
434    ///
435    /// # Example
436    /// ```
437    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
438    /// use google_cloud_bigquery_datatransfer_v1::Result;
439    /// async fn sample(
440    ///    client: &DataTransferService
441    /// ) -> Result<()> {
442    ///     let response = client.check_valid_creds()
443    ///         /* set fields */
444    ///         .send().await?;
445    ///     println!("response {:?}", response);
446    ///     Ok(())
447    /// }
448    /// ```
449    pub fn check_valid_creds(&self) -> super::builder::data_transfer_service::CheckValidCreds {
450        super::builder::data_transfer_service::CheckValidCreds::new(self.inner.clone())
451    }
452
453    /// Enroll data sources in a user project. This allows users to create transfer
454    /// configurations for these data sources. They will also appear in the
455    /// ListDataSources RPC and as such, will appear in the
456    /// [BigQuery UI](https://console.cloud.google.com/bigquery), and the documents
457    /// can be found in the public guide for
458    /// [BigQuery Web UI](https://cloud.google.com/bigquery/bigquery-web-ui) and
459    /// [Data Transfer
460    /// Service](https://cloud.google.com/bigquery/docs/working-with-transfers).
461    ///
462    /// # Example
463    /// ```
464    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
465    /// use google_cloud_bigquery_datatransfer_v1::Result;
466    /// async fn sample(
467    ///    client: &DataTransferService
468    /// ) -> Result<()> {
469    ///     client.enroll_data_sources()
470    ///         /* set fields */
471    ///         .send().await?;
472    ///     Ok(())
473    /// }
474    /// ```
475    pub fn enroll_data_sources(&self) -> super::builder::data_transfer_service::EnrollDataSources {
476        super::builder::data_transfer_service::EnrollDataSources::new(self.inner.clone())
477    }
478
479    /// Unenroll data sources in a user project. This allows users to remove
480    /// transfer configurations for these data sources. They will no longer appear
481    /// in the ListDataSources RPC and will also no longer appear in the [BigQuery
482    /// UI](https://console.cloud.google.com/bigquery). Data transfers
483    /// configurations of unenrolled data sources will not be scheduled.
484    ///
485    /// # Example
486    /// ```
487    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
488    /// use google_cloud_bigquery_datatransfer_v1::Result;
489    /// async fn sample(
490    ///    client: &DataTransferService
491    /// ) -> Result<()> {
492    ///     client.unenroll_data_sources()
493    ///         /* set fields */
494    ///         .send().await?;
495    ///     Ok(())
496    /// }
497    /// ```
498    pub fn unenroll_data_sources(
499        &self,
500    ) -> super::builder::data_transfer_service::UnenrollDataSources {
501        super::builder::data_transfer_service::UnenrollDataSources::new(self.inner.clone())
502    }
503
504    /// Lists information about the supported locations for this service.
505    ///
506    /// # Example
507    /// ```
508    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
509    /// use google_cloud_gax::paginator::ItemPaginator as _;
510    /// use google_cloud_bigquery_datatransfer_v1::Result;
511    /// async fn sample(
512    ///    client: &DataTransferService
513    /// ) -> Result<()> {
514    ///     let mut list = client.list_locations()
515    ///         /* set fields */
516    ///         .by_item();
517    ///     while let Some(item) = list.next().await.transpose()? {
518    ///         println!("{:?}", item);
519    ///     }
520    ///     Ok(())
521    /// }
522    /// ```
523    pub fn list_locations(&self) -> super::builder::data_transfer_service::ListLocations {
524        super::builder::data_transfer_service::ListLocations::new(self.inner.clone())
525    }
526
527    /// Gets information about a location.
528    ///
529    /// # Example
530    /// ```
531    /// # use google_cloud_bigquery_datatransfer_v1::client::DataTransferService;
532    /// use google_cloud_bigquery_datatransfer_v1::Result;
533    /// async fn sample(
534    ///    client: &DataTransferService
535    /// ) -> Result<()> {
536    ///     let response = client.get_location()
537    ///         /* set fields */
538    ///         .send().await?;
539    ///     println!("response {:?}", response);
540    ///     Ok(())
541    /// }
542    /// ```
543    pub fn get_location(&self) -> super::builder::data_transfer_service::GetLocation {
544        super::builder::data_transfer_service::GetLocation::new(self.inner.clone())
545    }
546}