Skip to main content

google_cloud_datastore_admin_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 Datastore API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
24/// use google_cloud_lro::Poller;
25/// # async fn sample() -> Result<(), Box<dyn std::error::Error>> {
26///     let client = DatastoreAdmin::builder().build().await?;
27///     let response = client.export_entities()
28///         /* set fields */
29///         .poller().until_done().await?;
30///     println!("response {:?}", response);
31/// # Ok(()) }
32/// ```
33///
34/// # Service Description
35///
36/// Google Cloud Datastore Admin API
37///
38/// The Datastore Admin API provides several admin services for Cloud Datastore.
39///
40/// Concepts: Project, namespace, kind, and entity as defined in the Google Cloud
41/// Datastore API.
42///
43/// Operation: An Operation represents work being performed in the background.
44///
45/// EntityFilter: Allows specifying a subset of entities in a project. This is
46/// specified as a combination of kinds and namespaces (either or both of which
47/// may be all).
48///
49/// Export/Import Service:
50///
51/// - The Export/Import service provides the ability to copy all or a subset of
52///   entities to/from Google Cloud Storage.
53/// - Exported data may be imported into Cloud Datastore for any Google Cloud
54///   Platform project. It is not restricted to the export source project. It is
55///   possible to export from one project and then import into another.
56/// - Exported data can also be loaded into Google BigQuery for analysis.
57/// - Exports and imports are performed asynchronously. An Operation resource is
58///   created for each export/import. The state (including any errors encountered)
59///   of the export/import may be queried via the Operation resource.
60///
61/// Index Service:
62///
63/// - The index service manages Cloud Datastore composite indexes.
64/// - Index creation and deletion are performed asynchronously.
65///   An Operation resource is created for each such asynchronous operation.
66///   The state of the operation (including any errors encountered)
67///   may be queried via the Operation resource.
68///
69/// Operation Service:
70///
71/// - The Operations collection provides a record of actions performed for the
72///   specified project (including any operations in progress). Operations are not
73///   created directly but through calls on other collections or resources.
74/// - An operation that is not yet done may be cancelled. The request to cancel
75///   is asynchronous and the operation may continue to run for some time after the
76///   request to cancel is made.
77/// - An operation that is done may be deleted so that it is no longer listed as
78///   part of the Operation collection.
79/// - ListOperations returns all pending operations, but not completed
80///   operations.
81/// - Operations are created by service DatastoreAdmin, but are accessed via
82///   service google.longrunning.Operations.
83///
84/// # Configuration
85///
86/// To configure `DatastoreAdmin` use the `with_*` methods in the type returned
87/// by [builder()][DatastoreAdmin::builder]. The default configuration should
88/// work for most applications. Common configuration changes include
89///
90/// * [with_endpoint()]: by default this client uses the global default endpoint
91///   (`https://datastore.googleapis.com`). Applications using regional
92///   endpoints or running in restricted networks (e.g. a network configured
93//    with [Private Google Access with VPC Service Controls]) may want to
94///   override this default.
95/// * [with_credentials()]: by default this client uses
96///   [Application Default Credentials]. Applications using custom
97///   authentication may need to override this default.
98///
99/// [with_endpoint()]: super::builder::datastore_admin::ClientBuilder::with_endpoint
100/// [with_credentials()]: super::builder::datastore_admin::ClientBuilder::with_credentials
101/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
102/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
103///
104/// # Pooling and Cloning
105///
106/// `DatastoreAdmin` holds a connection pool internally, it is advised to
107/// create one and reuse it. You do not need to wrap `DatastoreAdmin` in
108/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
109/// already uses an `Arc` internally.
110#[derive(Clone, Debug)]
111pub struct DatastoreAdmin {
112    inner: std::sync::Arc<dyn super::stub::dynamic::DatastoreAdmin>,
113}
114
115impl DatastoreAdmin {
116    /// Returns a builder for [DatastoreAdmin].
117    ///
118    /// ```
119    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
120    /// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
121    /// let client = DatastoreAdmin::builder().build().await?;
122    /// # Ok(()) }
123    /// ```
124    pub fn builder() -> super::builder::datastore_admin::ClientBuilder {
125        crate::new_client_builder(super::builder::datastore_admin::client::Factory)
126    }
127
128    /// Creates a new client from the provided stub.
129    ///
130    /// The most common case for calling this function is in tests mocking the
131    /// client's behavior.
132    pub fn from_stub<T>(stub: T) -> Self
133    where
134        T: super::stub::DatastoreAdmin + 'static,
135    {
136        Self {
137            inner: std::sync::Arc::new(stub),
138        }
139    }
140
141    pub(crate) async fn new(
142        config: gaxi::options::ClientConfig,
143    ) -> crate::ClientBuilderResult<Self> {
144        let inner = Self::build_inner(config).await?;
145        Ok(Self { inner })
146    }
147
148    async fn build_inner(
149        conf: gaxi::options::ClientConfig,
150    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::DatastoreAdmin>> {
151        if gaxi::options::tracing_enabled(&conf) {
152            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
153        }
154        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
155    }
156
157    async fn build_transport(
158        conf: gaxi::options::ClientConfig,
159    ) -> crate::ClientBuilderResult<impl super::stub::DatastoreAdmin> {
160        super::transport::DatastoreAdmin::new(conf).await
161    }
162
163    async fn build_with_tracing(
164        conf: gaxi::options::ClientConfig,
165    ) -> crate::ClientBuilderResult<impl super::stub::DatastoreAdmin> {
166        Self::build_transport(conf)
167            .await
168            .map(super::tracing::DatastoreAdmin::new)
169    }
170
171    /// Exports a copy of all or a subset of entities from Google Cloud Datastore
172    /// to another storage system, such as Google Cloud Storage. Recent updates to
173    /// entities may not be reflected in the export. The export occurs in the
174    /// background and its progress can be monitored and managed via the
175    /// Operation resource that is created. The output of an export may only be
176    /// used once the associated operation is done. If an export operation is
177    /// cancelled before completion it may leave partial data behind in Google
178    /// Cloud Storage.
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_datastore_admin_v1::client::DatastoreAdmin;
193    /// use google_cloud_lro::Poller;
194    /// use google_cloud_datastore_admin_v1::Result;
195    /// async fn sample(
196    ///    client: &DatastoreAdmin
197    /// ) -> Result<()> {
198    ///     let response = client.export_entities()
199    ///         /* set fields */
200    ///         .poller().until_done().await?;
201    ///     println!("response {:?}", response);
202    ///     Ok(())
203    /// }
204    /// ```
205    pub fn export_entities(&self) -> super::builder::datastore_admin::ExportEntities {
206        super::builder::datastore_admin::ExportEntities::new(self.inner.clone())
207    }
208
209    /// Imports entities into Google Cloud Datastore. Existing entities with the
210    /// same key are overwritten. The import occurs in the background and its
211    /// progress can be monitored and managed via the Operation resource that is
212    /// created. If an ImportEntities operation is cancelled, it is possible
213    /// that a subset of the data has already been imported to Cloud Datastore.
214    ///
215    /// # Long running operations
216    ///
217    /// This method is used to start, and/or poll a [long-running Operation].
218    /// The [Working with long-running operations] chapter in the [user guide]
219    /// covers these operations in detail.
220    ///
221    /// [long-running operation]: https://google.aip.dev/151
222    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
223    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
224    ///
225    /// # Example
226    /// ```
227    /// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
228    /// use google_cloud_lro::Poller;
229    /// use google_cloud_datastore_admin_v1::Result;
230    /// async fn sample(
231    ///    client: &DatastoreAdmin
232    /// ) -> Result<()> {
233    ///     client.import_entities()
234    ///         /* set fields */
235    ///         .poller().until_done().await?;
236    ///     Ok(())
237    /// }
238    /// ```
239    pub fn import_entities(&self) -> super::builder::datastore_admin::ImportEntities {
240        super::builder::datastore_admin::ImportEntities::new(self.inner.clone())
241    }
242
243    /// Creates the specified index.
244    /// A newly created index's initial state is `CREATING`. On completion of the
245    /// returned [google.longrunning.Operation][google.longrunning.Operation], the
246    /// state will be `READY`. If the index already exists, the call will return an
247    /// `ALREADY_EXISTS` status.
248    ///
249    /// During index creation, the process could result in an error, in which
250    /// case the index will move to the `ERROR` state. The process can be recovered
251    /// by fixing the data that caused the error, removing the index with
252    /// [delete][google.datastore.admin.v1.DatastoreAdmin.DeleteIndex], then
253    /// re-creating the index with [create]
254    /// [google.datastore.admin.v1.DatastoreAdmin.CreateIndex].
255    ///
256    /// Indexes with a single property cannot be created.
257    ///
258    /// [google.datastore.admin.v1.DatastoreAdmin.DeleteIndex]: crate::client::DatastoreAdmin::delete_index
259    /// [google.longrunning.Operation]: google_cloud_longrunning::model::Operation
260    ///
261    /// # Long running operations
262    ///
263    /// This method is used to start, and/or poll a [long-running Operation].
264    /// The [Working with long-running operations] chapter in the [user guide]
265    /// covers these operations in detail.
266    ///
267    /// [long-running operation]: https://google.aip.dev/151
268    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
269    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
270    ///
271    /// # Example
272    /// ```
273    /// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
274    /// use google_cloud_lro::Poller;
275    /// use google_cloud_datastore_admin_v1::Result;
276    /// async fn sample(
277    ///    client: &DatastoreAdmin
278    /// ) -> Result<()> {
279    ///     let response = client.create_index()
280    ///         /* set fields */
281    ///         .poller().until_done().await?;
282    ///     println!("response {:?}", response);
283    ///     Ok(())
284    /// }
285    /// ```
286    pub fn create_index(&self) -> super::builder::datastore_admin::CreateIndex {
287        super::builder::datastore_admin::CreateIndex::new(self.inner.clone())
288    }
289
290    /// Deletes an existing index.
291    /// An index can only be deleted if it is in a `READY` or `ERROR` state. On
292    /// successful execution of the request, the index will be in a `DELETING`
293    /// [state][google.datastore.admin.v1.Index.State]. And on completion of the
294    /// returned [google.longrunning.Operation][google.longrunning.Operation], the
295    /// index will be removed.
296    ///
297    /// During index deletion, the process could result in an error, in which
298    /// case the index will move to the `ERROR` state. The process can be recovered
299    /// by fixing the data that caused the error, followed by calling
300    /// [delete][google.datastore.admin.v1.DatastoreAdmin.DeleteIndex] again.
301    ///
302    /// [google.datastore.admin.v1.DatastoreAdmin.DeleteIndex]: crate::client::DatastoreAdmin::delete_index
303    /// [google.datastore.admin.v1.Index.State]: crate::model::index::State
304    /// [google.longrunning.Operation]: google_cloud_longrunning::model::Operation
305    ///
306    /// # Long running operations
307    ///
308    /// This method is used to start, and/or poll a [long-running Operation].
309    /// The [Working with long-running operations] chapter in the [user guide]
310    /// covers these operations in detail.
311    ///
312    /// [long-running operation]: https://google.aip.dev/151
313    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
314    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
315    ///
316    /// # Example
317    /// ```
318    /// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
319    /// use google_cloud_lro::Poller;
320    /// use google_cloud_datastore_admin_v1::Result;
321    /// async fn sample(
322    ///    client: &DatastoreAdmin
323    /// ) -> Result<()> {
324    ///     let response = client.delete_index()
325    ///         /* set fields */
326    ///         .poller().until_done().await?;
327    ///     println!("response {:?}", response);
328    ///     Ok(())
329    /// }
330    /// ```
331    pub fn delete_index(&self) -> super::builder::datastore_admin::DeleteIndex {
332        super::builder::datastore_admin::DeleteIndex::new(self.inner.clone())
333    }
334
335    /// Gets an index.
336    ///
337    /// # Example
338    /// ```
339    /// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
340    /// use google_cloud_datastore_admin_v1::Result;
341    /// async fn sample(
342    ///    client: &DatastoreAdmin
343    /// ) -> Result<()> {
344    ///     let response = client.get_index()
345    ///         /* set fields */
346    ///         .send().await?;
347    ///     println!("response {:?}", response);
348    ///     Ok(())
349    /// }
350    /// ```
351    pub fn get_index(&self) -> super::builder::datastore_admin::GetIndex {
352        super::builder::datastore_admin::GetIndex::new(self.inner.clone())
353    }
354
355    /// Lists the indexes that match the specified filters.  Datastore uses an
356    /// eventually consistent query to fetch the list of indexes and may
357    /// occasionally return stale results.
358    ///
359    /// # Example
360    /// ```
361    /// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
362    /// use google_cloud_gax::paginator::ItemPaginator as _;
363    /// use google_cloud_datastore_admin_v1::Result;
364    /// async fn sample(
365    ///    client: &DatastoreAdmin
366    /// ) -> Result<()> {
367    ///     let mut list = client.list_indexes()
368    ///         /* set fields */
369    ///         .by_item();
370    ///     while let Some(item) = list.next().await.transpose()? {
371    ///         println!("{:?}", item);
372    ///     }
373    ///     Ok(())
374    /// }
375    /// ```
376    pub fn list_indexes(&self) -> super::builder::datastore_admin::ListIndexes {
377        super::builder::datastore_admin::ListIndexes::new(self.inner.clone())
378    }
379
380    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
381    ///
382    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
383    ///
384    /// # Example
385    /// ```
386    /// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
387    /// use google_cloud_gax::paginator::ItemPaginator as _;
388    /// use google_cloud_datastore_admin_v1::Result;
389    /// async fn sample(
390    ///    client: &DatastoreAdmin
391    /// ) -> Result<()> {
392    ///     let mut list = client.list_operations()
393    ///         /* set fields */
394    ///         .by_item();
395    ///     while let Some(item) = list.next().await.transpose()? {
396    ///         println!("{:?}", item);
397    ///     }
398    ///     Ok(())
399    /// }
400    /// ```
401    pub fn list_operations(&self) -> super::builder::datastore_admin::ListOperations {
402        super::builder::datastore_admin::ListOperations::new(self.inner.clone())
403    }
404
405    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
406    ///
407    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
408    ///
409    /// # Example
410    /// ```
411    /// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
412    /// use google_cloud_datastore_admin_v1::Result;
413    /// async fn sample(
414    ///    client: &DatastoreAdmin
415    /// ) -> Result<()> {
416    ///     let response = client.get_operation()
417    ///         /* set fields */
418    ///         .send().await?;
419    ///     println!("response {:?}", response);
420    ///     Ok(())
421    /// }
422    /// ```
423    pub fn get_operation(&self) -> super::builder::datastore_admin::GetOperation {
424        super::builder::datastore_admin::GetOperation::new(self.inner.clone())
425    }
426
427    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
428    ///
429    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
430    ///
431    /// # Example
432    /// ```
433    /// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
434    /// use google_cloud_datastore_admin_v1::Result;
435    /// async fn sample(
436    ///    client: &DatastoreAdmin
437    /// ) -> Result<()> {
438    ///     client.delete_operation()
439    ///         /* set fields */
440    ///         .send().await?;
441    ///     Ok(())
442    /// }
443    /// ```
444    pub fn delete_operation(&self) -> super::builder::datastore_admin::DeleteOperation {
445        super::builder::datastore_admin::DeleteOperation::new(self.inner.clone())
446    }
447
448    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
449    ///
450    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
451    ///
452    /// # Example
453    /// ```
454    /// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
455    /// use google_cloud_datastore_admin_v1::Result;
456    /// async fn sample(
457    ///    client: &DatastoreAdmin
458    /// ) -> Result<()> {
459    ///     client.cancel_operation()
460    ///         /* set fields */
461    ///         .send().await?;
462    ///     Ok(())
463    /// }
464    /// ```
465    pub fn cancel_operation(&self) -> super::builder::datastore_admin::CancelOperation {
466        super::builder::datastore_admin::CancelOperation::new(self.inner.clone())
467    }
468}