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/// # tokio_test::block_on(async {
24/// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
25/// let client = DatastoreAdmin::builder().build().await?;
26/// // use `client` to make requests to the Cloud Datastore API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Google Cloud Datastore Admin API
33///
34/// The Datastore Admin API provides several admin services for Cloud Datastore.
35///
36/// Concepts: Project, namespace, kind, and entity as defined in the Google Cloud
37/// Datastore API.
38///
39/// Operation: An Operation represents work being performed in the background.
40///
41/// EntityFilter: Allows specifying a subset of entities in a project. This is
42/// specified as a combination of kinds and namespaces (either or both of which
43/// may be all).
44///
45/// Export/Import Service:
46///
47/// - The Export/Import service provides the ability to copy all or a subset of
48/// entities to/from Google Cloud Storage.
49/// - Exported data may be imported into Cloud Datastore for any Google Cloud
50/// Platform project. It is not restricted to the export source project. It is
51/// possible to export from one project and then import into another.
52/// - Exported data can also be loaded into Google BigQuery for analysis.
53/// - Exports and imports are performed asynchronously. An Operation resource is
54/// created for each export/import. The state (including any errors encountered)
55/// of the export/import may be queried via the Operation resource.
56///
57/// Index Service:
58///
59/// - The index service manages Cloud Datastore composite indexes.
60/// - Index creation and deletion are performed asynchronously.
61/// An Operation resource is created for each such asynchronous operation.
62/// The state of the operation (including any errors encountered)
63/// may be queried via the Operation resource.
64///
65/// Operation Service:
66///
67/// - The Operations collection provides a record of actions performed for the
68/// specified project (including any operations in progress). Operations are not
69/// created directly but through calls on other collections or resources.
70/// - An operation that is not yet done may be cancelled. The request to cancel
71/// is asynchronous and the operation may continue to run for some time after the
72/// request to cancel is made.
73/// - An operation that is done may be deleted so that it is no longer listed as
74/// part of the Operation collection.
75/// - ListOperations returns all pending operations, but not completed
76/// operations.
77/// - Operations are created by service DatastoreAdmin, but are accessed via
78/// service google.longrunning.Operations.
79///
80/// # Configuration
81///
82/// To configure `DatastoreAdmin` use the `with_*` methods in the type returned
83/// by [builder()][DatastoreAdmin::builder]. The default configuration should
84/// work for most applications. Common configuration changes include
85///
86/// * [with_endpoint()]: by default this client uses the global default endpoint
87/// (`https://datastore.googleapis.com`). Applications using regional
88/// endpoints or running in restricted networks (e.g. a network configured
89// with [Private Google Access with VPC Service Controls]) may want to
90/// override this default.
91/// * [with_credentials()]: by default this client uses
92/// [Application Default Credentials]. Applications using custom
93/// authentication may need to override this default.
94///
95/// [with_endpoint()]: super::builder::datastore_admin::ClientBuilder::with_endpoint
96/// [with_credentials()]: super::builder::datastore_admin::ClientBuilder::credentials
97/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
98/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
99///
100/// # Pooling and Cloning
101///
102/// `DatastoreAdmin` holds a connection pool internally, it is advised to
103/// create one and the reuse it. You do not need to wrap `DatastoreAdmin` in
104/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
105/// already uses an `Arc` internally.
106#[derive(Clone, Debug)]
107pub struct DatastoreAdmin {
108 inner: std::sync::Arc<dyn super::stub::dynamic::DatastoreAdmin>,
109}
110
111impl DatastoreAdmin {
112 /// Returns a builder for [DatastoreAdmin].
113 ///
114 /// ```
115 /// # tokio_test::block_on(async {
116 /// # use google_cloud_datastore_admin_v1::client::DatastoreAdmin;
117 /// let client = DatastoreAdmin::builder().build().await?;
118 /// # gax::client_builder::Result::<()>::Ok(()) });
119 /// ```
120 pub fn builder() -> super::builder::datastore_admin::ClientBuilder {
121 gax::client_builder::internal::new_builder(super::builder::datastore_admin::client::Factory)
122 }
123
124 /// Creates a new client from the provided stub.
125 ///
126 /// The most common case for calling this function is in tests mocking the
127 /// client's behavior.
128 pub fn from_stub<T>(stub: T) -> Self
129 where
130 T: super::stub::DatastoreAdmin + 'static,
131 {
132 Self {
133 inner: std::sync::Arc::new(stub),
134 }
135 }
136
137 pub(crate) async fn new(
138 config: gaxi::options::ClientConfig,
139 ) -> gax::client_builder::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 ) -> gax::client_builder::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 ) -> gax::client_builder::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 ) -> gax::client_builder::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}