1# -*- coding: utf-8 -*- 2# Copyright 2020 Google LLC 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16from collections import OrderedDict 17import functools 18import re 19from typing import Dict, Sequence, Tuple, Type, Union 20import pkg_resources 21 22from google.api_core.client_options import ClientOptions # type: ignore 23from google.api_core import exceptions as core_exceptions # type: ignore 24from google.api_core import gapic_v1 # type: ignore 25from google.api_core import retry as retries # type: ignore 26from google.auth import credentials as ga_credentials # type: ignore 27from google.oauth2 import service_account # type: ignore 28 29OptionalRetry = Union[retries.Retry, object] 30 31from google.api_core import operation # type: ignore 32from google.api_core import operation_async # type: ignore 33from google.cloud.datastore_admin_v1.services.datastore_admin import pagers 34from google.cloud.datastore_admin_v1.types import datastore_admin 35from google.cloud.datastore_admin_v1.types import index 36from google.protobuf import empty_pb2 # type: ignore 37from .transports.base import DatastoreAdminTransport, DEFAULT_CLIENT_INFO 38from .transports.grpc_asyncio import DatastoreAdminGrpcAsyncIOTransport 39from .client import DatastoreAdminClient 40 41 42class DatastoreAdminAsyncClient: 43 """Google Cloud Datastore Admin API 44 The Datastore Admin API provides several admin services for 45 Cloud Datastore. 46 ----------------------------------------------------------------------------- 47 ## Concepts 48 49 Project, namespace, kind, and entity as defined in the Google 50 Cloud Datastore API. 51 52 Operation: An Operation represents work being performed in the 53 background. 54 EntityFilter: Allows specifying a subset of entities in a 55 project. This is specified as a combination of kinds and 56 namespaces (either or both of which may be all). 57 58 ----------------------------------------------------------------------------- 59 ## Services 60 61 # Export/Import 62 63 The Export/Import service provides the ability to copy all or a 64 subset of entities to/from Google Cloud Storage. 65 66 Exported data may be imported into Cloud Datastore for any 67 Google Cloud Platform project. It is not restricted to the 68 export source project. It is possible to export from one project 69 and then import into another. 70 Exported data can also be loaded into Google BigQuery for 71 analysis. 72 Exports and imports are performed asynchronously. An Operation 73 resource is created for each export/import. The state (including 74 any errors encountered) of the export/import may be queried via 75 the Operation resource. 76 # Index 77 78 The index service manages Cloud Datastore composite indexes. 79 Index creation and deletion are performed asynchronously. An 80 Operation resource is created for each such asynchronous 81 operation. The state of the operation (including any errors 82 encountered) may be queried via the Operation resource. 83 84 # Operation 85 86 The Operations collection provides a record of actions performed 87 for the specified project (including any operations in 88 progress). Operations are not created directly but through calls 89 on other collections or resources. 90 An operation that is not yet done may be cancelled. The request 91 to cancel is asynchronous and the operation may continue to run 92 for some time after the request to cancel is made. 93 94 An operation that is done may be deleted so that it is no longer 95 listed as part of the Operation collection. 96 97 ListOperations returns all pending operations, but not completed 98 operations. 99 Operations are created by service DatastoreAdmin, 100 but are accessed via service google.longrunning.Operations. 101 """ 102 103 _client: DatastoreAdminClient 104 105 DEFAULT_ENDPOINT = DatastoreAdminClient.DEFAULT_ENDPOINT 106 DEFAULT_MTLS_ENDPOINT = DatastoreAdminClient.DEFAULT_MTLS_ENDPOINT 107 108 common_billing_account_path = staticmethod( 109 DatastoreAdminClient.common_billing_account_path 110 ) 111 parse_common_billing_account_path = staticmethod( 112 DatastoreAdminClient.parse_common_billing_account_path 113 ) 114 common_folder_path = staticmethod(DatastoreAdminClient.common_folder_path) 115 parse_common_folder_path = staticmethod( 116 DatastoreAdminClient.parse_common_folder_path 117 ) 118 common_organization_path = staticmethod( 119 DatastoreAdminClient.common_organization_path 120 ) 121 parse_common_organization_path = staticmethod( 122 DatastoreAdminClient.parse_common_organization_path 123 ) 124 common_project_path = staticmethod(DatastoreAdminClient.common_project_path) 125 parse_common_project_path = staticmethod( 126 DatastoreAdminClient.parse_common_project_path 127 ) 128 common_location_path = staticmethod(DatastoreAdminClient.common_location_path) 129 parse_common_location_path = staticmethod( 130 DatastoreAdminClient.parse_common_location_path 131 ) 132 133 @classmethod 134 def from_service_account_info(cls, info: dict, *args, **kwargs): 135 """Creates an instance of this client using the provided credentials 136 info. 137 138 Args: 139 info (dict): The service account private key info. 140 args: Additional arguments to pass to the constructor. 141 kwargs: Additional arguments to pass to the constructor. 142 143 Returns: 144 DatastoreAdminAsyncClient: The constructed client. 145 """ 146 return DatastoreAdminClient.from_service_account_info.__func__(DatastoreAdminAsyncClient, info, *args, **kwargs) # type: ignore 147 148 @classmethod 149 def from_service_account_file(cls, filename: str, *args, **kwargs): 150 """Creates an instance of this client using the provided credentials 151 file. 152 153 Args: 154 filename (str): The path to the service account private key json 155 file. 156 args: Additional arguments to pass to the constructor. 157 kwargs: Additional arguments to pass to the constructor. 158 159 Returns: 160 DatastoreAdminAsyncClient: The constructed client. 161 """ 162 return DatastoreAdminClient.from_service_account_file.__func__(DatastoreAdminAsyncClient, filename, *args, **kwargs) # type: ignore 163 164 from_service_account_json = from_service_account_file 165 166 @property 167 def transport(self) -> DatastoreAdminTransport: 168 """Returns the transport used by the client instance. 169 170 Returns: 171 DatastoreAdminTransport: The transport used by the client instance. 172 """ 173 return self._client.transport 174 175 get_transport_class = functools.partial( 176 type(DatastoreAdminClient).get_transport_class, type(DatastoreAdminClient) 177 ) 178 179 def __init__( 180 self, 181 *, 182 credentials: ga_credentials.Credentials = None, 183 transport: Union[str, DatastoreAdminTransport] = "grpc_asyncio", 184 client_options: ClientOptions = None, 185 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 186 ) -> None: 187 """Instantiates the datastore admin client. 188 189 Args: 190 credentials (Optional[google.auth.credentials.Credentials]): The 191 authorization credentials to attach to requests. These 192 credentials identify the application to the service; if none 193 are specified, the client will attempt to ascertain the 194 credentials from the environment. 195 transport (Union[str, ~.DatastoreAdminTransport]): The 196 transport to use. If set to None, a transport is chosen 197 automatically. 198 client_options (ClientOptions): Custom options for the client. It 199 won't take effect if a ``transport`` instance is provided. 200 (1) The ``api_endpoint`` property can be used to override the 201 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT 202 environment variable can also be used to override the endpoint: 203 "always" (always use the default mTLS endpoint), "never" (always 204 use the default regular endpoint) and "auto" (auto switch to the 205 default mTLS endpoint if client certificate is present, this is 206 the default value). However, the ``api_endpoint`` property takes 207 precedence if provided. 208 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 209 is "true", then the ``client_cert_source`` property can be used 210 to provide client certificate for mutual TLS transport. If 211 not provided, the default SSL client certificate will be used if 212 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 213 set, no client certificate will be used. 214 215 Raises: 216 google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport 217 creation failed for any reason. 218 """ 219 self._client = DatastoreAdminClient( 220 credentials=credentials, 221 transport=transport, 222 client_options=client_options, 223 client_info=client_info, 224 ) 225 226 async def export_entities( 227 self, 228 request: Union[datastore_admin.ExportEntitiesRequest, dict] = None, 229 *, 230 project_id: str = None, 231 labels: Sequence[datastore_admin.ExportEntitiesRequest.LabelsEntry] = None, 232 entity_filter: datastore_admin.EntityFilter = None, 233 output_url_prefix: str = None, 234 retry: OptionalRetry = gapic_v1.method.DEFAULT, 235 timeout: float = None, 236 metadata: Sequence[Tuple[str, str]] = (), 237 ) -> operation_async.AsyncOperation: 238 r"""Exports a copy of all or a subset of entities from 239 Google Cloud Datastore to another storage system, such 240 as Google Cloud Storage. Recent updates to entities may 241 not be reflected in the export. The export occurs in the 242 background and its progress can be monitored and managed 243 via the Operation resource that is created. The output 244 of an export may only be used once the associated 245 operation is done. If an export operation is cancelled 246 before completion it may leave partial data behind in 247 Google Cloud Storage. 248 249 Args: 250 request (Union[google.cloud.datastore_admin_v1.types.ExportEntitiesRequest, dict]): 251 The request object. The request for 252 [google.datastore.admin.v1.DatastoreAdmin.ExportEntities][google.datastore.admin.v1.DatastoreAdmin.ExportEntities]. 253 project_id (:class:`str`): 254 Required. Project ID against which to 255 make the request. 256 257 This corresponds to the ``project_id`` field 258 on the ``request`` instance; if ``request`` is provided, this 259 should not be set. 260 labels (:class:`Sequence[google.cloud.datastore_admin_v1.types.ExportEntitiesRequest.LabelsEntry]`): 261 Client-assigned labels. 262 This corresponds to the ``labels`` field 263 on the ``request`` instance; if ``request`` is provided, this 264 should not be set. 265 entity_filter (:class:`google.cloud.datastore_admin_v1.types.EntityFilter`): 266 Description of what data from the 267 project is included in the export. 268 269 This corresponds to the ``entity_filter`` field 270 on the ``request`` instance; if ``request`` is provided, this 271 should not be set. 272 output_url_prefix (:class:`str`): 273 Required. Location for the export metadata and data 274 files. 275 276 The full resource URL of the external storage location. 277 Currently, only Google Cloud Storage is supported. So 278 output_url_prefix should be of the form: 279 ``gs://BUCKET_NAME[/NAMESPACE_PATH]``, where 280 ``BUCKET_NAME`` is the name of the Cloud Storage bucket 281 and ``NAMESPACE_PATH`` is an optional Cloud Storage 282 namespace path (this is not a Cloud Datastore 283 namespace). For more information about Cloud Storage 284 namespace paths, see `Object name 285 considerations <https://cloud.google.com/storage/docs/naming#object-considerations>`__. 286 287 The resulting files will be nested deeper than the 288 specified URL prefix. The final output URL will be 289 provided in the 290 [google.datastore.admin.v1.ExportEntitiesResponse.output_url][google.datastore.admin.v1.ExportEntitiesResponse.output_url] 291 field. That value should be used for subsequent 292 ImportEntities operations. 293 294 By nesting the data files deeper, the same Cloud Storage 295 bucket can be used in multiple ExportEntities operations 296 without conflict. 297 298 This corresponds to the ``output_url_prefix`` field 299 on the ``request`` instance; if ``request`` is provided, this 300 should not be set. 301 retry (google.api_core.retry.Retry): Designation of what errors, if any, 302 should be retried. 303 timeout (float): The timeout for this request. 304 metadata (Sequence[Tuple[str, str]]): Strings which should be 305 sent along with the request as metadata. 306 307 Returns: 308 google.api_core.operation_async.AsyncOperation: 309 An object representing a long-running operation. 310 311 The result type for the operation will be :class:`google.cloud.datastore_admin_v1.types.ExportEntitiesResponse` The response for 312 [google.datastore.admin.v1.DatastoreAdmin.ExportEntities][google.datastore.admin.v1.DatastoreAdmin.ExportEntities]. 313 314 """ 315 # Create or coerce a protobuf request object. 316 # Sanity check: If we got a request object, we should *not* have 317 # gotten any keyword arguments that map to the request. 318 has_flattened_params = any( 319 [project_id, labels, entity_filter, output_url_prefix] 320 ) 321 if request is not None and has_flattened_params: 322 raise ValueError( 323 "If the `request` argument is set, then none of " 324 "the individual field arguments should be set." 325 ) 326 327 request = datastore_admin.ExportEntitiesRequest(request) 328 329 # If we have keyword arguments corresponding to fields on the 330 # request, apply these. 331 if project_id is not None: 332 request.project_id = project_id 333 if entity_filter is not None: 334 request.entity_filter = entity_filter 335 if output_url_prefix is not None: 336 request.output_url_prefix = output_url_prefix 337 338 if labels: 339 request.labels.update(labels) 340 341 # Wrap the RPC method; this adds retry and timeout information, 342 # and friendly error handling. 343 rpc = gapic_v1.method_async.wrap_method( 344 self._client._transport.export_entities, 345 default_timeout=60.0, 346 client_info=DEFAULT_CLIENT_INFO, 347 ) 348 349 # Send the request. 350 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 351 352 # Wrap the response in an operation future. 353 response = operation_async.from_gapic( 354 response, 355 self._client._transport.operations_client, 356 datastore_admin.ExportEntitiesResponse, 357 metadata_type=datastore_admin.ExportEntitiesMetadata, 358 ) 359 360 # Done; return the response. 361 return response 362 363 async def import_entities( 364 self, 365 request: Union[datastore_admin.ImportEntitiesRequest, dict] = None, 366 *, 367 project_id: str = None, 368 labels: Sequence[datastore_admin.ImportEntitiesRequest.LabelsEntry] = None, 369 input_url: str = None, 370 entity_filter: datastore_admin.EntityFilter = None, 371 retry: OptionalRetry = gapic_v1.method.DEFAULT, 372 timeout: float = None, 373 metadata: Sequence[Tuple[str, str]] = (), 374 ) -> operation_async.AsyncOperation: 375 r"""Imports entities into Google Cloud Datastore. 376 Existing entities with the same key are overwritten. The 377 import occurs in the background and its progress can be 378 monitored and managed via the Operation resource that is 379 created. If an ImportEntities operation is cancelled, it 380 is possible that a subset of the data has already been 381 imported to Cloud Datastore. 382 383 Args: 384 request (Union[google.cloud.datastore_admin_v1.types.ImportEntitiesRequest, dict]): 385 The request object. The request for 386 [google.datastore.admin.v1.DatastoreAdmin.ImportEntities][google.datastore.admin.v1.DatastoreAdmin.ImportEntities]. 387 project_id (:class:`str`): 388 Required. Project ID against which to 389 make the request. 390 391 This corresponds to the ``project_id`` field 392 on the ``request`` instance; if ``request`` is provided, this 393 should not be set. 394 labels (:class:`Sequence[google.cloud.datastore_admin_v1.types.ImportEntitiesRequest.LabelsEntry]`): 395 Client-assigned labels. 396 This corresponds to the ``labels`` field 397 on the ``request`` instance; if ``request`` is provided, this 398 should not be set. 399 input_url (:class:`str`): 400 Required. The full resource URL of the external storage 401 location. Currently, only Google Cloud Storage is 402 supported. So input_url should be of the form: 403 ``gs://BUCKET_NAME[/NAMESPACE_PATH]/OVERALL_EXPORT_METADATA_FILE``, 404 where ``BUCKET_NAME`` is the name of the Cloud Storage 405 bucket, ``NAMESPACE_PATH`` is an optional Cloud Storage 406 namespace path (this is not a Cloud Datastore 407 namespace), and ``OVERALL_EXPORT_METADATA_FILE`` is the 408 metadata file written by the ExportEntities operation. 409 For more information about Cloud Storage namespace 410 paths, see `Object name 411 considerations <https://cloud.google.com/storage/docs/naming#object-considerations>`__. 412 413 For more information, see 414 [google.datastore.admin.v1.ExportEntitiesResponse.output_url][google.datastore.admin.v1.ExportEntitiesResponse.output_url]. 415 416 This corresponds to the ``input_url`` field 417 on the ``request`` instance; if ``request`` is provided, this 418 should not be set. 419 entity_filter (:class:`google.cloud.datastore_admin_v1.types.EntityFilter`): 420 Optionally specify which kinds/namespaces are to be 421 imported. If provided, the list must be a subset of the 422 EntityFilter used in creating the export, otherwise a 423 FAILED_PRECONDITION error will be returned. If no filter 424 is specified then all entities from the export are 425 imported. 426 427 This corresponds to the ``entity_filter`` field 428 on the ``request`` instance; if ``request`` is provided, this 429 should not be set. 430 retry (google.api_core.retry.Retry): Designation of what errors, if any, 431 should be retried. 432 timeout (float): The timeout for this request. 433 metadata (Sequence[Tuple[str, str]]): Strings which should be 434 sent along with the request as metadata. 435 436 Returns: 437 google.api_core.operation_async.AsyncOperation: 438 An object representing a long-running operation. 439 440 The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated 441 empty messages in your APIs. A typical example is to 442 use it as the request or the response type of an API 443 method. For instance: 444 445 service Foo { 446 rpc Bar(google.protobuf.Empty) returns 447 (google.protobuf.Empty); 448 449 } 450 451 The JSON representation for Empty is empty JSON 452 object {}. 453 454 """ 455 # Create or coerce a protobuf request object. 456 # Sanity check: If we got a request object, we should *not* have 457 # gotten any keyword arguments that map to the request. 458 has_flattened_params = any([project_id, labels, input_url, entity_filter]) 459 if request is not None and has_flattened_params: 460 raise ValueError( 461 "If the `request` argument is set, then none of " 462 "the individual field arguments should be set." 463 ) 464 465 request = datastore_admin.ImportEntitiesRequest(request) 466 467 # If we have keyword arguments corresponding to fields on the 468 # request, apply these. 469 if project_id is not None: 470 request.project_id = project_id 471 if input_url is not None: 472 request.input_url = input_url 473 if entity_filter is not None: 474 request.entity_filter = entity_filter 475 476 if labels: 477 request.labels.update(labels) 478 479 # Wrap the RPC method; this adds retry and timeout information, 480 # and friendly error handling. 481 rpc = gapic_v1.method_async.wrap_method( 482 self._client._transport.import_entities, 483 default_timeout=60.0, 484 client_info=DEFAULT_CLIENT_INFO, 485 ) 486 487 # Send the request. 488 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 489 490 # Wrap the response in an operation future. 491 response = operation_async.from_gapic( 492 response, 493 self._client._transport.operations_client, 494 empty_pb2.Empty, 495 metadata_type=datastore_admin.ImportEntitiesMetadata, 496 ) 497 498 # Done; return the response. 499 return response 500 501 async def create_index( 502 self, 503 request: Union[datastore_admin.CreateIndexRequest, dict] = None, 504 *, 505 retry: OptionalRetry = gapic_v1.method.DEFAULT, 506 timeout: float = None, 507 metadata: Sequence[Tuple[str, str]] = (), 508 ) -> operation_async.AsyncOperation: 509 r"""Creates the specified index. A newly created index's initial 510 state is ``CREATING``. On completion of the returned 511 [google.longrunning.Operation][google.longrunning.Operation], 512 the state will be ``READY``. If the index already exists, the 513 call will return an ``ALREADY_EXISTS`` status. 514 515 During index creation, the process could result in an error, in 516 which case the index will move to the ``ERROR`` state. The 517 process can be recovered by fixing the data that caused the 518 error, removing the index with 519 [delete][google.datastore.admin.v1.DatastoreAdmin.DeleteIndex], 520 then re-creating the index with [create] 521 [google.datastore.admin.v1.DatastoreAdmin.CreateIndex]. 522 523 Indexes with a single property cannot be created. 524 525 Args: 526 request (Union[google.cloud.datastore_admin_v1.types.CreateIndexRequest, dict]): 527 The request object. The request for 528 [google.datastore.admin.v1.DatastoreAdmin.CreateIndex][google.datastore.admin.v1.DatastoreAdmin.CreateIndex]. 529 retry (google.api_core.retry.Retry): Designation of what errors, if any, 530 should be retried. 531 timeout (float): The timeout for this request. 532 metadata (Sequence[Tuple[str, str]]): Strings which should be 533 sent along with the request as metadata. 534 535 Returns: 536 google.api_core.operation_async.AsyncOperation: 537 An object representing a long-running operation. 538 539 The result type for the operation will be 540 :class:`google.cloud.datastore_admin_v1.types.Index` 541 Datastore composite index definition. 542 543 """ 544 # Create or coerce a protobuf request object. 545 request = datastore_admin.CreateIndexRequest(request) 546 547 # Wrap the RPC method; this adds retry and timeout information, 548 # and friendly error handling. 549 rpc = gapic_v1.method_async.wrap_method( 550 self._client._transport.create_index, 551 default_timeout=60.0, 552 client_info=DEFAULT_CLIENT_INFO, 553 ) 554 555 # Send the request. 556 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 557 558 # Wrap the response in an operation future. 559 response = operation_async.from_gapic( 560 response, 561 self._client._transport.operations_client, 562 index.Index, 563 metadata_type=datastore_admin.IndexOperationMetadata, 564 ) 565 566 # Done; return the response. 567 return response 568 569 async def delete_index( 570 self, 571 request: Union[datastore_admin.DeleteIndexRequest, dict] = None, 572 *, 573 retry: OptionalRetry = gapic_v1.method.DEFAULT, 574 timeout: float = None, 575 metadata: Sequence[Tuple[str, str]] = (), 576 ) -> operation_async.AsyncOperation: 577 r"""Deletes an existing index. An index can only be deleted if it is 578 in a ``READY`` or ``ERROR`` state. On successful execution of 579 the request, the index will be in a ``DELETING`` 580 [state][google.datastore.admin.v1.Index.State]. And on 581 completion of the returned 582 [google.longrunning.Operation][google.longrunning.Operation], 583 the index will be removed. 584 585 During index deletion, the process could result in an error, in 586 which case the index will move to the ``ERROR`` state. The 587 process can be recovered by fixing the data that caused the 588 error, followed by calling 589 [delete][google.datastore.admin.v1.DatastoreAdmin.DeleteIndex] 590 again. 591 592 Args: 593 request (Union[google.cloud.datastore_admin_v1.types.DeleteIndexRequest, dict]): 594 The request object. The request for 595 [google.datastore.admin.v1.DatastoreAdmin.DeleteIndex][google.datastore.admin.v1.DatastoreAdmin.DeleteIndex]. 596 retry (google.api_core.retry.Retry): Designation of what errors, if any, 597 should be retried. 598 timeout (float): The timeout for this request. 599 metadata (Sequence[Tuple[str, str]]): Strings which should be 600 sent along with the request as metadata. 601 602 Returns: 603 google.api_core.operation_async.AsyncOperation: 604 An object representing a long-running operation. 605 606 The result type for the operation will be 607 :class:`google.cloud.datastore_admin_v1.types.Index` 608 Datastore composite index definition. 609 610 """ 611 # Create or coerce a protobuf request object. 612 request = datastore_admin.DeleteIndexRequest(request) 613 614 # Wrap the RPC method; this adds retry and timeout information, 615 # and friendly error handling. 616 rpc = gapic_v1.method_async.wrap_method( 617 self._client._transport.delete_index, 618 default_timeout=60.0, 619 client_info=DEFAULT_CLIENT_INFO, 620 ) 621 622 # Send the request. 623 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 624 625 # Wrap the response in an operation future. 626 response = operation_async.from_gapic( 627 response, 628 self._client._transport.operations_client, 629 index.Index, 630 metadata_type=datastore_admin.IndexOperationMetadata, 631 ) 632 633 # Done; return the response. 634 return response 635 636 async def get_index( 637 self, 638 request: Union[datastore_admin.GetIndexRequest, dict] = None, 639 *, 640 retry: OptionalRetry = gapic_v1.method.DEFAULT, 641 timeout: float = None, 642 metadata: Sequence[Tuple[str, str]] = (), 643 ) -> index.Index: 644 r"""Gets an index. 645 646 Args: 647 request (Union[google.cloud.datastore_admin_v1.types.GetIndexRequest, dict]): 648 The request object. The request for 649 [google.datastore.admin.v1.DatastoreAdmin.GetIndex][google.datastore.admin.v1.DatastoreAdmin.GetIndex]. 650 retry (google.api_core.retry.Retry): Designation of what errors, if any, 651 should be retried. 652 timeout (float): The timeout for this request. 653 metadata (Sequence[Tuple[str, str]]): Strings which should be 654 sent along with the request as metadata. 655 656 Returns: 657 google.cloud.datastore_admin_v1.types.Index: 658 Datastore composite index definition. 659 """ 660 # Create or coerce a protobuf request object. 661 request = datastore_admin.GetIndexRequest(request) 662 663 # Wrap the RPC method; this adds retry and timeout information, 664 # and friendly error handling. 665 rpc = gapic_v1.method_async.wrap_method( 666 self._client._transport.get_index, 667 default_retry=retries.Retry( 668 initial=0.1, 669 maximum=60.0, 670 multiplier=1.3, 671 predicate=retries.if_exception_type( 672 core_exceptions.DeadlineExceeded, 673 core_exceptions.ServiceUnavailable, 674 ), 675 deadline=60.0, 676 ), 677 default_timeout=60.0, 678 client_info=DEFAULT_CLIENT_INFO, 679 ) 680 681 # Send the request. 682 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 683 684 # Done; return the response. 685 return response 686 687 async def list_indexes( 688 self, 689 request: Union[datastore_admin.ListIndexesRequest, dict] = None, 690 *, 691 retry: OptionalRetry = gapic_v1.method.DEFAULT, 692 timeout: float = None, 693 metadata: Sequence[Tuple[str, str]] = (), 694 ) -> pagers.ListIndexesAsyncPager: 695 r"""Lists the indexes that match the specified filters. 696 Datastore uses an eventually consistent query to fetch 697 the list of indexes and may occasionally return stale 698 results. 699 700 Args: 701 request (Union[google.cloud.datastore_admin_v1.types.ListIndexesRequest, dict]): 702 The request object. The request for 703 [google.datastore.admin.v1.DatastoreAdmin.ListIndexes][google.datastore.admin.v1.DatastoreAdmin.ListIndexes]. 704 retry (google.api_core.retry.Retry): Designation of what errors, if any, 705 should be retried. 706 timeout (float): The timeout for this request. 707 metadata (Sequence[Tuple[str, str]]): Strings which should be 708 sent along with the request as metadata. 709 710 Returns: 711 google.cloud.datastore_admin_v1.services.datastore_admin.pagers.ListIndexesAsyncPager: 712 The response for 713 [google.datastore.admin.v1.DatastoreAdmin.ListIndexes][google.datastore.admin.v1.DatastoreAdmin.ListIndexes]. 714 715 Iterating over this object will yield results and 716 resolve additional pages automatically. 717 718 """ 719 # Create or coerce a protobuf request object. 720 request = datastore_admin.ListIndexesRequest(request) 721 722 # Wrap the RPC method; this adds retry and timeout information, 723 # and friendly error handling. 724 rpc = gapic_v1.method_async.wrap_method( 725 self._client._transport.list_indexes, 726 default_retry=retries.Retry( 727 initial=0.1, 728 maximum=60.0, 729 multiplier=1.3, 730 predicate=retries.if_exception_type( 731 core_exceptions.DeadlineExceeded, 732 core_exceptions.ServiceUnavailable, 733 ), 734 deadline=60.0, 735 ), 736 default_timeout=60.0, 737 client_info=DEFAULT_CLIENT_INFO, 738 ) 739 740 # Send the request. 741 response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 742 743 # This method is paged; wrap the response in a pager, which provides 744 # an `__aiter__` convenience method. 745 response = pagers.ListIndexesAsyncPager( 746 method=rpc, request=request, response=response, metadata=metadata, 747 ) 748 749 # Done; return the response. 750 return response 751 752 async def __aenter__(self): 753 return self 754 755 async def __aexit__(self, exc_type, exc, tb): 756 await self.transport.close() 757 758 759try: 760 DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 761 gapic_version=pkg_resources.get_distribution( 762 "google-cloud-datastore-admin", 763 ).version, 764 ) 765except pkg_resources.DistributionNotFound: 766 DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() 767 768 769__all__ = ("DatastoreAdminAsyncClient",) 770