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