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