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