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
19use crate::Result;
20
21/// Implements a client for the Cloud Datastore API.
22///
23/// # Example
24/// ```
25/// # tokio_test::block_on(async {
26/// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
27/// let client = DatastoreAdmin::builder().build().await?;
28/// // use `client` to make requests to the Cloud Datastore API.
29/// # gax::Result::<()>::Ok(()) });
30/// ```
31///
32/// # Service Description
33///
34/// Google Cloud Datastore Admin API
35///
36/// The Datastore Admin API provides several admin services for Cloud Datastore.
37///
38/// Concepts: Project, namespace, kind, and entity as defined in the Google Cloud
39/// Datastore API.
40///
41/// Operation: An Operation represents work being performed in the background.
42///
43/// EntityFilter: Allows specifying a subset of entities in a project. This is
44/// specified as a combination of kinds and namespaces (either or both of which
45/// may be all).
46///
47/// Export/Import Service:
48///
49/// - The Export/Import service provides the ability to copy all or a subset of
50///   entities to/from Google Cloud Storage.
51/// - Exported data may be imported into Cloud Datastore for any Google Cloud
52///   Platform project. It is not restricted to the export source project. It is
53///   possible to export from one project and then import into another.
54/// - Exported data can also be loaded into Google BigQuery for analysis.
55/// - Exports and imports are performed asynchronously. An Operation resource is
56///   created for each export/import. The state (including any errors encountered)
57///   of the export/import may be queried via the Operation resource.
58///
59/// Index Service:
60///
61/// - The index service manages Cloud Datastore composite indexes.
62/// - Index creation and deletion are performed asynchronously.
63///   An Operation resource is created for each such asynchronous operation.
64///   The state of the operation (including any errors encountered)
65///   may be queried via the Operation resource.
66///
67/// Operation Service:
68///
69/// - The Operations collection provides a record of actions performed for the
70///   specified project (including any operations in progress). Operations are not
71///   created directly but through calls on other collections or resources.
72/// - An operation that is not yet done may be cancelled. The request to cancel
73///   is asynchronous and the operation may continue to run for some time after the
74///   request to cancel is made.
75/// - An operation that is done may be deleted so that it is no longer listed as
76///   part of the Operation collection.
77/// - ListOperations returns all pending operations, but not completed
78///   operations.
79/// - Operations are created by service DatastoreAdmin, but are accessed via
80///   service google.longrunning.Operations.
81///
82/// # Configuration
83///
84/// To configure `DatastoreAdmin` use the `with_*` methods in the type returned
85/// by [builder()][DatastoreAdmin::builder]. The default configuration should
86/// work for most applications. Common configuration changes include
87///
88/// * [with_endpoint()]: by default this client uses the global default endpoint
89///   (`https://datastore.googleapis.com`). Applications using regional
90///   endpoints or running in restricted networks (e.g. a network configured
91//    with [Private Google Access with VPC Service Controls]) may want to
92///   override this default.
93/// * [with_credentials()]: by default this client uses
94///   [Application Default Credentials]. Applications using custom
95///   authentication may need to override this default.
96///
97/// [with_endpoint()]: super::builder::datastore_admin::ClientBuilder::with_endpoint
98/// [with_credentials()]: super::builder::datastore_admin::ClientBuilder::credentials
99/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
100/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
101///
102/// # Pooling and Cloning
103///
104/// `DatastoreAdmin` holds a connection pool internally, it is advised to
105/// create one and the reuse it.  You do not need to wrap `DatastoreAdmin` in
106/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
107/// already uses an `Arc` internally.
108#[derive(Clone, Debug)]
109pub struct DatastoreAdmin {
110    inner: std::sync::Arc<dyn super::stub::dynamic::DatastoreAdmin>,
111}
112
113impl DatastoreAdmin {
114    /// Returns a builder for [DatastoreAdmin].
115    ///
116    /// ```
117    /// # tokio_test::block_on(async {
118    /// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
119    /// let client = DatastoreAdmin::builder().build().await?;
120    /// # gax::Result::<()>::Ok(()) });
121    /// ```
122    pub fn builder() -> super::builder::datastore_admin::ClientBuilder {
123        gax::client_builder::internal::new_builder(super::builder::datastore_admin::client::Factory)
124    }
125
126    /// Creates a new client from the provided stub.
127    ///
128    /// The most common case for calling this function is in tests mocking the
129    /// client's behavior.
130    pub fn from_stub<T>(stub: T) -> Self
131    where
132        T: super::stub::DatastoreAdmin + 'static,
133    {
134        Self {
135            inner: std::sync::Arc::new(stub),
136        }
137    }
138
139    pub(crate) async fn new(config: gaxi::options::ClientConfig) -> Result<Self> {
140        let inner = Self::build_inner(config).await?;
141        Ok(Self { inner })
142    }
143
144    async fn build_inner(
145        conf: gaxi::options::ClientConfig,
146    ) -> Result<std::sync::Arc<dyn super::stub::dynamic::DatastoreAdmin>> {
147        if gaxi::options::tracing_enabled(&conf) {
148            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
149        }
150        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
151    }
152
153    async fn build_transport(
154        conf: gaxi::options::ClientConfig,
155    ) -> Result<impl super::stub::DatastoreAdmin> {
156        super::transport::DatastoreAdmin::new(conf).await
157    }
158
159    async fn build_with_tracing(
160        conf: gaxi::options::ClientConfig,
161    ) -> Result<impl super::stub::DatastoreAdmin> {
162        Self::build_transport(conf)
163            .await
164            .map(super::tracing::DatastoreAdmin::new)
165    }
166
167    /// Exports a copy of all or a subset of entities from Google Cloud Datastore
168    /// to another storage system, such as Google Cloud Storage. Recent updates to
169    /// entities may not be reflected in the export. The export occurs in the
170    /// background and its progress can be monitored and managed via the
171    /// Operation resource that is created. The output of an export may only be
172    /// used once the associated operation is done. If an export operation is
173    /// cancelled before completion it may leave partial data behind in Google
174    /// Cloud Storage.
175    ///
176    /// # Long running operations
177    ///
178    /// This method is used to start, and/or poll a [long-running Operation].
179    /// The [Working with long-running operations] chapter in the [user guide]
180    /// covers these operations in detail.
181    ///
182    /// [long-running operation]: https://google.aip.dev/151
183    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
184    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
185    pub fn export_entities(&self) -> super::builder::datastore_admin::ExportEntities {
186        super::builder::datastore_admin::ExportEntities::new(self.inner.clone())
187    }
188
189    /// Imports entities into Google Cloud Datastore. Existing entities with the
190    /// same key are overwritten. The import occurs in the background and its
191    /// progress can be monitored and managed via the Operation resource that is
192    /// created. If an ImportEntities operation is cancelled, it is possible
193    /// that a subset of the data has already been imported to Cloud Datastore.
194    ///
195    /// # Long running operations
196    ///
197    /// This method is used to start, and/or poll a [long-running Operation].
198    /// The [Working with long-running operations] chapter in the [user guide]
199    /// covers these operations in detail.
200    ///
201    /// [long-running operation]: https://google.aip.dev/151
202    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
203    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
204    pub fn import_entities(&self) -> super::builder::datastore_admin::ImportEntities {
205        super::builder::datastore_admin::ImportEntities::new(self.inner.clone())
206    }
207
208    /// Creates the specified index.
209    /// A newly created index's initial state is `CREATING`. On completion of the
210    /// returned [google.longrunning.Operation][google.longrunning.Operation], the
211    /// state will be `READY`. If the index already exists, the call will return an
212    /// `ALREADY_EXISTS` status.
213    ///
214    /// During index creation, the process could result in an error, in which
215    /// case the index will move to the `ERROR` state. The process can be recovered
216    /// by fixing the data that caused the error, removing the index with
217    /// [delete][google.datastore.admin.v1.DatastoreAdmin.DeleteIndex], then
218    /// re-creating the index with [create]
219    /// [google.datastore.admin.v1.DatastoreAdmin.CreateIndex].
220    ///
221    /// Indexes with a single property cannot be created.
222    ///
223    /// [google.datastore.admin.v1.DatastoreAdmin.DeleteIndex]: crate::client::DatastoreAdmin::delete_index
224    /// [google.longrunning.Operation]: longrunning::model::Operation
225    ///
226    /// # Long running operations
227    ///
228    /// This method is used to start, and/or poll a [long-running Operation].
229    /// The [Working with long-running operations] chapter in the [user guide]
230    /// covers these operations in detail.
231    ///
232    /// [long-running operation]: https://google.aip.dev/151
233    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
234    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
235    pub fn create_index(&self) -> super::builder::datastore_admin::CreateIndex {
236        super::builder::datastore_admin::CreateIndex::new(self.inner.clone())
237    }
238
239    /// Deletes an existing index.
240    /// An index can only be deleted if it is in a `READY` or `ERROR` state. On
241    /// successful execution of the request, the index will be in a `DELETING`
242    /// [state][google.datastore.admin.v1.Index.State]. And on completion of the
243    /// returned [google.longrunning.Operation][google.longrunning.Operation], the
244    /// index will be removed.
245    ///
246    /// During index deletion, the process could result in an error, in which
247    /// case the index will move to the `ERROR` state. The process can be recovered
248    /// by fixing the data that caused the error, followed by calling
249    /// [delete][google.datastore.admin.v1.DatastoreAdmin.DeleteIndex] again.
250    ///
251    /// [google.datastore.admin.v1.DatastoreAdmin.DeleteIndex]: crate::client::DatastoreAdmin::delete_index
252    /// [google.datastore.admin.v1.Index.State]: crate::model::index::State
253    /// [google.longrunning.Operation]: longrunning::model::Operation
254    ///
255    /// # Long running operations
256    ///
257    /// This method is used to start, and/or poll a [long-running Operation].
258    /// The [Working with long-running operations] chapter in the [user guide]
259    /// covers these operations in detail.
260    ///
261    /// [long-running operation]: https://google.aip.dev/151
262    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
263    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
264    pub fn delete_index(&self) -> super::builder::datastore_admin::DeleteIndex {
265        super::builder::datastore_admin::DeleteIndex::new(self.inner.clone())
266    }
267
268    /// Gets an index.
269    pub fn get_index(&self) -> super::builder::datastore_admin::GetIndex {
270        super::builder::datastore_admin::GetIndex::new(self.inner.clone())
271    }
272
273    /// Lists the indexes that match the specified filters.  Datastore uses an
274    /// eventually consistent query to fetch the list of indexes and may
275    /// occasionally return stale results.
276    pub fn list_indexes(&self) -> super::builder::datastore_admin::ListIndexes {
277        super::builder::datastore_admin::ListIndexes::new(self.inner.clone())
278    }
279
280    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
281    ///
282    /// [google.longrunning.Operations]: longrunning::client::Operations
283    pub fn list_operations(&self) -> super::builder::datastore_admin::ListOperations {
284        super::builder::datastore_admin::ListOperations::new(self.inner.clone())
285    }
286
287    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
288    ///
289    /// [google.longrunning.Operations]: longrunning::client::Operations
290    pub fn get_operation(&self) -> super::builder::datastore_admin::GetOperation {
291        super::builder::datastore_admin::GetOperation::new(self.inner.clone())
292    }
293
294    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
295    ///
296    /// [google.longrunning.Operations]: longrunning::client::Operations
297    pub fn delete_operation(&self) -> super::builder::datastore_admin::DeleteOperation {
298        super::builder::datastore_admin::DeleteOperation::new(self.inner.clone())
299    }
300
301    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
302    ///
303    /// [google.longrunning.Operations]: longrunning::client::Operations
304    pub fn cancel_operation(&self) -> super::builder::datastore_admin::CancelOperation {
305        super::builder::datastore_admin::CancelOperation::new(self.inner.clone())
306    }
307}