From 25e5e72d154cd7614bf36535c1b334755aee8463 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 12 May 2023 08:48:12 +0000 Subject: [PATCH 1/2] feat: Add support for UpdateDatabase in Cloud Spanner PiperOrigin-RevId: 531423380 Source-Link: https://github.com/googleapis/googleapis/commit/3e054d1467e20b2f475eeb77f17a8595c5aa22d2 Source-Link: https://github.com/googleapis/googleapis-gen/commit/e347738483743e8e866cac722db0e9425356fc80 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZTM0NzczODQ4Mzc0M2U4ZTg2NmNhYzcyMmRiMGU5NDI1MzU2ZmM4MCJ9 --- owl-bot-staging/spanner/v1/.coveragerc | 13 + owl-bot-staging/spanner/v1/.flake8 | 33 + owl-bot-staging/spanner/v1/MANIFEST.in | 2 + owl-bot-staging/spanner/v1/README.rst | 49 + owl-bot-staging/spanner/v1/docs/conf.py | 376 + owl-bot-staging/spanner/v1/docs/index.rst | 7 + .../spanner/v1/docs/spanner_v1/services.rst | 6 + .../spanner/v1/docs/spanner_v1/spanner.rst | 10 + .../spanner/v1/docs/spanner_v1/types.rst | 6 + .../v1/google/cloud/spanner/__init__.py | 103 + .../v1/google/cloud/spanner/gapic_version.py | 16 + .../spanner/v1/google/cloud/spanner/py.typed | 2 + .../v1/google/cloud/spanner_v1/__init__.py | 104 + .../cloud/spanner_v1/gapic_metadata.json | 253 + .../google/cloud/spanner_v1/gapic_version.py | 16 + .../v1/google/cloud/spanner_v1/py.typed | 2 + .../cloud/spanner_v1/services/__init__.py | 15 + .../spanner_v1/services/spanner/__init__.py | 22 + .../services/spanner/async_client.py | 1920 +++ .../spanner_v1/services/spanner/client.py | 2062 +++ .../spanner_v1/services/spanner/pagers.py | 139 + .../services/spanner/transports/__init__.py | 38 + .../services/spanner/transports/base.py | 427 + .../services/spanner/transports/grpc.py | 766 + .../spanner/transports/grpc_asyncio.py | 765 + .../services/spanner/transports/rest.py | 1973 +++ .../google/cloud/spanner_v1/types/__init__.py | 110 + .../cloud/spanner_v1/types/commit_response.py | 79 + .../v1/google/cloud/spanner_v1/types/keys.py | 248 + .../google/cloud/spanner_v1/types/mutation.py | 201 + .../cloud/spanner_v1/types/query_plan.py | 219 + .../cloud/spanner_v1/types/result_set.py | 341 + .../google/cloud/spanner_v1/types/spanner.py | 1327 ++ .../cloud/spanner_v1/types/transaction.py | 673 + .../v1/google/cloud/spanner_v1/types/type.py | 248 + owl-bot-staging/spanner/v1/mypy.ini | 3 + owl-bot-staging/spanner/v1/noxfile.py | 184 + .../snippet_metadata_google.spanner.v1.json | 2410 +++ ...ted_spanner_batch_create_sessions_async.py | 53 + ...ated_spanner_batch_create_sessions_sync.py | 53 + ...nerated_spanner_begin_transaction_async.py | 52 + ...enerated_spanner_begin_transaction_sync.py | 52 + ...anner_v1_generated_spanner_commit_async.py | 53 + ...panner_v1_generated_spanner_commit_sync.py | 53 + ..._generated_spanner_create_session_async.py | 52 + ...1_generated_spanner_create_session_sync.py | 52 + ..._generated_spanner_delete_session_async.py | 50 + ...1_generated_spanner_delete_session_sync.py | 50 + ...nerated_spanner_execute_batch_dml_async.py | 57 + ...enerated_spanner_execute_batch_dml_sync.py | 57 + ..._v1_generated_spanner_execute_sql_async.py | 53 + ...r_v1_generated_spanner_execute_sql_sync.py | 53 + ...ted_spanner_execute_streaming_sql_async.py | 54 + ...ated_spanner_execute_streaming_sql_sync.py | 54 + ..._v1_generated_spanner_get_session_async.py | 52 + ...r_v1_generated_spanner_get_session_sync.py | 52 + ...1_generated_spanner_list_sessions_async.py | 53 + ...v1_generated_spanner_list_sessions_sync.py | 53 + ...generated_spanner_partition_query_async.py | 53 + ..._generated_spanner_partition_query_sync.py | 53 + ..._generated_spanner_partition_read_async.py | 53 + ...1_generated_spanner_partition_read_sync.py | 53 + ...spanner_v1_generated_spanner_read_async.py | 54 + .../spanner_v1_generated_spanner_read_sync.py | 54 + ...ner_v1_generated_spanner_rollback_async.py | 51 + ...nner_v1_generated_spanner_rollback_sync.py | 51 + ..._generated_spanner_streaming_read_async.py | 55 + ...1_generated_spanner_streaming_read_sync.py | 55 + .../v1/scripts/fixup_spanner_v1_keywords.py | 190 + owl-bot-staging/spanner/v1/setup.py | 90 + .../spanner/v1/testing/constraints-3.10.txt | 6 + .../spanner/v1/testing/constraints-3.11.txt | 6 + .../spanner/v1/testing/constraints-3.12.txt | 6 + .../spanner/v1/testing/constraints-3.7.txt | 9 + .../spanner/v1/testing/constraints-3.8.txt | 6 + .../spanner/v1/testing/constraints-3.9.txt | 6 + owl-bot-staging/spanner/v1/tests/__init__.py | 16 + .../spanner/v1/tests/unit/__init__.py | 16 + .../spanner/v1/tests/unit/gapic/__init__.py | 16 + .../tests/unit/gapic/spanner_v1/__init__.py | 16 + .../unit/gapic/spanner_v1/test_spanner.py | 7665 +++++++++ .../spanner_admin_database/v1/.coveragerc | 13 + .../spanner_admin_database/v1/.flake8 | 33 + .../spanner_admin_database/v1/MANIFEST.in | 2 + .../spanner_admin_database/v1/README.rst | 49 + .../spanner_admin_database/v1/docs/conf.py | 376 + .../spanner_admin_database/v1/docs/index.rst | 7 + .../database_admin.rst | 10 + .../spanner_admin_database_v1/services.rst | 6 + .../docs/spanner_admin_database_v1/types.rst | 6 + .../cloud/spanner_admin_database/__init__.py | 113 + .../spanner_admin_database/gapic_version.py | 16 + .../cloud/spanner_admin_database/py.typed | 2 + .../spanner_admin_database_v1/__init__.py | 114 + .../gapic_metadata.json | 328 + .../gapic_version.py | 16 + .../cloud/spanner_admin_database_v1/py.typed | 2 + .../services/__init__.py | 15 + .../services/database_admin/__init__.py | 22 + .../services/database_admin/async_client.py | 3146 ++++ .../services/database_admin/client.py | 3296 ++++ .../services/database_admin/pagers.py | 625 + .../database_admin/transports/__init__.py | 38 + .../database_admin/transports/base.py | 562 + .../database_admin/transports/grpc.py | 1015 ++ .../database_admin/transports/grpc_asyncio.py | 1014 ++ .../database_admin/transports/rest.py | 3132 ++++ .../types/__init__.py | 110 + .../spanner_admin_database_v1/types/backup.py | 906 ++ .../spanner_admin_database_v1/types/common.py | 155 + .../types/spanner_database_admin.py | 1059 ++ .../spanner_admin_database/v1/mypy.ini | 3 + .../spanner_admin_database/v1/noxfile.py | 184 + ...data_google.spanner.admin.database.v1.json | 3319 ++++ ...erated_database_admin_copy_backup_async.py | 58 + ...nerated_database_admin_copy_backup_sync.py | 58 + ...ated_database_admin_create_backup_async.py | 57 + ...rated_database_admin_create_backup_sync.py | 57 + ...ed_database_admin_create_database_async.py | 57 + ...ted_database_admin_create_database_sync.py | 57 + ...ated_database_admin_delete_backup_async.py | 50 + ...rated_database_admin_delete_backup_sync.py | 50 + ...ated_database_admin_drop_database_async.py | 50 + ...rated_database_admin_drop_database_sync.py | 50 + ...nerated_database_admin_get_backup_async.py | 52 + ...enerated_database_admin_get_backup_sync.py | 52 + ...rated_database_admin_get_database_async.py | 52 + ...d_database_admin_get_database_ddl_async.py | 52 + ...ed_database_admin_get_database_ddl_sync.py | 52 + ...erated_database_admin_get_database_sync.py | 52 + ...ted_database_admin_get_iam_policy_async.py | 53 + ...ated_database_admin_get_iam_policy_sync.py | 53 + ...base_admin_list_backup_operations_async.py | 53 + ...abase_admin_list_backup_operations_sync.py | 53 + ...rated_database_admin_list_backups_async.py | 53 + ...erated_database_admin_list_backups_sync.py | 53 + ...se_admin_list_database_operations_async.py | 53 + ...ase_admin_list_database_operations_sync.py | 53 + ...atabase_admin_list_database_roles_async.py | 53 + ...database_admin_list_database_roles_sync.py | 53 + ...ted_database_admin_list_databases_async.py | 53 + ...ated_database_admin_list_databases_sync.py | 53 + ...d_database_admin_restore_database_async.py | 58 + ...ed_database_admin_restore_database_sync.py | 58 + ...ted_database_admin_set_iam_policy_async.py | 53 + ...ated_database_admin_set_iam_policy_sync.py | 53 + ...tabase_admin_test_iam_permissions_async.py | 54 + ...atabase_admin_test_iam_permissions_sync.py | 54 + ...ated_database_admin_update_backup_async.py | 51 + ...rated_database_admin_update_backup_sync.py | 51 + ...ed_database_admin_update_database_async.py | 59 + ...atabase_admin_update_database_ddl_async.py | 57 + ...database_admin_update_database_ddl_sync.py | 57 + ...ted_database_admin_update_database_sync.py | 59 + ...ixup_spanner_admin_database_v1_keywords.py | 195 + .../spanner_admin_database/v1/setup.py | 91 + .../v1/testing/constraints-3.10.txt | 7 + .../v1/testing/constraints-3.11.txt | 7 + .../v1/testing/constraints-3.12.txt | 7 + .../v1/testing/constraints-3.7.txt | 10 + .../v1/testing/constraints-3.8.txt | 7 + .../v1/testing/constraints-3.9.txt | 7 + .../v1/tests/__init__.py | 16 + .../v1/tests/unit/__init__.py | 16 + .../v1/tests/unit/gapic/__init__.py | 16 + .../spanner_admin_database_v1/__init__.py | 16 + .../test_database_admin.py | 12988 ++++++++++++++++ .../spanner_admin_instance/v1/.coveragerc | 13 + .../spanner_admin_instance/v1/.flake8 | 33 + .../spanner_admin_instance/v1/MANIFEST.in | 2 + .../spanner_admin_instance/v1/README.rst | 49 + .../spanner_admin_instance/v1/docs/conf.py | 376 + .../spanner_admin_instance/v1/docs/index.rst | 7 + .../instance_admin.rst | 10 + .../spanner_admin_instance_v1/services.rst | 6 + .../docs/spanner_admin_instance_v1/types.rst | 6 + .../cloud/spanner_admin_instance/__init__.py | 71 + .../spanner_admin_instance/gapic_version.py | 16 + .../cloud/spanner_admin_instance/py.typed | 2 + .../spanner_admin_instance_v1/__init__.py | 72 + .../gapic_metadata.json | 238 + .../gapic_version.py | 16 + .../cloud/spanner_admin_instance_v1/py.typed | 2 + .../services/__init__.py | 15 + .../services/instance_admin/__init__.py | 22 + .../services/instance_admin/async_client.py | 2221 +++ .../services/instance_admin/client.py | 2391 +++ .../services/instance_admin/pagers.py | 382 + .../instance_admin/transports/__init__.py | 38 + .../instance_admin/transports/base.py | 383 + .../instance_admin/transports/grpc.py | 861 + .../instance_admin/transports/grpc_asyncio.py | 860 + .../instance_admin/transports/rest.py | 2003 +++ .../types/__init__.py | 66 + .../spanner_admin_instance_v1/types/common.py | 64 + .../types/spanner_instance_admin.py | 1128 ++ .../spanner_admin_instance/v1/mypy.ini | 3 + .../spanner_admin_instance/v1/noxfile.py | 184 + ...data_google.spanner.admin.instance.v1.json | 2313 +++ ...ed_instance_admin_create_instance_async.py | 63 + ...ance_admin_create_instance_config_async.py | 57 + ...tance_admin_create_instance_config_sync.py | 57 + ...ted_instance_admin_create_instance_sync.py | 63 + ...ed_instance_admin_delete_instance_async.py | 50 + ...ance_admin_delete_instance_config_async.py | 50 + ...tance_admin_delete_instance_config_sync.py | 50 + ...ted_instance_admin_delete_instance_sync.py | 50 + ...ted_instance_admin_get_iam_policy_async.py | 53 + ...ated_instance_admin_get_iam_policy_sync.py | 53 + ...rated_instance_admin_get_instance_async.py | 52 + ...nstance_admin_get_instance_config_async.py | 52 + ...instance_admin_get_instance_config_sync.py | 52 + ...erated_instance_admin_get_instance_sync.py | 52 + ...n_list_instance_config_operations_async.py | 53 + ...in_list_instance_config_operations_sync.py | 53 + ...tance_admin_list_instance_configs_async.py | 53 + ...stance_admin_list_instance_configs_sync.py | 53 + ...ted_instance_admin_list_instances_async.py | 53 + ...ated_instance_admin_list_instances_sync.py | 53 + ...ted_instance_admin_set_iam_policy_async.py | 53 + ...ated_instance_admin_set_iam_policy_sync.py | 53 + ...stance_admin_test_iam_permissions_async.py | 54 + ...nstance_admin_test_iam_permissions_sync.py | 54 + ...ed_instance_admin_update_instance_async.py | 61 + ...ance_admin_update_instance_config_async.py | 55 + ...tance_admin_update_instance_config_sync.py | 55 + ...ted_instance_admin_update_instance_sync.py | 61 + ...ixup_spanner_admin_instance_v1_keywords.py | 189 + .../spanner_admin_instance/v1/setup.py | 91 + .../v1/testing/constraints-3.10.txt | 7 + .../v1/testing/constraints-3.11.txt | 7 + .../v1/testing/constraints-3.12.txt | 7 + .../v1/testing/constraints-3.7.txt | 10 + .../v1/testing/constraints-3.8.txt | 7 + .../v1/testing/constraints-3.9.txt | 7 + .../v1/tests/__init__.py | 16 + .../v1/tests/unit/__init__.py | 16 + .../v1/tests/unit/gapic/__init__.py | 16 + .../spanner_admin_instance_v1/__init__.py | 16 + .../test_instance_admin.py | 8775 +++++++++++ 240 files changed, 84574 insertions(+) create mode 100644 owl-bot-staging/spanner/v1/.coveragerc create mode 100644 owl-bot-staging/spanner/v1/.flake8 create mode 100644 owl-bot-staging/spanner/v1/MANIFEST.in create mode 100644 owl-bot-staging/spanner/v1/README.rst create mode 100644 owl-bot-staging/spanner/v1/docs/conf.py create mode 100644 owl-bot-staging/spanner/v1/docs/index.rst create mode 100644 owl-bot-staging/spanner/v1/docs/spanner_v1/services.rst create mode 100644 owl-bot-staging/spanner/v1/docs/spanner_v1/spanner.rst create mode 100644 owl-bot-staging/spanner/v1/docs/spanner_v1/types.rst create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner/__init__.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner/gapic_version.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner/py.typed create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/__init__.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_metadata.json create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_version.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/py.typed create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/__init__.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/__init__.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/async_client.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/client.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/pagers.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/__init__.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/base.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/rest.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/__init__.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/commit_response.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/keys.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/mutation.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/query_plan.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/result_set.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/spanner.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/transaction.py create mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/type.py create mode 100644 owl-bot-staging/spanner/v1/mypy.ini create mode 100644 owl-bot-staging/spanner/v1/noxfile.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/snippet_metadata_google.spanner.v1.json create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_sync.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_sync.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_sync.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_sync.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_sync.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_sync.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_sync.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_sync.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_sync.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_sync.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_sync.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_sync.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_sync.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_sync.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_async.py create mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_sync.py create mode 100644 owl-bot-staging/spanner/v1/scripts/fixup_spanner_v1_keywords.py create mode 100644 owl-bot-staging/spanner/v1/setup.py create mode 100644 owl-bot-staging/spanner/v1/testing/constraints-3.10.txt create mode 100644 owl-bot-staging/spanner/v1/testing/constraints-3.11.txt create mode 100644 owl-bot-staging/spanner/v1/testing/constraints-3.12.txt create mode 100644 owl-bot-staging/spanner/v1/testing/constraints-3.7.txt create mode 100644 owl-bot-staging/spanner/v1/testing/constraints-3.8.txt create mode 100644 owl-bot-staging/spanner/v1/testing/constraints-3.9.txt create mode 100644 owl-bot-staging/spanner/v1/tests/__init__.py create mode 100644 owl-bot-staging/spanner/v1/tests/unit/__init__.py create mode 100644 owl-bot-staging/spanner/v1/tests/unit/gapic/__init__.py create mode 100644 owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/__init__.py create mode 100644 owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/test_spanner.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/.coveragerc create mode 100644 owl-bot-staging/spanner_admin_database/v1/.flake8 create mode 100644 owl-bot-staging/spanner_admin_database/v1/MANIFEST.in create mode 100644 owl-bot-staging/spanner_admin_database/v1/README.rst create mode 100644 owl-bot-staging/spanner_admin_database/v1/docs/conf.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/docs/index.rst create mode 100644 owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/database_admin.rst create mode 100644 owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/services.rst create mode 100644 owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/types.rst create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/__init__.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/gapic_version.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/py.typed create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/__init__.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_metadata.json create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_version.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/py.typed create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/__init__.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/client.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/__init__.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/backup.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/common.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/mypy.ini create mode 100644 owl-bot-staging/spanner_admin_database/v1/noxfile.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.database.v1.json create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_async.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_sync.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/scripts/fixup_spanner_admin_database_v1_keywords.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/setup.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.10.txt create mode 100644 owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.11.txt create mode 100644 owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.12.txt create mode 100644 owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.7.txt create mode 100644 owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.8.txt create mode 100644 owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.9.txt create mode 100644 owl-bot-staging/spanner_admin_database/v1/tests/__init__.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/tests/unit/__init__.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/__init__.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/__init__.py create mode 100644 owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/.coveragerc create mode 100644 owl-bot-staging/spanner_admin_instance/v1/.flake8 create mode 100644 owl-bot-staging/spanner_admin_instance/v1/MANIFEST.in create mode 100644 owl-bot-staging/spanner_admin_instance/v1/README.rst create mode 100644 owl-bot-staging/spanner_admin_instance/v1/docs/conf.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/docs/index.rst create mode 100644 owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/instance_admin.rst create mode 100644 owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/services.rst create mode 100644 owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/types.rst create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/__init__.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/gapic_version.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/py.typed create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/__init__.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_metadata.json create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_version.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/py.typed create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/__init__.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/__init__.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/common.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/mypy.ini create mode 100644 owl-bot-staging/spanner_admin_instance/v1/noxfile.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.instance.v1.json create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_async.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_async.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_sync.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_sync.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_async.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_async.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_sync.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_sync.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_async.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_sync.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_async.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_async.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_sync.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_sync.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_async.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_async.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_sync.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_async.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_sync.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_async.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_sync.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_async.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_sync.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_async.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_async.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_sync.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_sync.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/scripts/fixup_spanner_admin_instance_v1_keywords.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/setup.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.10.txt create mode 100644 owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.11.txt create mode 100644 owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.12.txt create mode 100644 owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.7.txt create mode 100644 owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.8.txt create mode 100644 owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.9.txt create mode 100644 owl-bot-staging/spanner_admin_instance/v1/tests/__init__.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/tests/unit/__init__.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/__init__.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/__init__.py create mode 100644 owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py diff --git a/owl-bot-staging/spanner/v1/.coveragerc b/owl-bot-staging/spanner/v1/.coveragerc new file mode 100644 index 0000000000..677a992799 --- /dev/null +++ b/owl-bot-staging/spanner/v1/.coveragerc @@ -0,0 +1,13 @@ +[run] +branch = True + +[report] +show_missing = True +omit = + google/cloud/spanner/__init__.py + google/cloud/spanner/gapic_version.py +exclude_lines = + # Re-enable the standard pragma + pragma: NO COVER + # Ignore debug-only repr + def __repr__ diff --git a/owl-bot-staging/spanner/v1/.flake8 b/owl-bot-staging/spanner/v1/.flake8 new file mode 100644 index 0000000000..29227d4cf4 --- /dev/null +++ b/owl-bot-staging/spanner/v1/.flake8 @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Generated by synthtool. DO NOT EDIT! +[flake8] +ignore = E203, E266, E501, W503 +exclude = + # Exclude generated code. + **/proto/** + **/gapic/** + **/services/** + **/types/** + *_pb2.py + + # Standard linting exemptions. + **/.nox/** + __pycache__, + .git, + *.pyc, + conf.py diff --git a/owl-bot-staging/spanner/v1/MANIFEST.in b/owl-bot-staging/spanner/v1/MANIFEST.in new file mode 100644 index 0000000000..2bde59af4d --- /dev/null +++ b/owl-bot-staging/spanner/v1/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include google/cloud/spanner *.py +recursive-include google/cloud/spanner_v1 *.py diff --git a/owl-bot-staging/spanner/v1/README.rst b/owl-bot-staging/spanner/v1/README.rst new file mode 100644 index 0000000000..d6abf98111 --- /dev/null +++ b/owl-bot-staging/spanner/v1/README.rst @@ -0,0 +1,49 @@ +Python Client for Google Cloud Spanner API +================================================= + +Quick Start +----------- + +In order to use this library, you first need to go through the following steps: + +1. `Select or create a Cloud Platform project.`_ +2. `Enable billing for your project.`_ +3. Enable the Google Cloud Spanner API. +4. `Setup Authentication.`_ + +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project +.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html + +Installation +~~~~~~~~~~~~ + +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to +create isolated Python environments. The basic problem it addresses is one of +dependencies and versions, and indirectly permissions. + +With `virtualenv`_, it's possible to install this library without needing system +install permissions, and without clashing with the installed system +dependencies. + +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ + + +Mac/Linux +^^^^^^^^^ + +.. code-block:: console + + python3 -m venv + source /bin/activate + /bin/pip install /path/to/library + + +Windows +^^^^^^^ + +.. code-block:: console + + python3 -m venv + \Scripts\activate + \Scripts\pip.exe install \path\to\library diff --git a/owl-bot-staging/spanner/v1/docs/conf.py b/owl-bot-staging/spanner/v1/docs/conf.py new file mode 100644 index 0000000000..a2a239f23f --- /dev/null +++ b/owl-bot-staging/spanner/v1/docs/conf.py @@ -0,0 +1,376 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# google-cloud-spanner documentation build configuration file +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os +import shlex + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath("..")) + +__version__ = "0.1.0" + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +needs_sphinx = "4.0.1" + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.intersphinx", + "sphinx.ext.coverage", + "sphinx.ext.napoleon", + "sphinx.ext.todo", + "sphinx.ext.viewcode", +] + +# autodoc/autosummary flags +autoclass_content = "both" +autodoc_default_flags = ["members"] +autosummary_generate = True + + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# Allow markdown includes (so releases.md can include CHANGLEOG.md) +# http://www.sphinx-doc.org/en/master/markdown.html +source_parsers = {".md": "recommonmark.parser.CommonMarkParser"} + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +source_suffix = [".rst", ".md"] + +# The encoding of source files. +# source_encoding = 'utf-8-sig' + +# The root toctree document. +root_doc = "index" + +# General information about the project. +project = u"google-cloud-spanner" +copyright = u"2022, Google, LLC" +author = u"Google APIs" # TODO: autogenerate this bit + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The full version, including alpha/beta/rc tags. +release = __version__ +# The short X.Y version. +version = ".".join(release.split(".")[0:2]) + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# today = '' +# Else, today_fmt is used as the format for a strftime call. +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ["_build"] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = "sphinx" + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = "alabaster" + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +html_theme_options = { + "description": "Google Cloud Client Libraries for Python", + "github_user": "googleapis", + "github_repo": "google-cloud-python", + "github_banner": True, + "font_family": "'Roboto', Georgia, sans", + "head_font_family": "'Roboto', Georgia, serif", + "code_font_family": "'Roboto Mono', 'Consolas', monospace", +} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +# html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +# html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +# html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# html_additional_pages = {} + +# If false, no module index is generated. +# html_domain_indices = True + +# If false, no index is generated. +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' +# html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# Now only 'ja' uses this config value +# html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +# html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = "google-cloud-spanner-doc" + +# -- Options for warnings ------------------------------------------------------ + + +suppress_warnings = [ + # Temporarily suppress this to avoid "more than one target found for + # cross-reference" warning, which are intractable for us to avoid while in + # a mono-repo. + # See https://github.com/sphinx-doc/sphinx/blob + # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 + "ref.python" +] + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # 'preamble': '', + # Latex figure (float) alignment + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ( + root_doc, + "google-cloud-spanner.tex", + u"google-cloud-spanner Documentation", + author, + "manual", + ) +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# latex_use_parts = False + +# If true, show page references after internal links. +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# latex_appendices = [] + +# If false, no module index is generated. +# latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ( + root_doc, + "google-cloud-spanner", + u"Google Cloud Spanner Documentation", + [author], + 1, + ) +] + +# If true, show URL addresses after external links. +# man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ( + root_doc, + "google-cloud-spanner", + u"google-cloud-spanner Documentation", + author, + "google-cloud-spanner", + "GAPIC library for Google Cloud Spanner API", + "APIs", + ) +] + +# Documents to append as an appendix to all manuals. +# texinfo_appendices = [] + +# If false, no module index is generated. +# texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +# texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +# texinfo_no_detailmenu = False + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = { + "python": ("http://python.readthedocs.org/en/latest/", None), + "gax": ("https://gax-python.readthedocs.org/en/latest/", None), + "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), + "google-gax": ("https://gax-python.readthedocs.io/en/latest/", None), + "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None), + "grpc": ("https://grpc.io/grpc/python/", None), + "requests": ("http://requests.kennethreitz.org/en/stable/", None), + "proto": ("https://proto-plus-python.readthedocs.io/en/stable", None), + "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), +} + + +# Napoleon settings +napoleon_google_docstring = True +napoleon_numpy_docstring = True +napoleon_include_private_with_doc = False +napoleon_include_special_with_doc = True +napoleon_use_admonition_for_examples = False +napoleon_use_admonition_for_notes = False +napoleon_use_admonition_for_references = False +napoleon_use_ivar = False +napoleon_use_param = True +napoleon_use_rtype = True diff --git a/owl-bot-staging/spanner/v1/docs/index.rst b/owl-bot-staging/spanner/v1/docs/index.rst new file mode 100644 index 0000000000..ee873ac9c1 --- /dev/null +++ b/owl-bot-staging/spanner/v1/docs/index.rst @@ -0,0 +1,7 @@ +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + spanner_v1/services + spanner_v1/types diff --git a/owl-bot-staging/spanner/v1/docs/spanner_v1/services.rst b/owl-bot-staging/spanner/v1/docs/spanner_v1/services.rst new file mode 100644 index 0000000000..3bbbb55f79 --- /dev/null +++ b/owl-bot-staging/spanner/v1/docs/spanner_v1/services.rst @@ -0,0 +1,6 @@ +Services for Google Cloud Spanner v1 API +======================================== +.. toctree:: + :maxdepth: 2 + + spanner diff --git a/owl-bot-staging/spanner/v1/docs/spanner_v1/spanner.rst b/owl-bot-staging/spanner/v1/docs/spanner_v1/spanner.rst new file mode 100644 index 0000000000..b51f4447e4 --- /dev/null +++ b/owl-bot-staging/spanner/v1/docs/spanner_v1/spanner.rst @@ -0,0 +1,10 @@ +Spanner +------------------------- + +.. automodule:: google.cloud.spanner_v1.services.spanner + :members: + :inherited-members: + +.. automodule:: google.cloud.spanner_v1.services.spanner.pagers + :members: + :inherited-members: diff --git a/owl-bot-staging/spanner/v1/docs/spanner_v1/types.rst b/owl-bot-staging/spanner/v1/docs/spanner_v1/types.rst new file mode 100644 index 0000000000..c7ff7e6c71 --- /dev/null +++ b/owl-bot-staging/spanner/v1/docs/spanner_v1/types.rst @@ -0,0 +1,6 @@ +Types for Google Cloud Spanner v1 API +===================================== + +.. automodule:: google.cloud.spanner_v1.types + :members: + :show-inheritance: diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner/__init__.py b/owl-bot-staging/spanner/v1/google/cloud/spanner/__init__.py new file mode 100644 index 0000000000..757431564c --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner/__init__.py @@ -0,0 +1,103 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from google.cloud.spanner import gapic_version as package_version + +__version__ = package_version.__version__ + + +from google.cloud.spanner_v1.services.spanner.client import SpannerClient +from google.cloud.spanner_v1.services.spanner.async_client import SpannerAsyncClient + +from google.cloud.spanner_v1.types.commit_response import CommitResponse +from google.cloud.spanner_v1.types.keys import KeyRange +from google.cloud.spanner_v1.types.keys import KeySet +from google.cloud.spanner_v1.types.mutation import Mutation +from google.cloud.spanner_v1.types.query_plan import PlanNode +from google.cloud.spanner_v1.types.query_plan import QueryPlan +from google.cloud.spanner_v1.types.result_set import PartialResultSet +from google.cloud.spanner_v1.types.result_set import ResultSet +from google.cloud.spanner_v1.types.result_set import ResultSetMetadata +from google.cloud.spanner_v1.types.result_set import ResultSetStats +from google.cloud.spanner_v1.types.spanner import BatchCreateSessionsRequest +from google.cloud.spanner_v1.types.spanner import BatchCreateSessionsResponse +from google.cloud.spanner_v1.types.spanner import BeginTransactionRequest +from google.cloud.spanner_v1.types.spanner import CommitRequest +from google.cloud.spanner_v1.types.spanner import CreateSessionRequest +from google.cloud.spanner_v1.types.spanner import DeleteSessionRequest +from google.cloud.spanner_v1.types.spanner import ExecuteBatchDmlRequest +from google.cloud.spanner_v1.types.spanner import ExecuteBatchDmlResponse +from google.cloud.spanner_v1.types.spanner import ExecuteSqlRequest +from google.cloud.spanner_v1.types.spanner import GetSessionRequest +from google.cloud.spanner_v1.types.spanner import ListSessionsRequest +from google.cloud.spanner_v1.types.spanner import ListSessionsResponse +from google.cloud.spanner_v1.types.spanner import Partition +from google.cloud.spanner_v1.types.spanner import PartitionOptions +from google.cloud.spanner_v1.types.spanner import PartitionQueryRequest +from google.cloud.spanner_v1.types.spanner import PartitionReadRequest +from google.cloud.spanner_v1.types.spanner import PartitionResponse +from google.cloud.spanner_v1.types.spanner import ReadRequest +from google.cloud.spanner_v1.types.spanner import RequestOptions +from google.cloud.spanner_v1.types.spanner import RollbackRequest +from google.cloud.spanner_v1.types.spanner import Session +from google.cloud.spanner_v1.types.transaction import Transaction +from google.cloud.spanner_v1.types.transaction import TransactionOptions +from google.cloud.spanner_v1.types.transaction import TransactionSelector +from google.cloud.spanner_v1.types.type import StructType +from google.cloud.spanner_v1.types.type import Type +from google.cloud.spanner_v1.types.type import TypeAnnotationCode +from google.cloud.spanner_v1.types.type import TypeCode + +__all__ = ('SpannerClient', + 'SpannerAsyncClient', + 'CommitResponse', + 'KeyRange', + 'KeySet', + 'Mutation', + 'PlanNode', + 'QueryPlan', + 'PartialResultSet', + 'ResultSet', + 'ResultSetMetadata', + 'ResultSetStats', + 'BatchCreateSessionsRequest', + 'BatchCreateSessionsResponse', + 'BeginTransactionRequest', + 'CommitRequest', + 'CreateSessionRequest', + 'DeleteSessionRequest', + 'ExecuteBatchDmlRequest', + 'ExecuteBatchDmlResponse', + 'ExecuteSqlRequest', + 'GetSessionRequest', + 'ListSessionsRequest', + 'ListSessionsResponse', + 'Partition', + 'PartitionOptions', + 'PartitionQueryRequest', + 'PartitionReadRequest', + 'PartitionResponse', + 'ReadRequest', + 'RequestOptions', + 'RollbackRequest', + 'Session', + 'Transaction', + 'TransactionOptions', + 'TransactionSelector', + 'StructType', + 'Type', + 'TypeAnnotationCode', + 'TypeCode', +) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner/gapic_version.py b/owl-bot-staging/spanner/v1/google/cloud/spanner/gapic_version.py new file mode 100644 index 0000000000..405b1cebcf --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +__version__ = "0.1.0" # {x-release-please-version} diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner/py.typed b/owl-bot-staging/spanner/v1/google/cloud/spanner/py.typed new file mode 100644 index 0000000000..0989eccd04 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-spanner package uses inline types. diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/__init__.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/__init__.py new file mode 100644 index 0000000000..27c3210864 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/__init__.py @@ -0,0 +1,104 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from google.cloud.spanner_v1 import gapic_version as package_version + +__version__ = package_version.__version__ + + +from .services.spanner import SpannerClient +from .services.spanner import SpannerAsyncClient + +from .types.commit_response import CommitResponse +from .types.keys import KeyRange +from .types.keys import KeySet +from .types.mutation import Mutation +from .types.query_plan import PlanNode +from .types.query_plan import QueryPlan +from .types.result_set import PartialResultSet +from .types.result_set import ResultSet +from .types.result_set import ResultSetMetadata +from .types.result_set import ResultSetStats +from .types.spanner import BatchCreateSessionsRequest +from .types.spanner import BatchCreateSessionsResponse +from .types.spanner import BeginTransactionRequest +from .types.spanner import CommitRequest +from .types.spanner import CreateSessionRequest +from .types.spanner import DeleteSessionRequest +from .types.spanner import ExecuteBatchDmlRequest +from .types.spanner import ExecuteBatchDmlResponse +from .types.spanner import ExecuteSqlRequest +from .types.spanner import GetSessionRequest +from .types.spanner import ListSessionsRequest +from .types.spanner import ListSessionsResponse +from .types.spanner import Partition +from .types.spanner import PartitionOptions +from .types.spanner import PartitionQueryRequest +from .types.spanner import PartitionReadRequest +from .types.spanner import PartitionResponse +from .types.spanner import ReadRequest +from .types.spanner import RequestOptions +from .types.spanner import RollbackRequest +from .types.spanner import Session +from .types.transaction import Transaction +from .types.transaction import TransactionOptions +from .types.transaction import TransactionSelector +from .types.type import StructType +from .types.type import Type +from .types.type import TypeAnnotationCode +from .types.type import TypeCode + +__all__ = ( + 'SpannerAsyncClient', +'BatchCreateSessionsRequest', +'BatchCreateSessionsResponse', +'BeginTransactionRequest', +'CommitRequest', +'CommitResponse', +'CreateSessionRequest', +'DeleteSessionRequest', +'ExecuteBatchDmlRequest', +'ExecuteBatchDmlResponse', +'ExecuteSqlRequest', +'GetSessionRequest', +'KeyRange', +'KeySet', +'ListSessionsRequest', +'ListSessionsResponse', +'Mutation', +'PartialResultSet', +'Partition', +'PartitionOptions', +'PartitionQueryRequest', +'PartitionReadRequest', +'PartitionResponse', +'PlanNode', +'QueryPlan', +'ReadRequest', +'RequestOptions', +'ResultSet', +'ResultSetMetadata', +'ResultSetStats', +'RollbackRequest', +'Session', +'SpannerClient', +'StructType', +'Transaction', +'TransactionOptions', +'TransactionSelector', +'Type', +'TypeAnnotationCode', +'TypeCode', +) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_metadata.json b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_metadata.json new file mode 100644 index 0000000000..ea51736a55 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_metadata.json @@ -0,0 +1,253 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.spanner_v1", + "protoPackage": "google.spanner.v1", + "schema": "1.0", + "services": { + "Spanner": { + "clients": { + "grpc": { + "libraryClient": "SpannerClient", + "rpcs": { + "BatchCreateSessions": { + "methods": [ + "batch_create_sessions" + ] + }, + "BeginTransaction": { + "methods": [ + "begin_transaction" + ] + }, + "Commit": { + "methods": [ + "commit" + ] + }, + "CreateSession": { + "methods": [ + "create_session" + ] + }, + "DeleteSession": { + "methods": [ + "delete_session" + ] + }, + "ExecuteBatchDml": { + "methods": [ + "execute_batch_dml" + ] + }, + "ExecuteSql": { + "methods": [ + "execute_sql" + ] + }, + "ExecuteStreamingSql": { + "methods": [ + "execute_streaming_sql" + ] + }, + "GetSession": { + "methods": [ + "get_session" + ] + }, + "ListSessions": { + "methods": [ + "list_sessions" + ] + }, + "PartitionQuery": { + "methods": [ + "partition_query" + ] + }, + "PartitionRead": { + "methods": [ + "partition_read" + ] + }, + "Read": { + "methods": [ + "read" + ] + }, + "Rollback": { + "methods": [ + "rollback" + ] + }, + "StreamingRead": { + "methods": [ + "streaming_read" + ] + } + } + }, + "grpc-async": { + "libraryClient": "SpannerAsyncClient", + "rpcs": { + "BatchCreateSessions": { + "methods": [ + "batch_create_sessions" + ] + }, + "BeginTransaction": { + "methods": [ + "begin_transaction" + ] + }, + "Commit": { + "methods": [ + "commit" + ] + }, + "CreateSession": { + "methods": [ + "create_session" + ] + }, + "DeleteSession": { + "methods": [ + "delete_session" + ] + }, + "ExecuteBatchDml": { + "methods": [ + "execute_batch_dml" + ] + }, + "ExecuteSql": { + "methods": [ + "execute_sql" + ] + }, + "ExecuteStreamingSql": { + "methods": [ + "execute_streaming_sql" + ] + }, + "GetSession": { + "methods": [ + "get_session" + ] + }, + "ListSessions": { + "methods": [ + "list_sessions" + ] + }, + "PartitionQuery": { + "methods": [ + "partition_query" + ] + }, + "PartitionRead": { + "methods": [ + "partition_read" + ] + }, + "Read": { + "methods": [ + "read" + ] + }, + "Rollback": { + "methods": [ + "rollback" + ] + }, + "StreamingRead": { + "methods": [ + "streaming_read" + ] + } + } + }, + "rest": { + "libraryClient": "SpannerClient", + "rpcs": { + "BatchCreateSessions": { + "methods": [ + "batch_create_sessions" + ] + }, + "BeginTransaction": { + "methods": [ + "begin_transaction" + ] + }, + "Commit": { + "methods": [ + "commit" + ] + }, + "CreateSession": { + "methods": [ + "create_session" + ] + }, + "DeleteSession": { + "methods": [ + "delete_session" + ] + }, + "ExecuteBatchDml": { + "methods": [ + "execute_batch_dml" + ] + }, + "ExecuteSql": { + "methods": [ + "execute_sql" + ] + }, + "ExecuteStreamingSql": { + "methods": [ + "execute_streaming_sql" + ] + }, + "GetSession": { + "methods": [ + "get_session" + ] + }, + "ListSessions": { + "methods": [ + "list_sessions" + ] + }, + "PartitionQuery": { + "methods": [ + "partition_query" + ] + }, + "PartitionRead": { + "methods": [ + "partition_read" + ] + }, + "Read": { + "methods": [ + "read" + ] + }, + "Rollback": { + "methods": [ + "rollback" + ] + }, + "StreamingRead": { + "methods": [ + "streaming_read" + ] + } + } + } + } + } + } +} diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_version.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_version.py new file mode 100644 index 0000000000..405b1cebcf --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +__version__ = "0.1.0" # {x-release-please-version} diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/py.typed b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/py.typed new file mode 100644 index 0000000000..0989eccd04 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-spanner package uses inline types. diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/__init__.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/__init__.py new file mode 100644 index 0000000000..e8e1c3845d --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/__init__.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/__init__.py new file mode 100644 index 0000000000..04d980250a --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .client import SpannerClient +from .async_client import SpannerAsyncClient + +__all__ = ( + 'SpannerClient', + 'SpannerAsyncClient', +) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/async_client.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/async_client.py new file mode 100644 index 0000000000..1657668e54 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/async_client.py @@ -0,0 +1,1920 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +import functools +import re +from typing import Dict, Mapping, MutableMapping, MutableSequence, Optional, AsyncIterable, Awaitable, Sequence, Tuple, Type, Union + +from google.cloud.spanner_v1 import gapic_version as package_version + +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.cloud.spanner_v1.services.spanner import pagers +from google.cloud.spanner_v1.types import commit_response +from google.cloud.spanner_v1.types import mutation +from google.cloud.spanner_v1.types import result_set +from google.cloud.spanner_v1.types import spanner +from google.cloud.spanner_v1.types import transaction +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from .transports.base import SpannerTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import SpannerGrpcAsyncIOTransport +from .client import SpannerClient + + +class SpannerAsyncClient: + """Cloud Spanner API + The Cloud Spanner API can be used to manage sessions and execute + transactions on data stored in Cloud Spanner databases. + """ + + _client: SpannerClient + + DEFAULT_ENDPOINT = SpannerClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = SpannerClient.DEFAULT_MTLS_ENDPOINT + + database_path = staticmethod(SpannerClient.database_path) + parse_database_path = staticmethod(SpannerClient.parse_database_path) + session_path = staticmethod(SpannerClient.session_path) + parse_session_path = staticmethod(SpannerClient.parse_session_path) + common_billing_account_path = staticmethod(SpannerClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(SpannerClient.parse_common_billing_account_path) + common_folder_path = staticmethod(SpannerClient.common_folder_path) + parse_common_folder_path = staticmethod(SpannerClient.parse_common_folder_path) + common_organization_path = staticmethod(SpannerClient.common_organization_path) + parse_common_organization_path = staticmethod(SpannerClient.parse_common_organization_path) + common_project_path = staticmethod(SpannerClient.common_project_path) + parse_common_project_path = staticmethod(SpannerClient.parse_common_project_path) + common_location_path = staticmethod(SpannerClient.common_location_path) + parse_common_location_path = staticmethod(SpannerClient.parse_common_location_path) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + SpannerAsyncClient: The constructed client. + """ + return SpannerClient.from_service_account_info.__func__(SpannerAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + SpannerAsyncClient: The constructed client. + """ + return SpannerClient.from_service_account_file.__func__(SpannerAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @classmethod + def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[ClientOptions] = None): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variable is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return SpannerClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> SpannerTransport: + """Returns the transport used by the client instance. + + Returns: + SpannerTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial(type(SpannerClient).get_transport_class, type(SpannerClient)) + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Union[str, SpannerTransport] = "grpc_asyncio", + client_options: Optional[ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the spanner client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, ~.SpannerTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (ClientOptions): Custom options for the client. It + won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + """ + self._client = SpannerClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + async def create_session(self, + request: Optional[Union[spanner.CreateSessionRequest, dict]] = None, + *, + database: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner.Session: + r"""Creates a new session. A session can be used to perform + transactions that read and/or modify data in a Cloud Spanner + database. Sessions are meant to be reused for many consecutive + transactions. + + Sessions can only execute one transaction at a time. To execute + multiple concurrent read-write/write-only transactions, create + multiple sessions. Note that standalone reads and queries use a + transaction internally, and count toward the one transaction + limit. + + Active sessions use additional server resources, so it is a good + idea to delete idle and unneeded sessions. Aside from explicit + deletes, Cloud Spanner may delete sessions for which no + operations are sent for more than an hour. If a session is + deleted, requests to it return ``NOT_FOUND``. + + Idle sessions can be kept alive by sending a trivial SQL query + periodically, e.g., ``"SELECT 1"``. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_create_session(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.CreateSessionRequest( + database="database_value", + ) + + # Make the request + response = await client.create_session(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.CreateSessionRequest, dict]]): + The request object. The request for + [CreateSession][google.spanner.v1.Spanner.CreateSession]. + database (:class:`str`): + Required. The database in which the + new session is created. + + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.Session: + A session in the Cloud Spanner API. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner.CreateSessionRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.create_session, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("database", request.database), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def batch_create_sessions(self, + request: Optional[Union[spanner.BatchCreateSessionsRequest, dict]] = None, + *, + database: Optional[str] = None, + session_count: Optional[int] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner.BatchCreateSessionsResponse: + r"""Creates multiple new sessions. + This API can be used to initialize a session cache on + the clients. See https://goo.gl/TgSFN2 for best + practices on session cache management. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_batch_create_sessions(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.BatchCreateSessionsRequest( + database="database_value", + session_count=1420, + ) + + # Make the request + response = await client.batch_create_sessions(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.BatchCreateSessionsRequest, dict]]): + The request object. The request for + [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. + database (:class:`str`): + Required. The database in which the + new sessions are created. + + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + session_count (:class:`int`): + Required. The number of sessions to be created in this + batch call. The API may return fewer than the requested + number of sessions. If a specific number of sessions are + desired, the client can make additional calls to + BatchCreateSessions (adjusting + [session_count][google.spanner.v1.BatchCreateSessionsRequest.session_count] + as necessary). + + This corresponds to the ``session_count`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.BatchCreateSessionsResponse: + The response for + [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database, session_count]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner.BatchCreateSessionsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + if session_count is not None: + request.session_count = session_count + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.batch_create_sessions, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("database", request.database), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_session(self, + request: Optional[Union[spanner.GetSessionRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner.Session: + r"""Gets a session. Returns ``NOT_FOUND`` if the session does not + exist. This is mainly useful for determining whether a session + is still alive. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_get_session(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.GetSessionRequest( + name="name_value", + ) + + # Make the request + response = await client.get_session(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.GetSessionRequest, dict]]): + The request object. The request for + [GetSession][google.spanner.v1.Spanner.GetSession]. + name (:class:`str`): + Required. The name of the session to + retrieve. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.Session: + A session in the Cloud Spanner API. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner.GetSessionRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_session, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_sessions(self, + request: Optional[Union[spanner.ListSessionsRequest, dict]] = None, + *, + database: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListSessionsAsyncPager: + r"""Lists all sessions in a given database. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_list_sessions(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ListSessionsRequest( + database="database_value", + ) + + # Make the request + page_result = client.list_sessions(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.ListSessionsRequest, dict]]): + The request object. The request for + [ListSessions][google.spanner.v1.Spanner.ListSessions]. + database (:class:`str`): + Required. The database in which to + list sessions. + + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.services.spanner.pagers.ListSessionsAsyncPager: + The response for + [ListSessions][google.spanner.v1.Spanner.ListSessions]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner.ListSessionsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_sessions, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("database", request.database), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListSessionsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_session(self, + request: Optional[Union[spanner.DeleteSessionRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Ends a session, releasing server resources associated + with it. This will asynchronously trigger cancellation + of any operations that are running with this session. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_delete_session(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.DeleteSessionRequest( + name="name_value", + ) + + # Make the request + await client.delete_session(request=request) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.DeleteSessionRequest, dict]]): + The request object. The request for + [DeleteSession][google.spanner.v1.Spanner.DeleteSession]. + name (:class:`str`): + Required. The name of the session to + delete. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner.DeleteSessionRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.delete_session, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def execute_sql(self, + request: Optional[Union[spanner.ExecuteSqlRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> result_set.ResultSet: + r"""Executes an SQL statement, returning all results in a single + reply. This method cannot be used to return a result set larger + than 10 MiB; if the query yields more data than that, the query + fails with a ``FAILED_PRECONDITION`` error. + + Operations inside read-write transactions might return + ``ABORTED``. If this occurs, the application should restart the + transaction from the beginning. See + [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be fetched in streaming fashion by + calling + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] + instead. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_execute_sql(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = await client.execute_sql(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.ExecuteSqlRequest, dict]]): + The request object. The request for + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.ResultSet: + Results from [Read][google.spanner.v1.Spanner.Read] or + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. + + """ + # Create or coerce a protobuf request object. + request = spanner.ExecuteSqlRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.execute_sql, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def execute_streaming_sql(self, + request: Optional[Union[spanner.ExecuteSqlRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> Awaitable[AsyncIterable[result_set.PartialResultSet]]: + r"""Like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except + returns the result set as a stream. Unlike + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there is no + limit on the size of the returned result set. However, no + individual row in the result set can exceed 100 MiB, and no + column value can exceed 10 MiB. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_execute_streaming_sql(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + stream = await client.execute_streaming_sql(request=request) + + # Handle the response + async for response in stream: + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.ExecuteSqlRequest, dict]]): + The request object. The request for + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + AsyncIterable[google.cloud.spanner_v1.types.PartialResultSet]: + Partial results from a streaming read + or SQL query. Streaming reads and SQL + queries better tolerate large result + sets, large rows, and large values, but + are a little trickier to consume. + + """ + # Create or coerce a protobuf request object. + request = spanner.ExecuteSqlRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.execute_streaming_sql, + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def execute_batch_dml(self, + request: Optional[Union[spanner.ExecuteBatchDmlRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner.ExecuteBatchDmlResponse: + r"""Executes a batch of SQL DML statements. This method allows many + statements to be run with lower latency than submitting them + sequentially with + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. + + Statements are executed in sequential order. A request can + succeed even if a statement fails. The + [ExecuteBatchDmlResponse.status][google.spanner.v1.ExecuteBatchDmlResponse.status] + field in the response provides information about the statement + that failed. Clients must inspect this field to determine + whether an error occurred. + + Execution stops after the first failed statement; the remaining + statements are not executed. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_execute_batch_dml(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + statements = spanner_v1.Statement() + statements.sql = "sql_value" + + request = spanner_v1.ExecuteBatchDmlRequest( + session="session_value", + statements=statements, + seqno=550, + ) + + # Make the request + response = await client.execute_batch_dml(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.ExecuteBatchDmlRequest, dict]]): + The request object. The request for + [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.ExecuteBatchDmlResponse: + The response for [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. Contains a list + of [ResultSet][google.spanner.v1.ResultSet] messages, + one for each DML statement that has successfully + executed, in the same order as the statements in the + request. If a statement fails, the status in the + response body identifies the cause of the failure. + + To check for DML statements that failed, use the + following approach: + + 1. Check the status in the response message. The + [google.rpc.Code][google.rpc.Code] enum value OK + indicates that all statements were executed + successfully. + 2. If the status was not OK, check the number of + result sets in the response. If the response + contains N + [ResultSet][google.spanner.v1.ResultSet] messages, + then statement N+1 in the request failed. + + Example 1: + + - Request: 5 DML statements, all executed + successfully. + - Response: 5 + [ResultSet][google.spanner.v1.ResultSet] messages, + with the status OK. + + Example 2: + + - Request: 5 DML statements. The third statement has + a syntax error. + - Response: 2 + [ResultSet][google.spanner.v1.ResultSet] messages, + and a syntax error (INVALID_ARGUMENT) status. The + number of [ResultSet][google.spanner.v1.ResultSet] + messages indicates that the third statement + failed, and the fourth and fifth statements were + not executed. + + """ + # Create or coerce a protobuf request object. + request = spanner.ExecuteBatchDmlRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.execute_batch_dml, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def read(self, + request: Optional[Union[spanner.ReadRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> result_set.ResultSet: + r"""Reads rows from the database using key lookups and scans, as a + simple key/value style alternative to + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method + cannot be used to return a result set larger than 10 MiB; if the + read matches more data than that, the read fails with a + ``FAILED_PRECONDITION`` error. + + Reads inside read-write transactions might return ``ABORTED``. + If this occurs, the application should restart the transaction + from the beginning. See + [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be yielded in streaming fashion by + calling [StreamingRead][google.spanner.v1.Spanner.StreamingRead] + instead. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_read(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value1', 'columns_value2'], + ) + + # Make the request + response = await client.read(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.ReadRequest, dict]]): + The request object. The request for [Read][google.spanner.v1.Spanner.Read] + and + [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.ResultSet: + Results from [Read][google.spanner.v1.Spanner.Read] or + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. + + """ + # Create or coerce a protobuf request object. + request = spanner.ReadRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.read, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def streaming_read(self, + request: Optional[Union[spanner.ReadRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> Awaitable[AsyncIterable[result_set.PartialResultSet]]: + r"""Like [Read][google.spanner.v1.Spanner.Read], except returns the + result set as a stream. Unlike + [Read][google.spanner.v1.Spanner.Read], there is no limit on the + size of the returned result set. However, no individual row in + the result set can exceed 100 MiB, and no column value can + exceed 10 MiB. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_streaming_read(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value1', 'columns_value2'], + ) + + # Make the request + stream = await client.streaming_read(request=request) + + # Handle the response + async for response in stream: + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.ReadRequest, dict]]): + The request object. The request for [Read][google.spanner.v1.Spanner.Read] + and + [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + AsyncIterable[google.cloud.spanner_v1.types.PartialResultSet]: + Partial results from a streaming read + or SQL query. Streaming reads and SQL + queries better tolerate large result + sets, large rows, and large values, but + are a little trickier to consume. + + """ + # Create or coerce a protobuf request object. + request = spanner.ReadRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.streaming_read, + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def begin_transaction(self, + request: Optional[Union[spanner.BeginTransactionRequest, dict]] = None, + *, + session: Optional[str] = None, + options: Optional[transaction.TransactionOptions] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> transaction.Transaction: + r"""Begins a new transaction. This step can often be skipped: + [Read][google.spanner.v1.Spanner.Read], + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [Commit][google.spanner.v1.Spanner.Commit] can begin a new + transaction as a side-effect. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_begin_transaction(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.BeginTransactionRequest( + session="session_value", + ) + + # Make the request + response = await client.begin_transaction(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.BeginTransactionRequest, dict]]): + The request object. The request for + [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction]. + session (:class:`str`): + Required. The session in which the + transaction runs. + + This corresponds to the ``session`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + options (:class:`google.cloud.spanner_v1.types.TransactionOptions`): + Required. Options for the new + transaction. + + This corresponds to the ``options`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.Transaction: + A transaction. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([session, options]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner.BeginTransactionRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if session is not None: + request.session = session + if options is not None: + request.options = options + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.begin_transaction, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def commit(self, + request: Optional[Union[spanner.CommitRequest, dict]] = None, + *, + session: Optional[str] = None, + transaction_id: Optional[bytes] = None, + mutations: Optional[MutableSequence[mutation.Mutation]] = None, + single_use_transaction: Optional[transaction.TransactionOptions] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> commit_response.CommitResponse: + r"""Commits a transaction. The request includes the mutations to be + applied to rows in the database. + + ``Commit`` might return an ``ABORTED`` error. This can occur at + any time; commonly, the cause is conflicts with concurrent + transactions. However, it can also happen for a variety of other + reasons. If ``Commit`` returns ``ABORTED``, the caller should + re-attempt the transaction from the beginning, re-using the same + session. + + On very rare occasions, ``Commit`` might return ``UNKNOWN``. + This can happen, for example, if the client job experiences a 1+ + hour networking failure. At that point, Cloud Spanner has lost + track of the transaction outcome and we recommend that you + perform another read from the database to see the state of + things as they are now. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_commit(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.CommitRequest( + transaction_id=b'transaction_id_blob', + session="session_value", + ) + + # Make the request + response = await client.commit(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.CommitRequest, dict]]): + The request object. The request for + [Commit][google.spanner.v1.Spanner.Commit]. + session (:class:`str`): + Required. The session in which the + transaction to be committed is running. + + This corresponds to the ``session`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + transaction_id (:class:`bytes`): + Commit a previously-started + transaction. + + This corresponds to the ``transaction_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + mutations (:class:`MutableSequence[google.cloud.spanner_v1.types.Mutation]`): + The mutations to be executed when + this transaction commits. All mutations + are applied atomically, in the order + they appear in this list. + + This corresponds to the ``mutations`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + single_use_transaction (:class:`google.cloud.spanner_v1.types.TransactionOptions`): + Execute mutations in a temporary transaction. Note that + unlike commit of a previously-started transaction, + commit with a temporary transaction is non-idempotent. + That is, if the ``CommitRequest`` is sent to Cloud + Spanner more than once (for instance, due to retries in + the application, or in the transport library), it is + possible that the mutations are executed more than once. + If this is undesirable, use + [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction] + and [Commit][google.spanner.v1.Spanner.Commit] instead. + + This corresponds to the ``single_use_transaction`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.CommitResponse: + The response for + [Commit][google.spanner.v1.Spanner.Commit]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([session, transaction_id, mutations, single_use_transaction]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner.CommitRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if session is not None: + request.session = session + if transaction_id is not None: + request.transaction_id = transaction_id + if single_use_transaction is not None: + request.single_use_transaction = single_use_transaction + if mutations: + request.mutations.extend(mutations) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.commit, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def rollback(self, + request: Optional[Union[spanner.RollbackRequest, dict]] = None, + *, + session: Optional[str] = None, + transaction_id: Optional[bytes] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Rolls back a transaction, releasing any locks it holds. It is a + good idea to call this for any transaction that includes one or + more [Read][google.spanner.v1.Spanner.Read] or + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and + ultimately decides not to commit. + + ``Rollback`` returns ``OK`` if it successfully aborts the + transaction, the transaction was already aborted, or the + transaction is not found. ``Rollback`` never returns + ``ABORTED``. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_rollback(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.RollbackRequest( + session="session_value", + transaction_id=b'transaction_id_blob', + ) + + # Make the request + await client.rollback(request=request) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.RollbackRequest, dict]]): + The request object. The request for + [Rollback][google.spanner.v1.Spanner.Rollback]. + session (:class:`str`): + Required. The session in which the + transaction to roll back is running. + + This corresponds to the ``session`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + transaction_id (:class:`bytes`): + Required. The transaction to roll + back. + + This corresponds to the ``transaction_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([session, transaction_id]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner.RollbackRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if session is not None: + request.session = session + if transaction_id is not None: + request.transaction_id = transaction_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.rollback, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def partition_query(self, + request: Optional[Union[spanner.PartitionQueryRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner.PartitionResponse: + r"""Creates a set of partition tokens that can be used to execute a + query operation in parallel. Each of the returned partition + tokens can be used by + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] + to specify a subset of the query result to read. The same + session and read-only transaction must be used by the + PartitionQueryRequest used to create the partition tokens and + the ExecuteSqlRequests that use the partition tokens. + + Partition tokens become invalid when the session used to create + them is deleted, is idle for too long, begins a new transaction, + or becomes too old. When any of these happen, it is not possible + to resume the query, and the whole operation must be restarted + from the beginning. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_partition_query(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionQueryRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = await client.partition_query(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.PartitionQueryRequest, dict]]): + The request object. The request for + [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.PartitionResponse: + The response for [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] + or + [PartitionRead][google.spanner.v1.Spanner.PartitionRead] + + """ + # Create or coerce a protobuf request object. + request = spanner.PartitionQueryRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.partition_query, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def partition_read(self, + request: Optional[Union[spanner.PartitionReadRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner.PartitionResponse: + r"""Creates a set of partition tokens that can be used to execute a + read operation in parallel. Each of the returned partition + tokens can be used by + [StreamingRead][google.spanner.v1.Spanner.StreamingRead] to + specify a subset of the read result to read. The same session + and read-only transaction must be used by the + PartitionReadRequest used to create the partition tokens and the + ReadRequests that use the partition tokens. There are no + ordering guarantees on rows returned among the returned + partition tokens, or even within each individual StreamingRead + call issued with a partition_token. + + Partition tokens become invalid when the session used to create + them is deleted, is idle for too long, begins a new transaction, + or becomes too old. When any of these happen, it is not possible + to resume the read, and the whole operation must be restarted + from the beginning. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + async def sample_partition_read(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionReadRequest( + session="session_value", + table="table_value", + ) + + # Make the request + response = await client.partition_read(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_v1.types.PartitionReadRequest, dict]]): + The request object. The request for + [PartitionRead][google.spanner.v1.Spanner.PartitionRead] + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.PartitionResponse: + The response for [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] + or + [PartitionRead][google.spanner.v1.Spanner.PartitionRead] + + """ + # Create or coerce a protobuf request object. + request = spanner.PartitionReadRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.partition_read, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + + +__all__ = ( + "SpannerAsyncClient", +) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/client.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/client.py new file mode 100644 index 0000000000..c867967c7d --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/client.py @@ -0,0 +1,2062 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +import os +import re +from typing import Dict, Mapping, MutableMapping, MutableSequence, Optional, Iterable, Sequence, Tuple, Type, Union, cast + +from google.cloud.spanner_v1 import gapic_version as package_version + +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.cloud.spanner_v1.services.spanner import pagers +from google.cloud.spanner_v1.types import commit_response +from google.cloud.spanner_v1.types import mutation +from google.cloud.spanner_v1.types import result_set +from google.cloud.spanner_v1.types import spanner +from google.cloud.spanner_v1.types import transaction +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from .transports.base import SpannerTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import SpannerGrpcTransport +from .transports.grpc_asyncio import SpannerGrpcAsyncIOTransport +from .transports.rest import SpannerRestTransport + + +class SpannerClientMeta(type): + """Metaclass for the Spanner client. + + This provides class-level methods for building and retrieving + support objects (e.g. transport) without polluting the client instance + objects. + """ + _transport_registry = OrderedDict() # type: Dict[str, Type[SpannerTransport]] + _transport_registry["grpc"] = SpannerGrpcTransport + _transport_registry["grpc_asyncio"] = SpannerGrpcAsyncIOTransport + _transport_registry["rest"] = SpannerRestTransport + + def get_transport_class(cls, + label: Optional[str] = None, + ) -> Type[SpannerTransport]: + """Returns an appropriate transport class. + + Args: + label: The name of the desired transport. If none is + provided, then the first transport in the registry is used. + + Returns: + The transport class to use. + """ + # If a specific transport is requested, return that one. + if label: + return cls._transport_registry[label] + + # No transport is requested; return the default (that is, the first one + # in the dictionary). + return next(iter(cls._transport_registry.values())) + + +class SpannerClient(metaclass=SpannerClientMeta): + """Cloud Spanner API + The Cloud Spanner API can be used to manage sessions and execute + transactions on data stored in Cloud Spanner databases. + """ + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + str: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + DEFAULT_ENDPOINT = "spanner.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + SpannerClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + SpannerClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file( + filename) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> SpannerTransport: + """Returns the transport used by the client instance. + + Returns: + SpannerTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def database_path(project: str,instance: str,database: str,) -> str: + """Returns a fully-qualified database string.""" + return "projects/{project}/instances/{instance}/databases/{database}".format(project=project, instance=instance, database=database, ) + + @staticmethod + def parse_database_path(path: str) -> Dict[str,str]: + """Parses a database path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)/databases/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def session_path(project: str,instance: str,database: str,session: str,) -> str: + """Returns a fully-qualified session string.""" + return "projects/{project}/instances/{instance}/databases/{database}/sessions/{session}".format(project=project, instance=instance, database=database, session=session, ) + + @staticmethod + def parse_session_path(path: str) -> Dict[str,str]: + """Parses a session path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)/databases/(?P.+?)/sessions/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path(billing_account: str, ) -> str: + """Returns a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str,str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str, ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder, ) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str,str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str, ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization, ) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str,str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str, ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format(project=project, ) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str,str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str, ) -> str: + """Returns a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format(project=project, location=location, ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str,str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @classmethod + def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_options_lib.ClientOptions] = None): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variable is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[Union[str, SpannerTransport]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the spanner client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, SpannerTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the + client. It won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + """ + if isinstance(client_options, dict): + client_options = client_options_lib.from_dict(client_options) + if client_options is None: + client_options = client_options_lib.ClientOptions() + client_options = cast(client_options_lib.ClientOptions, client_options) + + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source(client_options) + + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError("client_options.api_key and credentials are mutually exclusive") + + # Save or instantiate the transport. + # Ordinarily, we provide the transport, but allowing a custom transport + # instance provides an extensibility point for unusual situations. + if isinstance(transport, SpannerTransport): + # transport is a SpannerTransport instance. + if credentials or client_options.credentials_file or api_key_value: + raise ValueError("When providing a transport instance, " + "provide its credentials directly.") + if client_options.scopes: + raise ValueError( + "When providing a transport instance, provide its scopes " + "directly." + ) + self._transport = transport + else: + import google.auth._default # type: ignore + + if api_key_value and hasattr(google.auth._default, "get_api_key_credentials"): + credentials = google.auth._default.get_api_key_credentials(api_key_value) + + Transport = type(self).get_transport_class(transport) + self._transport = Transport( + credentials=credentials, + credentials_file=client_options.credentials_file, + host=api_endpoint, + scopes=client_options.scopes, + client_cert_source_for_mtls=client_cert_source_func, + quota_project_id=client_options.quota_project_id, + client_info=client_info, + always_use_jwt_access=True, + api_audience=client_options.api_audience, + ) + + def create_session(self, + request: Optional[Union[spanner.CreateSessionRequest, dict]] = None, + *, + database: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner.Session: + r"""Creates a new session. A session can be used to perform + transactions that read and/or modify data in a Cloud Spanner + database. Sessions are meant to be reused for many consecutive + transactions. + + Sessions can only execute one transaction at a time. To execute + multiple concurrent read-write/write-only transactions, create + multiple sessions. Note that standalone reads and queries use a + transaction internally, and count toward the one transaction + limit. + + Active sessions use additional server resources, so it is a good + idea to delete idle and unneeded sessions. Aside from explicit + deletes, Cloud Spanner may delete sessions for which no + operations are sent for more than an hour. If a session is + deleted, requests to it return ``NOT_FOUND``. + + Idle sessions can be kept alive by sending a trivial SQL query + periodically, e.g., ``"SELECT 1"``. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_create_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.CreateSessionRequest( + database="database_value", + ) + + # Make the request + response = client.create_session(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_v1.types.CreateSessionRequest, dict]): + The request object. The request for + [CreateSession][google.spanner.v1.Spanner.CreateSession]. + database (str): + Required. The database in which the + new session is created. + + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.Session: + A session in the Cloud Spanner API. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner.CreateSessionRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.CreateSessionRequest): + request = spanner.CreateSessionRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_session] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("database", request.database), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def batch_create_sessions(self, + request: Optional[Union[spanner.BatchCreateSessionsRequest, dict]] = None, + *, + database: Optional[str] = None, + session_count: Optional[int] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner.BatchCreateSessionsResponse: + r"""Creates multiple new sessions. + This API can be used to initialize a session cache on + the clients. See https://goo.gl/TgSFN2 for best + practices on session cache management. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_batch_create_sessions(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.BatchCreateSessionsRequest( + database="database_value", + session_count=1420, + ) + + # Make the request + response = client.batch_create_sessions(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_v1.types.BatchCreateSessionsRequest, dict]): + The request object. The request for + [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. + database (str): + Required. The database in which the + new sessions are created. + + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + session_count (int): + Required. The number of sessions to be created in this + batch call. The API may return fewer than the requested + number of sessions. If a specific number of sessions are + desired, the client can make additional calls to + BatchCreateSessions (adjusting + [session_count][google.spanner.v1.BatchCreateSessionsRequest.session_count] + as necessary). + + This corresponds to the ``session_count`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.BatchCreateSessionsResponse: + The response for + [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database, session_count]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner.BatchCreateSessionsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.BatchCreateSessionsRequest): + request = spanner.BatchCreateSessionsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + if session_count is not None: + request.session_count = session_count + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.batch_create_sessions] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("database", request.database), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_session(self, + request: Optional[Union[spanner.GetSessionRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner.Session: + r"""Gets a session. Returns ``NOT_FOUND`` if the session does not + exist. This is mainly useful for determining whether a session + is still alive. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_get_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.GetSessionRequest( + name="name_value", + ) + + # Make the request + response = client.get_session(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_v1.types.GetSessionRequest, dict]): + The request object. The request for + [GetSession][google.spanner.v1.Spanner.GetSession]. + name (str): + Required. The name of the session to + retrieve. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.Session: + A session in the Cloud Spanner API. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner.GetSessionRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.GetSessionRequest): + request = spanner.GetSessionRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_session] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_sessions(self, + request: Optional[Union[spanner.ListSessionsRequest, dict]] = None, + *, + database: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListSessionsPager: + r"""Lists all sessions in a given database. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_list_sessions(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ListSessionsRequest( + database="database_value", + ) + + # Make the request + page_result = client.list_sessions(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.spanner_v1.types.ListSessionsRequest, dict]): + The request object. The request for + [ListSessions][google.spanner.v1.Spanner.ListSessions]. + database (str): + Required. The database in which to + list sessions. + + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.services.spanner.pagers.ListSessionsPager: + The response for + [ListSessions][google.spanner.v1.Spanner.ListSessions]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner.ListSessionsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.ListSessionsRequest): + request = spanner.ListSessionsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_sessions] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("database", request.database), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListSessionsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_session(self, + request: Optional[Union[spanner.DeleteSessionRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Ends a session, releasing server resources associated + with it. This will asynchronously trigger cancellation + of any operations that are running with this session. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_delete_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.DeleteSessionRequest( + name="name_value", + ) + + # Make the request + client.delete_session(request=request) + + Args: + request (Union[google.cloud.spanner_v1.types.DeleteSessionRequest, dict]): + The request object. The request for + [DeleteSession][google.spanner.v1.Spanner.DeleteSession]. + name (str): + Required. The name of the session to + delete. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner.DeleteSessionRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.DeleteSessionRequest): + request = spanner.DeleteSessionRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.delete_session] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def execute_sql(self, + request: Optional[Union[spanner.ExecuteSqlRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> result_set.ResultSet: + r"""Executes an SQL statement, returning all results in a single + reply. This method cannot be used to return a result set larger + than 10 MiB; if the query yields more data than that, the query + fails with a ``FAILED_PRECONDITION`` error. + + Operations inside read-write transactions might return + ``ABORTED``. If this occurs, the application should restart the + transaction from the beginning. See + [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be fetched in streaming fashion by + calling + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] + instead. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_execute_sql(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = client.execute_sql(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_v1.types.ExecuteSqlRequest, dict]): + The request object. The request for + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.ResultSet: + Results from [Read][google.spanner.v1.Spanner.Read] or + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a spanner.ExecuteSqlRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.ExecuteSqlRequest): + request = spanner.ExecuteSqlRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.execute_sql] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def execute_streaming_sql(self, + request: Optional[Union[spanner.ExecuteSqlRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> Iterable[result_set.PartialResultSet]: + r"""Like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except + returns the result set as a stream. Unlike + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there is no + limit on the size of the returned result set. However, no + individual row in the result set can exceed 100 MiB, and no + column value can exceed 10 MiB. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_execute_streaming_sql(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + stream = client.execute_streaming_sql(request=request) + + # Handle the response + for response in stream: + print(response) + + Args: + request (Union[google.cloud.spanner_v1.types.ExecuteSqlRequest, dict]): + The request object. The request for + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + Iterable[google.cloud.spanner_v1.types.PartialResultSet]: + Partial results from a streaming read + or SQL query. Streaming reads and SQL + queries better tolerate large result + sets, large rows, and large values, but + are a little trickier to consume. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a spanner.ExecuteSqlRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.ExecuteSqlRequest): + request = spanner.ExecuteSqlRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.execute_streaming_sql] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def execute_batch_dml(self, + request: Optional[Union[spanner.ExecuteBatchDmlRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner.ExecuteBatchDmlResponse: + r"""Executes a batch of SQL DML statements. This method allows many + statements to be run with lower latency than submitting them + sequentially with + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. + + Statements are executed in sequential order. A request can + succeed even if a statement fails. The + [ExecuteBatchDmlResponse.status][google.spanner.v1.ExecuteBatchDmlResponse.status] + field in the response provides information about the statement + that failed. Clients must inspect this field to determine + whether an error occurred. + + Execution stops after the first failed statement; the remaining + statements are not executed. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_execute_batch_dml(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + statements = spanner_v1.Statement() + statements.sql = "sql_value" + + request = spanner_v1.ExecuteBatchDmlRequest( + session="session_value", + statements=statements, + seqno=550, + ) + + # Make the request + response = client.execute_batch_dml(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_v1.types.ExecuteBatchDmlRequest, dict]): + The request object. The request for + [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.ExecuteBatchDmlResponse: + The response for [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. Contains a list + of [ResultSet][google.spanner.v1.ResultSet] messages, + one for each DML statement that has successfully + executed, in the same order as the statements in the + request. If a statement fails, the status in the + response body identifies the cause of the failure. + + To check for DML statements that failed, use the + following approach: + + 1. Check the status in the response message. The + [google.rpc.Code][google.rpc.Code] enum value OK + indicates that all statements were executed + successfully. + 2. If the status was not OK, check the number of + result sets in the response. If the response + contains N + [ResultSet][google.spanner.v1.ResultSet] messages, + then statement N+1 in the request failed. + + Example 1: + + - Request: 5 DML statements, all executed + successfully. + - Response: 5 + [ResultSet][google.spanner.v1.ResultSet] messages, + with the status OK. + + Example 2: + + - Request: 5 DML statements. The third statement has + a syntax error. + - Response: 2 + [ResultSet][google.spanner.v1.ResultSet] messages, + and a syntax error (INVALID_ARGUMENT) status. The + number of [ResultSet][google.spanner.v1.ResultSet] + messages indicates that the third statement + failed, and the fourth and fifth statements were + not executed. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a spanner.ExecuteBatchDmlRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.ExecuteBatchDmlRequest): + request = spanner.ExecuteBatchDmlRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.execute_batch_dml] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def read(self, + request: Optional[Union[spanner.ReadRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> result_set.ResultSet: + r"""Reads rows from the database using key lookups and scans, as a + simple key/value style alternative to + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method + cannot be used to return a result set larger than 10 MiB; if the + read matches more data than that, the read fails with a + ``FAILED_PRECONDITION`` error. + + Reads inside read-write transactions might return ``ABORTED``. + If this occurs, the application should restart the transaction + from the beginning. See + [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be yielded in streaming fashion by + calling [StreamingRead][google.spanner.v1.Spanner.StreamingRead] + instead. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value1', 'columns_value2'], + ) + + # Make the request + response = client.read(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_v1.types.ReadRequest, dict]): + The request object. The request for [Read][google.spanner.v1.Spanner.Read] + and + [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.ResultSet: + Results from [Read][google.spanner.v1.Spanner.Read] or + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a spanner.ReadRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.ReadRequest): + request = spanner.ReadRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.read] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def streaming_read(self, + request: Optional[Union[spanner.ReadRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> Iterable[result_set.PartialResultSet]: + r"""Like [Read][google.spanner.v1.Spanner.Read], except returns the + result set as a stream. Unlike + [Read][google.spanner.v1.Spanner.Read], there is no limit on the + size of the returned result set. However, no individual row in + the result set can exceed 100 MiB, and no column value can + exceed 10 MiB. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_streaming_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value1', 'columns_value2'], + ) + + # Make the request + stream = client.streaming_read(request=request) + + # Handle the response + for response in stream: + print(response) + + Args: + request (Union[google.cloud.spanner_v1.types.ReadRequest, dict]): + The request object. The request for [Read][google.spanner.v1.Spanner.Read] + and + [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + Iterable[google.cloud.spanner_v1.types.PartialResultSet]: + Partial results from a streaming read + or SQL query. Streaming reads and SQL + queries better tolerate large result + sets, large rows, and large values, but + are a little trickier to consume. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a spanner.ReadRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.ReadRequest): + request = spanner.ReadRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.streaming_read] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def begin_transaction(self, + request: Optional[Union[spanner.BeginTransactionRequest, dict]] = None, + *, + session: Optional[str] = None, + options: Optional[transaction.TransactionOptions] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> transaction.Transaction: + r"""Begins a new transaction. This step can often be skipped: + [Read][google.spanner.v1.Spanner.Read], + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [Commit][google.spanner.v1.Spanner.Commit] can begin a new + transaction as a side-effect. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_begin_transaction(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.BeginTransactionRequest( + session="session_value", + ) + + # Make the request + response = client.begin_transaction(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_v1.types.BeginTransactionRequest, dict]): + The request object. The request for + [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction]. + session (str): + Required. The session in which the + transaction runs. + + This corresponds to the ``session`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + options (google.cloud.spanner_v1.types.TransactionOptions): + Required. Options for the new + transaction. + + This corresponds to the ``options`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.Transaction: + A transaction. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([session, options]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner.BeginTransactionRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.BeginTransactionRequest): + request = spanner.BeginTransactionRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if session is not None: + request.session = session + if options is not None: + request.options = options + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.begin_transaction] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def commit(self, + request: Optional[Union[spanner.CommitRequest, dict]] = None, + *, + session: Optional[str] = None, + transaction_id: Optional[bytes] = None, + mutations: Optional[MutableSequence[mutation.Mutation]] = None, + single_use_transaction: Optional[transaction.TransactionOptions] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> commit_response.CommitResponse: + r"""Commits a transaction. The request includes the mutations to be + applied to rows in the database. + + ``Commit`` might return an ``ABORTED`` error. This can occur at + any time; commonly, the cause is conflicts with concurrent + transactions. However, it can also happen for a variety of other + reasons. If ``Commit`` returns ``ABORTED``, the caller should + re-attempt the transaction from the beginning, re-using the same + session. + + On very rare occasions, ``Commit`` might return ``UNKNOWN``. + This can happen, for example, if the client job experiences a 1+ + hour networking failure. At that point, Cloud Spanner has lost + track of the transaction outcome and we recommend that you + perform another read from the database to see the state of + things as they are now. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_commit(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.CommitRequest( + transaction_id=b'transaction_id_blob', + session="session_value", + ) + + # Make the request + response = client.commit(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_v1.types.CommitRequest, dict]): + The request object. The request for + [Commit][google.spanner.v1.Spanner.Commit]. + session (str): + Required. The session in which the + transaction to be committed is running. + + This corresponds to the ``session`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + transaction_id (bytes): + Commit a previously-started + transaction. + + This corresponds to the ``transaction_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + mutations (MutableSequence[google.cloud.spanner_v1.types.Mutation]): + The mutations to be executed when + this transaction commits. All mutations + are applied atomically, in the order + they appear in this list. + + This corresponds to the ``mutations`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + single_use_transaction (google.cloud.spanner_v1.types.TransactionOptions): + Execute mutations in a temporary transaction. Note that + unlike commit of a previously-started transaction, + commit with a temporary transaction is non-idempotent. + That is, if the ``CommitRequest`` is sent to Cloud + Spanner more than once (for instance, due to retries in + the application, or in the transport library), it is + possible that the mutations are executed more than once. + If this is undesirable, use + [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction] + and [Commit][google.spanner.v1.Spanner.Commit] instead. + + This corresponds to the ``single_use_transaction`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.CommitResponse: + The response for + [Commit][google.spanner.v1.Spanner.Commit]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([session, transaction_id, mutations, single_use_transaction]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner.CommitRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.CommitRequest): + request = spanner.CommitRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if session is not None: + request.session = session + if transaction_id is not None: + request.transaction_id = transaction_id + if mutations is not None: + request.mutations = mutations + if single_use_transaction is not None: + request.single_use_transaction = single_use_transaction + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.commit] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def rollback(self, + request: Optional[Union[spanner.RollbackRequest, dict]] = None, + *, + session: Optional[str] = None, + transaction_id: Optional[bytes] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Rolls back a transaction, releasing any locks it holds. It is a + good idea to call this for any transaction that includes one or + more [Read][google.spanner.v1.Spanner.Read] or + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and + ultimately decides not to commit. + + ``Rollback`` returns ``OK`` if it successfully aborts the + transaction, the transaction was already aborted, or the + transaction is not found. ``Rollback`` never returns + ``ABORTED``. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_rollback(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.RollbackRequest( + session="session_value", + transaction_id=b'transaction_id_blob', + ) + + # Make the request + client.rollback(request=request) + + Args: + request (Union[google.cloud.spanner_v1.types.RollbackRequest, dict]): + The request object. The request for + [Rollback][google.spanner.v1.Spanner.Rollback]. + session (str): + Required. The session in which the + transaction to roll back is running. + + This corresponds to the ``session`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + transaction_id (bytes): + Required. The transaction to roll + back. + + This corresponds to the ``transaction_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([session, transaction_id]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner.RollbackRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.RollbackRequest): + request = spanner.RollbackRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if session is not None: + request.session = session + if transaction_id is not None: + request.transaction_id = transaction_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.rollback] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def partition_query(self, + request: Optional[Union[spanner.PartitionQueryRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner.PartitionResponse: + r"""Creates a set of partition tokens that can be used to execute a + query operation in parallel. Each of the returned partition + tokens can be used by + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] + to specify a subset of the query result to read. The same + session and read-only transaction must be used by the + PartitionQueryRequest used to create the partition tokens and + the ExecuteSqlRequests that use the partition tokens. + + Partition tokens become invalid when the session used to create + them is deleted, is idle for too long, begins a new transaction, + or becomes too old. When any of these happen, it is not possible + to resume the query, and the whole operation must be restarted + from the beginning. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_partition_query(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionQueryRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = client.partition_query(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_v1.types.PartitionQueryRequest, dict]): + The request object. The request for + [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.PartitionResponse: + The response for [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] + or + [PartitionRead][google.spanner.v1.Spanner.PartitionRead] + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a spanner.PartitionQueryRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.PartitionQueryRequest): + request = spanner.PartitionQueryRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.partition_query] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def partition_read(self, + request: Optional[Union[spanner.PartitionReadRequest, dict]] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner.PartitionResponse: + r"""Creates a set of partition tokens that can be used to execute a + read operation in parallel. Each of the returned partition + tokens can be used by + [StreamingRead][google.spanner.v1.Spanner.StreamingRead] to + specify a subset of the read result to read. The same session + and read-only transaction must be used by the + PartitionReadRequest used to create the partition tokens and the + ReadRequests that use the partition tokens. There are no + ordering guarantees on rows returned among the returned + partition tokens, or even within each individual StreamingRead + call issued with a partition_token. + + Partition tokens become invalid when the session used to create + them is deleted, is idle for too long, begins a new transaction, + or becomes too old. When any of these happen, it is not possible + to resume the read, and the whole operation must be restarted + from the beginning. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_v1 + + def sample_partition_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionReadRequest( + session="session_value", + table="table_value", + ) + + # Make the request + response = client.partition_read(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_v1.types.PartitionReadRequest, dict]): + The request object. The request for + [PartitionRead][google.spanner.v1.Spanner.PartitionRead] + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_v1.types.PartitionResponse: + The response for [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] + or + [PartitionRead][google.spanner.v1.Spanner.PartitionRead] + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a spanner.PartitionReadRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner.PartitionReadRequest): + request = spanner.PartitionReadRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.partition_read] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("session", request.session), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self) -> "SpannerClient": + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + + + + + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + + +__all__ = ( + "SpannerClient", +) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/pagers.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/pagers.py new file mode 100644 index 0000000000..6036124ab4 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/pagers.py @@ -0,0 +1,139 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from typing import Any, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator + +from google.cloud.spanner_v1.types import spanner + + +class ListSessionsPager: + """A pager for iterating through ``list_sessions`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_v1.types.ListSessionsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``sessions`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListSessions`` requests and continue to iterate + through the ``sessions`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_v1.types.ListSessionsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., spanner.ListSessionsResponse], + request: spanner.ListSessionsRequest, + response: spanner.ListSessionsResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_v1.types.ListSessionsRequest): + The initial request object. + response (google.cloud.spanner_v1.types.ListSessionsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner.ListSessionsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[spanner.ListSessionsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[spanner.Session]: + for page in self.pages: + yield from page.sessions + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListSessionsAsyncPager: + """A pager for iterating through ``list_sessions`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_v1.types.ListSessionsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``sessions`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListSessions`` requests and continue to iterate + through the ``sessions`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_v1.types.ListSessionsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., Awaitable[spanner.ListSessionsResponse]], + request: spanner.ListSessionsRequest, + response: spanner.ListSessionsResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_v1.types.ListSessionsRequest): + The initial request object. + response (google.cloud.spanner_v1.types.ListSessionsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner.ListSessionsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[spanner.ListSessionsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + def __aiter__(self) -> AsyncIterator[spanner.Session]: + async def async_generator(): + async for page in self.pages: + for response in page.sessions: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/__init__.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/__init__.py new file mode 100644 index 0000000000..8451357b75 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/__init__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from typing import Dict, Type + +from .base import SpannerTransport +from .grpc import SpannerGrpcTransport +from .grpc_asyncio import SpannerGrpcAsyncIOTransport +from .rest import SpannerRestTransport +from .rest import SpannerRestInterceptor + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[SpannerTransport]] +_transport_registry['grpc'] = SpannerGrpcTransport +_transport_registry['grpc_asyncio'] = SpannerGrpcAsyncIOTransport +_transport_registry['rest'] = SpannerRestTransport + +__all__ = ( + 'SpannerTransport', + 'SpannerGrpcTransport', + 'SpannerGrpcAsyncIOTransport', + 'SpannerRestTransport', + 'SpannerRestInterceptor', +) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/base.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/base.py new file mode 100644 index 0000000000..fa0f6b008d --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/base.py @@ -0,0 +1,427 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union + +from google.cloud.spanner_v1 import gapic_version as package_version + +import google.auth # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.spanner_v1.types import commit_response +from google.cloud.spanner_v1.types import result_set +from google.cloud.spanner_v1.types import spanner +from google.cloud.spanner_v1.types import transaction +from google.protobuf import empty_pb2 # type: ignore + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + + +class SpannerTransport(abc.ABC): + """Abstract transport class for Spanner.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.data', + ) + + DEFAULT_HOST: str = 'spanner.googleapis.com' + def __init__( + self, *, + host: str = DEFAULT_HOST, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} + + # Save the scopes. + self._scopes = scopes + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, + **scopes_kwargs, + quota_project_id=quota_project_id + ) + elif credentials is None: + credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) + # Don't apply audience if the credentials file passed from user. + if hasattr(credentials, "with_gdch_audience"): + credentials = credentials.with_gdch_audience(api_audience if api_audience else host) + + # If the credentials are service account credentials, then always try to use self signed JWT. + if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ':' not in host: + host += ':443' + self._host = host + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.create_session: gapic_v1.method.wrap_method( + self.create_session, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=client_info, + ), + self.batch_create_sessions: gapic_v1.method.wrap_method( + self.batch_create_sessions, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=60.0, + ), + default_timeout=60.0, + client_info=client_info, + ), + self.get_session: gapic_v1.method.wrap_method( + self.get_session, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=client_info, + ), + self.list_sessions: gapic_v1.method.wrap_method( + self.list_sessions, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.delete_session: gapic_v1.method.wrap_method( + self.delete_session, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=client_info, + ), + self.execute_sql: gapic_v1.method.wrap_method( + self.execute_sql, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=client_info, + ), + self.execute_streaming_sql: gapic_v1.method.wrap_method( + self.execute_streaming_sql, + default_timeout=3600.0, + client_info=client_info, + ), + self.execute_batch_dml: gapic_v1.method.wrap_method( + self.execute_batch_dml, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=client_info, + ), + self.read: gapic_v1.method.wrap_method( + self.read, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=client_info, + ), + self.streaming_read: gapic_v1.method.wrap_method( + self.streaming_read, + default_timeout=3600.0, + client_info=client_info, + ), + self.begin_transaction: gapic_v1.method.wrap_method( + self.begin_transaction, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=client_info, + ), + self.commit: gapic_v1.method.wrap_method( + self.commit, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.rollback: gapic_v1.method.wrap_method( + self.rollback, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=client_info, + ), + self.partition_query: gapic_v1.method.wrap_method( + self.partition_query, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=client_info, + ), + self.partition_read: gapic_v1.method.wrap_method( + self.partition_read, + default_retry=retries.Retry( +initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def create_session(self) -> Callable[ + [spanner.CreateSessionRequest], + Union[ + spanner.Session, + Awaitable[spanner.Session] + ]]: + raise NotImplementedError() + + @property + def batch_create_sessions(self) -> Callable[ + [spanner.BatchCreateSessionsRequest], + Union[ + spanner.BatchCreateSessionsResponse, + Awaitable[spanner.BatchCreateSessionsResponse] + ]]: + raise NotImplementedError() + + @property + def get_session(self) -> Callable[ + [spanner.GetSessionRequest], + Union[ + spanner.Session, + Awaitable[spanner.Session] + ]]: + raise NotImplementedError() + + @property + def list_sessions(self) -> Callable[ + [spanner.ListSessionsRequest], + Union[ + spanner.ListSessionsResponse, + Awaitable[spanner.ListSessionsResponse] + ]]: + raise NotImplementedError() + + @property + def delete_session(self) -> Callable[ + [spanner.DeleteSessionRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def execute_sql(self) -> Callable[ + [spanner.ExecuteSqlRequest], + Union[ + result_set.ResultSet, + Awaitable[result_set.ResultSet] + ]]: + raise NotImplementedError() + + @property + def execute_streaming_sql(self) -> Callable[ + [spanner.ExecuteSqlRequest], + Union[ + result_set.PartialResultSet, + Awaitable[result_set.PartialResultSet] + ]]: + raise NotImplementedError() + + @property + def execute_batch_dml(self) -> Callable[ + [spanner.ExecuteBatchDmlRequest], + Union[ + spanner.ExecuteBatchDmlResponse, + Awaitable[spanner.ExecuteBatchDmlResponse] + ]]: + raise NotImplementedError() + + @property + def read(self) -> Callable[ + [spanner.ReadRequest], + Union[ + result_set.ResultSet, + Awaitable[result_set.ResultSet] + ]]: + raise NotImplementedError() + + @property + def streaming_read(self) -> Callable[ + [spanner.ReadRequest], + Union[ + result_set.PartialResultSet, + Awaitable[result_set.PartialResultSet] + ]]: + raise NotImplementedError() + + @property + def begin_transaction(self) -> Callable[ + [spanner.BeginTransactionRequest], + Union[ + transaction.Transaction, + Awaitable[transaction.Transaction] + ]]: + raise NotImplementedError() + + @property + def commit(self) -> Callable[ + [spanner.CommitRequest], + Union[ + commit_response.CommitResponse, + Awaitable[commit_response.CommitResponse] + ]]: + raise NotImplementedError() + + @property + def rollback(self) -> Callable[ + [spanner.RollbackRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def partition_query(self) -> Callable[ + [spanner.PartitionQueryRequest], + Union[ + spanner.PartitionResponse, + Awaitable[spanner.PartitionResponse] + ]]: + raise NotImplementedError() + + @property + def partition_read(self) -> Callable[ + [spanner.PartitionReadRequest], + Union[ + spanner.PartitionResponse, + Awaitable[spanner.PartitionResponse] + ]]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + + +__all__ = ( + 'SpannerTransport', +) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc.py new file mode 100644 index 0000000000..491151f614 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc.py @@ -0,0 +1,766 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore + +from google.cloud.spanner_v1.types import commit_response +from google.cloud.spanner_v1.types import result_set +from google.cloud.spanner_v1.types import spanner +from google.cloud.spanner_v1.types import transaction +from google.protobuf import empty_pb2 # type: ignore +from .base import SpannerTransport, DEFAULT_CLIENT_INFO + + +class SpannerGrpcTransport(SpannerTransport): + """gRPC backend transport for Spanner. + + Cloud Spanner API + The Cloud Spanner API can be used to manage sessions and execute + transactions on data stored in Cloud Spanner databases. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + _stubs: Dict[str, Callable] + + def __init__(self, *, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[grpc.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel(cls, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service. + """ + return self._grpc_channel + + @property + def create_session(self) -> Callable[ + [spanner.CreateSessionRequest], + spanner.Session]: + r"""Return a callable for the create session method over gRPC. + + Creates a new session. A session can be used to perform + transactions that read and/or modify data in a Cloud Spanner + database. Sessions are meant to be reused for many consecutive + transactions. + + Sessions can only execute one transaction at a time. To execute + multiple concurrent read-write/write-only transactions, create + multiple sessions. Note that standalone reads and queries use a + transaction internally, and count toward the one transaction + limit. + + Active sessions use additional server resources, so it is a good + idea to delete idle and unneeded sessions. Aside from explicit + deletes, Cloud Spanner may delete sessions for which no + operations are sent for more than an hour. If a session is + deleted, requests to it return ``NOT_FOUND``. + + Idle sessions can be kept alive by sending a trivial SQL query + periodically, e.g., ``"SELECT 1"``. + + Returns: + Callable[[~.CreateSessionRequest], + ~.Session]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'create_session' not in self._stubs: + self._stubs['create_session'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/CreateSession', + request_serializer=spanner.CreateSessionRequest.serialize, + response_deserializer=spanner.Session.deserialize, + ) + return self._stubs['create_session'] + + @property + def batch_create_sessions(self) -> Callable[ + [spanner.BatchCreateSessionsRequest], + spanner.BatchCreateSessionsResponse]: + r"""Return a callable for the batch create sessions method over gRPC. + + Creates multiple new sessions. + This API can be used to initialize a session cache on + the clients. See https://goo.gl/TgSFN2 for best + practices on session cache management. + + Returns: + Callable[[~.BatchCreateSessionsRequest], + ~.BatchCreateSessionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'batch_create_sessions' not in self._stubs: + self._stubs['batch_create_sessions'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/BatchCreateSessions', + request_serializer=spanner.BatchCreateSessionsRequest.serialize, + response_deserializer=spanner.BatchCreateSessionsResponse.deserialize, + ) + return self._stubs['batch_create_sessions'] + + @property + def get_session(self) -> Callable[ + [spanner.GetSessionRequest], + spanner.Session]: + r"""Return a callable for the get session method over gRPC. + + Gets a session. Returns ``NOT_FOUND`` if the session does not + exist. This is mainly useful for determining whether a session + is still alive. + + Returns: + Callable[[~.GetSessionRequest], + ~.Session]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_session' not in self._stubs: + self._stubs['get_session'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/GetSession', + request_serializer=spanner.GetSessionRequest.serialize, + response_deserializer=spanner.Session.deserialize, + ) + return self._stubs['get_session'] + + @property + def list_sessions(self) -> Callable[ + [spanner.ListSessionsRequest], + spanner.ListSessionsResponse]: + r"""Return a callable for the list sessions method over gRPC. + + Lists all sessions in a given database. + + Returns: + Callable[[~.ListSessionsRequest], + ~.ListSessionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_sessions' not in self._stubs: + self._stubs['list_sessions'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/ListSessions', + request_serializer=spanner.ListSessionsRequest.serialize, + response_deserializer=spanner.ListSessionsResponse.deserialize, + ) + return self._stubs['list_sessions'] + + @property + def delete_session(self) -> Callable[ + [spanner.DeleteSessionRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete session method over gRPC. + + Ends a session, releasing server resources associated + with it. This will asynchronously trigger cancellation + of any operations that are running with this session. + + Returns: + Callable[[~.DeleteSessionRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'delete_session' not in self._stubs: + self._stubs['delete_session'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/DeleteSession', + request_serializer=spanner.DeleteSessionRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_session'] + + @property + def execute_sql(self) -> Callable[ + [spanner.ExecuteSqlRequest], + result_set.ResultSet]: + r"""Return a callable for the execute sql method over gRPC. + + Executes an SQL statement, returning all results in a single + reply. This method cannot be used to return a result set larger + than 10 MiB; if the query yields more data than that, the query + fails with a ``FAILED_PRECONDITION`` error. + + Operations inside read-write transactions might return + ``ABORTED``. If this occurs, the application should restart the + transaction from the beginning. See + [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be fetched in streaming fashion by + calling + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] + instead. + + Returns: + Callable[[~.ExecuteSqlRequest], + ~.ResultSet]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'execute_sql' not in self._stubs: + self._stubs['execute_sql'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/ExecuteSql', + request_serializer=spanner.ExecuteSqlRequest.serialize, + response_deserializer=result_set.ResultSet.deserialize, + ) + return self._stubs['execute_sql'] + + @property + def execute_streaming_sql(self) -> Callable[ + [spanner.ExecuteSqlRequest], + result_set.PartialResultSet]: + r"""Return a callable for the execute streaming sql method over gRPC. + + Like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except + returns the result set as a stream. Unlike + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there is no + limit on the size of the returned result set. However, no + individual row in the result set can exceed 100 MiB, and no + column value can exceed 10 MiB. + + Returns: + Callable[[~.ExecuteSqlRequest], + ~.PartialResultSet]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'execute_streaming_sql' not in self._stubs: + self._stubs['execute_streaming_sql'] = self.grpc_channel.unary_stream( + '/google.spanner.v1.Spanner/ExecuteStreamingSql', + request_serializer=spanner.ExecuteSqlRequest.serialize, + response_deserializer=result_set.PartialResultSet.deserialize, + ) + return self._stubs['execute_streaming_sql'] + + @property + def execute_batch_dml(self) -> Callable[ + [spanner.ExecuteBatchDmlRequest], + spanner.ExecuteBatchDmlResponse]: + r"""Return a callable for the execute batch dml method over gRPC. + + Executes a batch of SQL DML statements. This method allows many + statements to be run with lower latency than submitting them + sequentially with + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. + + Statements are executed in sequential order. A request can + succeed even if a statement fails. The + [ExecuteBatchDmlResponse.status][google.spanner.v1.ExecuteBatchDmlResponse.status] + field in the response provides information about the statement + that failed. Clients must inspect this field to determine + whether an error occurred. + + Execution stops after the first failed statement; the remaining + statements are not executed. + + Returns: + Callable[[~.ExecuteBatchDmlRequest], + ~.ExecuteBatchDmlResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'execute_batch_dml' not in self._stubs: + self._stubs['execute_batch_dml'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/ExecuteBatchDml', + request_serializer=spanner.ExecuteBatchDmlRequest.serialize, + response_deserializer=spanner.ExecuteBatchDmlResponse.deserialize, + ) + return self._stubs['execute_batch_dml'] + + @property + def read(self) -> Callable[ + [spanner.ReadRequest], + result_set.ResultSet]: + r"""Return a callable for the read method over gRPC. + + Reads rows from the database using key lookups and scans, as a + simple key/value style alternative to + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method + cannot be used to return a result set larger than 10 MiB; if the + read matches more data than that, the read fails with a + ``FAILED_PRECONDITION`` error. + + Reads inside read-write transactions might return ``ABORTED``. + If this occurs, the application should restart the transaction + from the beginning. See + [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be yielded in streaming fashion by + calling [StreamingRead][google.spanner.v1.Spanner.StreamingRead] + instead. + + Returns: + Callable[[~.ReadRequest], + ~.ResultSet]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'read' not in self._stubs: + self._stubs['read'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/Read', + request_serializer=spanner.ReadRequest.serialize, + response_deserializer=result_set.ResultSet.deserialize, + ) + return self._stubs['read'] + + @property + def streaming_read(self) -> Callable[ + [spanner.ReadRequest], + result_set.PartialResultSet]: + r"""Return a callable for the streaming read method over gRPC. + + Like [Read][google.spanner.v1.Spanner.Read], except returns the + result set as a stream. Unlike + [Read][google.spanner.v1.Spanner.Read], there is no limit on the + size of the returned result set. However, no individual row in + the result set can exceed 100 MiB, and no column value can + exceed 10 MiB. + + Returns: + Callable[[~.ReadRequest], + ~.PartialResultSet]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'streaming_read' not in self._stubs: + self._stubs['streaming_read'] = self.grpc_channel.unary_stream( + '/google.spanner.v1.Spanner/StreamingRead', + request_serializer=spanner.ReadRequest.serialize, + response_deserializer=result_set.PartialResultSet.deserialize, + ) + return self._stubs['streaming_read'] + + @property + def begin_transaction(self) -> Callable[ + [spanner.BeginTransactionRequest], + transaction.Transaction]: + r"""Return a callable for the begin transaction method over gRPC. + + Begins a new transaction. This step can often be skipped: + [Read][google.spanner.v1.Spanner.Read], + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [Commit][google.spanner.v1.Spanner.Commit] can begin a new + transaction as a side-effect. + + Returns: + Callable[[~.BeginTransactionRequest], + ~.Transaction]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'begin_transaction' not in self._stubs: + self._stubs['begin_transaction'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/BeginTransaction', + request_serializer=spanner.BeginTransactionRequest.serialize, + response_deserializer=transaction.Transaction.deserialize, + ) + return self._stubs['begin_transaction'] + + @property + def commit(self) -> Callable[ + [spanner.CommitRequest], + commit_response.CommitResponse]: + r"""Return a callable for the commit method over gRPC. + + Commits a transaction. The request includes the mutations to be + applied to rows in the database. + + ``Commit`` might return an ``ABORTED`` error. This can occur at + any time; commonly, the cause is conflicts with concurrent + transactions. However, it can also happen for a variety of other + reasons. If ``Commit`` returns ``ABORTED``, the caller should + re-attempt the transaction from the beginning, re-using the same + session. + + On very rare occasions, ``Commit`` might return ``UNKNOWN``. + This can happen, for example, if the client job experiences a 1+ + hour networking failure. At that point, Cloud Spanner has lost + track of the transaction outcome and we recommend that you + perform another read from the database to see the state of + things as they are now. + + Returns: + Callable[[~.CommitRequest], + ~.CommitResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'commit' not in self._stubs: + self._stubs['commit'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/Commit', + request_serializer=spanner.CommitRequest.serialize, + response_deserializer=commit_response.CommitResponse.deserialize, + ) + return self._stubs['commit'] + + @property + def rollback(self) -> Callable[ + [spanner.RollbackRequest], + empty_pb2.Empty]: + r"""Return a callable for the rollback method over gRPC. + + Rolls back a transaction, releasing any locks it holds. It is a + good idea to call this for any transaction that includes one or + more [Read][google.spanner.v1.Spanner.Read] or + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and + ultimately decides not to commit. + + ``Rollback`` returns ``OK`` if it successfully aborts the + transaction, the transaction was already aborted, or the + transaction is not found. ``Rollback`` never returns + ``ABORTED``. + + Returns: + Callable[[~.RollbackRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'rollback' not in self._stubs: + self._stubs['rollback'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/Rollback', + request_serializer=spanner.RollbackRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['rollback'] + + @property + def partition_query(self) -> Callable[ + [spanner.PartitionQueryRequest], + spanner.PartitionResponse]: + r"""Return a callable for the partition query method over gRPC. + + Creates a set of partition tokens that can be used to execute a + query operation in parallel. Each of the returned partition + tokens can be used by + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] + to specify a subset of the query result to read. The same + session and read-only transaction must be used by the + PartitionQueryRequest used to create the partition tokens and + the ExecuteSqlRequests that use the partition tokens. + + Partition tokens become invalid when the session used to create + them is deleted, is idle for too long, begins a new transaction, + or becomes too old. When any of these happen, it is not possible + to resume the query, and the whole operation must be restarted + from the beginning. + + Returns: + Callable[[~.PartitionQueryRequest], + ~.PartitionResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'partition_query' not in self._stubs: + self._stubs['partition_query'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/PartitionQuery', + request_serializer=spanner.PartitionQueryRequest.serialize, + response_deserializer=spanner.PartitionResponse.deserialize, + ) + return self._stubs['partition_query'] + + @property + def partition_read(self) -> Callable[ + [spanner.PartitionReadRequest], + spanner.PartitionResponse]: + r"""Return a callable for the partition read method over gRPC. + + Creates a set of partition tokens that can be used to execute a + read operation in parallel. Each of the returned partition + tokens can be used by + [StreamingRead][google.spanner.v1.Spanner.StreamingRead] to + specify a subset of the read result to read. The same session + and read-only transaction must be used by the + PartitionReadRequest used to create the partition tokens and the + ReadRequests that use the partition tokens. There are no + ordering guarantees on rows returned among the returned + partition tokens, or even within each individual StreamingRead + call issued with a partition_token. + + Partition tokens become invalid when the session used to create + them is deleted, is idle for too long, begins a new transaction, + or becomes too old. When any of these happen, it is not possible + to resume the read, and the whole operation must be restarted + from the beginning. + + Returns: + Callable[[~.PartitionReadRequest], + ~.PartitionResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'partition_read' not in self._stubs: + self._stubs['partition_read'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/PartitionRead', + request_serializer=spanner.PartitionReadRequest.serialize, + response_deserializer=spanner.PartitionResponse.deserialize, + ) + return self._stubs['partition_read'] + + def close(self): + self.grpc_channel.close() + + @property + def kind(self) -> str: + return "grpc" + + +__all__ = ( + 'SpannerGrpcTransport', +) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py new file mode 100644 index 0000000000..1c749a4772 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py @@ -0,0 +1,765 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.spanner_v1.types import commit_response +from google.cloud.spanner_v1.types import result_set +from google.cloud.spanner_v1.types import spanner +from google.cloud.spanner_v1.types import transaction +from google.protobuf import empty_pb2 # type: ignore +from .base import SpannerTransport, DEFAULT_CLIENT_INFO +from .grpc import SpannerGrpcTransport + + +class SpannerGrpcAsyncIOTransport(SpannerTransport): + """gRPC AsyncIO backend transport for Spanner. + + Cloud Spanner API + The Cloud Spanner API can be used to manage sessions and execute + transactions on data stored in Cloud Spanner databases. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel(cls, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + def __init__(self, *, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[aio.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def create_session(self) -> Callable[ + [spanner.CreateSessionRequest], + Awaitable[spanner.Session]]: + r"""Return a callable for the create session method over gRPC. + + Creates a new session. A session can be used to perform + transactions that read and/or modify data in a Cloud Spanner + database. Sessions are meant to be reused for many consecutive + transactions. + + Sessions can only execute one transaction at a time. To execute + multiple concurrent read-write/write-only transactions, create + multiple sessions. Note that standalone reads and queries use a + transaction internally, and count toward the one transaction + limit. + + Active sessions use additional server resources, so it is a good + idea to delete idle and unneeded sessions. Aside from explicit + deletes, Cloud Spanner may delete sessions for which no + operations are sent for more than an hour. If a session is + deleted, requests to it return ``NOT_FOUND``. + + Idle sessions can be kept alive by sending a trivial SQL query + periodically, e.g., ``"SELECT 1"``. + + Returns: + Callable[[~.CreateSessionRequest], + Awaitable[~.Session]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'create_session' not in self._stubs: + self._stubs['create_session'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/CreateSession', + request_serializer=spanner.CreateSessionRequest.serialize, + response_deserializer=spanner.Session.deserialize, + ) + return self._stubs['create_session'] + + @property + def batch_create_sessions(self) -> Callable[ + [spanner.BatchCreateSessionsRequest], + Awaitable[spanner.BatchCreateSessionsResponse]]: + r"""Return a callable for the batch create sessions method over gRPC. + + Creates multiple new sessions. + This API can be used to initialize a session cache on + the clients. See https://goo.gl/TgSFN2 for best + practices on session cache management. + + Returns: + Callable[[~.BatchCreateSessionsRequest], + Awaitable[~.BatchCreateSessionsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'batch_create_sessions' not in self._stubs: + self._stubs['batch_create_sessions'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/BatchCreateSessions', + request_serializer=spanner.BatchCreateSessionsRequest.serialize, + response_deserializer=spanner.BatchCreateSessionsResponse.deserialize, + ) + return self._stubs['batch_create_sessions'] + + @property + def get_session(self) -> Callable[ + [spanner.GetSessionRequest], + Awaitable[spanner.Session]]: + r"""Return a callable for the get session method over gRPC. + + Gets a session. Returns ``NOT_FOUND`` if the session does not + exist. This is mainly useful for determining whether a session + is still alive. + + Returns: + Callable[[~.GetSessionRequest], + Awaitable[~.Session]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_session' not in self._stubs: + self._stubs['get_session'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/GetSession', + request_serializer=spanner.GetSessionRequest.serialize, + response_deserializer=spanner.Session.deserialize, + ) + return self._stubs['get_session'] + + @property + def list_sessions(self) -> Callable[ + [spanner.ListSessionsRequest], + Awaitable[spanner.ListSessionsResponse]]: + r"""Return a callable for the list sessions method over gRPC. + + Lists all sessions in a given database. + + Returns: + Callable[[~.ListSessionsRequest], + Awaitable[~.ListSessionsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_sessions' not in self._stubs: + self._stubs['list_sessions'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/ListSessions', + request_serializer=spanner.ListSessionsRequest.serialize, + response_deserializer=spanner.ListSessionsResponse.deserialize, + ) + return self._stubs['list_sessions'] + + @property + def delete_session(self) -> Callable[ + [spanner.DeleteSessionRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete session method over gRPC. + + Ends a session, releasing server resources associated + with it. This will asynchronously trigger cancellation + of any operations that are running with this session. + + Returns: + Callable[[~.DeleteSessionRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'delete_session' not in self._stubs: + self._stubs['delete_session'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/DeleteSession', + request_serializer=spanner.DeleteSessionRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_session'] + + @property + def execute_sql(self) -> Callable[ + [spanner.ExecuteSqlRequest], + Awaitable[result_set.ResultSet]]: + r"""Return a callable for the execute sql method over gRPC. + + Executes an SQL statement, returning all results in a single + reply. This method cannot be used to return a result set larger + than 10 MiB; if the query yields more data than that, the query + fails with a ``FAILED_PRECONDITION`` error. + + Operations inside read-write transactions might return + ``ABORTED``. If this occurs, the application should restart the + transaction from the beginning. See + [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be fetched in streaming fashion by + calling + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] + instead. + + Returns: + Callable[[~.ExecuteSqlRequest], + Awaitable[~.ResultSet]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'execute_sql' not in self._stubs: + self._stubs['execute_sql'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/ExecuteSql', + request_serializer=spanner.ExecuteSqlRequest.serialize, + response_deserializer=result_set.ResultSet.deserialize, + ) + return self._stubs['execute_sql'] + + @property + def execute_streaming_sql(self) -> Callable[ + [spanner.ExecuteSqlRequest], + Awaitable[result_set.PartialResultSet]]: + r"""Return a callable for the execute streaming sql method over gRPC. + + Like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except + returns the result set as a stream. Unlike + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there is no + limit on the size of the returned result set. However, no + individual row in the result set can exceed 100 MiB, and no + column value can exceed 10 MiB. + + Returns: + Callable[[~.ExecuteSqlRequest], + Awaitable[~.PartialResultSet]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'execute_streaming_sql' not in self._stubs: + self._stubs['execute_streaming_sql'] = self.grpc_channel.unary_stream( + '/google.spanner.v1.Spanner/ExecuteStreamingSql', + request_serializer=spanner.ExecuteSqlRequest.serialize, + response_deserializer=result_set.PartialResultSet.deserialize, + ) + return self._stubs['execute_streaming_sql'] + + @property + def execute_batch_dml(self) -> Callable[ + [spanner.ExecuteBatchDmlRequest], + Awaitable[spanner.ExecuteBatchDmlResponse]]: + r"""Return a callable for the execute batch dml method over gRPC. + + Executes a batch of SQL DML statements. This method allows many + statements to be run with lower latency than submitting them + sequentially with + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. + + Statements are executed in sequential order. A request can + succeed even if a statement fails. The + [ExecuteBatchDmlResponse.status][google.spanner.v1.ExecuteBatchDmlResponse.status] + field in the response provides information about the statement + that failed. Clients must inspect this field to determine + whether an error occurred. + + Execution stops after the first failed statement; the remaining + statements are not executed. + + Returns: + Callable[[~.ExecuteBatchDmlRequest], + Awaitable[~.ExecuteBatchDmlResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'execute_batch_dml' not in self._stubs: + self._stubs['execute_batch_dml'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/ExecuteBatchDml', + request_serializer=spanner.ExecuteBatchDmlRequest.serialize, + response_deserializer=spanner.ExecuteBatchDmlResponse.deserialize, + ) + return self._stubs['execute_batch_dml'] + + @property + def read(self) -> Callable[ + [spanner.ReadRequest], + Awaitable[result_set.ResultSet]]: + r"""Return a callable for the read method over gRPC. + + Reads rows from the database using key lookups and scans, as a + simple key/value style alternative to + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method + cannot be used to return a result set larger than 10 MiB; if the + read matches more data than that, the read fails with a + ``FAILED_PRECONDITION`` error. + + Reads inside read-write transactions might return ``ABORTED``. + If this occurs, the application should restart the transaction + from the beginning. See + [Transaction][google.spanner.v1.Transaction] for more details. + + Larger result sets can be yielded in streaming fashion by + calling [StreamingRead][google.spanner.v1.Spanner.StreamingRead] + instead. + + Returns: + Callable[[~.ReadRequest], + Awaitable[~.ResultSet]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'read' not in self._stubs: + self._stubs['read'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/Read', + request_serializer=spanner.ReadRequest.serialize, + response_deserializer=result_set.ResultSet.deserialize, + ) + return self._stubs['read'] + + @property + def streaming_read(self) -> Callable[ + [spanner.ReadRequest], + Awaitable[result_set.PartialResultSet]]: + r"""Return a callable for the streaming read method over gRPC. + + Like [Read][google.spanner.v1.Spanner.Read], except returns the + result set as a stream. Unlike + [Read][google.spanner.v1.Spanner.Read], there is no limit on the + size of the returned result set. However, no individual row in + the result set can exceed 100 MiB, and no column value can + exceed 10 MiB. + + Returns: + Callable[[~.ReadRequest], + Awaitable[~.PartialResultSet]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'streaming_read' not in self._stubs: + self._stubs['streaming_read'] = self.grpc_channel.unary_stream( + '/google.spanner.v1.Spanner/StreamingRead', + request_serializer=spanner.ReadRequest.serialize, + response_deserializer=result_set.PartialResultSet.deserialize, + ) + return self._stubs['streaming_read'] + + @property + def begin_transaction(self) -> Callable[ + [spanner.BeginTransactionRequest], + Awaitable[transaction.Transaction]]: + r"""Return a callable for the begin transaction method over gRPC. + + Begins a new transaction. This step can often be skipped: + [Read][google.spanner.v1.Spanner.Read], + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [Commit][google.spanner.v1.Spanner.Commit] can begin a new + transaction as a side-effect. + + Returns: + Callable[[~.BeginTransactionRequest], + Awaitable[~.Transaction]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'begin_transaction' not in self._stubs: + self._stubs['begin_transaction'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/BeginTransaction', + request_serializer=spanner.BeginTransactionRequest.serialize, + response_deserializer=transaction.Transaction.deserialize, + ) + return self._stubs['begin_transaction'] + + @property + def commit(self) -> Callable[ + [spanner.CommitRequest], + Awaitable[commit_response.CommitResponse]]: + r"""Return a callable for the commit method over gRPC. + + Commits a transaction. The request includes the mutations to be + applied to rows in the database. + + ``Commit`` might return an ``ABORTED`` error. This can occur at + any time; commonly, the cause is conflicts with concurrent + transactions. However, it can also happen for a variety of other + reasons. If ``Commit`` returns ``ABORTED``, the caller should + re-attempt the transaction from the beginning, re-using the same + session. + + On very rare occasions, ``Commit`` might return ``UNKNOWN``. + This can happen, for example, if the client job experiences a 1+ + hour networking failure. At that point, Cloud Spanner has lost + track of the transaction outcome and we recommend that you + perform another read from the database to see the state of + things as they are now. + + Returns: + Callable[[~.CommitRequest], + Awaitable[~.CommitResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'commit' not in self._stubs: + self._stubs['commit'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/Commit', + request_serializer=spanner.CommitRequest.serialize, + response_deserializer=commit_response.CommitResponse.deserialize, + ) + return self._stubs['commit'] + + @property + def rollback(self) -> Callable[ + [spanner.RollbackRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the rollback method over gRPC. + + Rolls back a transaction, releasing any locks it holds. It is a + good idea to call this for any transaction that includes one or + more [Read][google.spanner.v1.Spanner.Read] or + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and + ultimately decides not to commit. + + ``Rollback`` returns ``OK`` if it successfully aborts the + transaction, the transaction was already aborted, or the + transaction is not found. ``Rollback`` never returns + ``ABORTED``. + + Returns: + Callable[[~.RollbackRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'rollback' not in self._stubs: + self._stubs['rollback'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/Rollback', + request_serializer=spanner.RollbackRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['rollback'] + + @property + def partition_query(self) -> Callable[ + [spanner.PartitionQueryRequest], + Awaitable[spanner.PartitionResponse]]: + r"""Return a callable for the partition query method over gRPC. + + Creates a set of partition tokens that can be used to execute a + query operation in parallel. Each of the returned partition + tokens can be used by + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] + to specify a subset of the query result to read. The same + session and read-only transaction must be used by the + PartitionQueryRequest used to create the partition tokens and + the ExecuteSqlRequests that use the partition tokens. + + Partition tokens become invalid when the session used to create + them is deleted, is idle for too long, begins a new transaction, + or becomes too old. When any of these happen, it is not possible + to resume the query, and the whole operation must be restarted + from the beginning. + + Returns: + Callable[[~.PartitionQueryRequest], + Awaitable[~.PartitionResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'partition_query' not in self._stubs: + self._stubs['partition_query'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/PartitionQuery', + request_serializer=spanner.PartitionQueryRequest.serialize, + response_deserializer=spanner.PartitionResponse.deserialize, + ) + return self._stubs['partition_query'] + + @property + def partition_read(self) -> Callable[ + [spanner.PartitionReadRequest], + Awaitable[spanner.PartitionResponse]]: + r"""Return a callable for the partition read method over gRPC. + + Creates a set of partition tokens that can be used to execute a + read operation in parallel. Each of the returned partition + tokens can be used by + [StreamingRead][google.spanner.v1.Spanner.StreamingRead] to + specify a subset of the read result to read. The same session + and read-only transaction must be used by the + PartitionReadRequest used to create the partition tokens and the + ReadRequests that use the partition tokens. There are no + ordering guarantees on rows returned among the returned + partition tokens, or even within each individual StreamingRead + call issued with a partition_token. + + Partition tokens become invalid when the session used to create + them is deleted, is idle for too long, begins a new transaction, + or becomes too old. When any of these happen, it is not possible + to resume the read, and the whole operation must be restarted + from the beginning. + + Returns: + Callable[[~.PartitionReadRequest], + Awaitable[~.PartitionResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'partition_read' not in self._stubs: + self._stubs['partition_read'] = self.grpc_channel.unary_unary( + '/google.spanner.v1.Spanner/PartitionRead', + request_serializer=spanner.PartitionReadRequest.serialize, + response_deserializer=spanner.PartitionResponse.deserialize, + ) + return self._stubs['partition_read'] + + def close(self): + return self.grpc_channel.close() + + +__all__ = ( + 'SpannerGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/rest.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/rest.py new file mode 100644 index 0000000000..d7bff17364 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/rest.py @@ -0,0 +1,1973 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from google.auth.transport.requests import AuthorizedSession # type: ignore +import json # type: ignore +import grpc # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.api_core import exceptions as core_exceptions +from google.api_core import retry as retries +from google.api_core import rest_helpers +from google.api_core import rest_streaming +from google.api_core import path_template +from google.api_core import gapic_v1 + +from google.protobuf import json_format +from requests import __version__ as requests_version +import dataclasses +import re +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +import warnings + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + + +from google.cloud.spanner_v1.types import commit_response +from google.cloud.spanner_v1.types import result_set +from google.cloud.spanner_v1.types import spanner +from google.cloud.spanner_v1.types import transaction +from google.protobuf import empty_pb2 # type: ignore + +from .base import SpannerTransport, DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, + grpc_version=None, + rest_version=requests_version, +) + + +class SpannerRestInterceptor: + """Interceptor for Spanner. + + Interceptors are used to manipulate requests, request metadata, and responses + in arbitrary ways. + Example use cases include: + * Logging + * Verifying requests according to service or custom semantics + * Stripping extraneous information from responses + + These use cases and more can be enabled by injecting an + instance of a custom subclass when constructing the SpannerRestTransport. + + .. code-block:: python + class MyCustomSpannerInterceptor(SpannerRestInterceptor): + def pre_batch_create_sessions(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_batch_create_sessions(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_begin_transaction(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_begin_transaction(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_commit(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_commit(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_create_session(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_create_session(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_delete_session(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def pre_execute_batch_dml(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_execute_batch_dml(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_execute_sql(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_execute_sql(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_execute_streaming_sql(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_execute_streaming_sql(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_get_session(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_session(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_list_sessions(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_sessions(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_partition_query(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_partition_query(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_partition_read(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_partition_read(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_read(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_read(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_rollback(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def pre_streaming_read(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_streaming_read(self, response): + logging.log(f"Received response: {response}") + return response + + transport = SpannerRestTransport(interceptor=MyCustomSpannerInterceptor()) + client = SpannerClient(transport=transport) + + + """ + def pre_batch_create_sessions(self, request: spanner.BatchCreateSessionsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.BatchCreateSessionsRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for batch_create_sessions + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def post_batch_create_sessions(self, response: spanner.BatchCreateSessionsResponse) -> spanner.BatchCreateSessionsResponse: + """Post-rpc interceptor for batch_create_sessions + + Override in a subclass to manipulate the response + after it is returned by the Spanner server but before + it is returned to user code. + """ + return response + def pre_begin_transaction(self, request: spanner.BeginTransactionRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.BeginTransactionRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for begin_transaction + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def post_begin_transaction(self, response: transaction.Transaction) -> transaction.Transaction: + """Post-rpc interceptor for begin_transaction + + Override in a subclass to manipulate the response + after it is returned by the Spanner server but before + it is returned to user code. + """ + return response + def pre_commit(self, request: spanner.CommitRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.CommitRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for commit + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def post_commit(self, response: commit_response.CommitResponse) -> commit_response.CommitResponse: + """Post-rpc interceptor for commit + + Override in a subclass to manipulate the response + after it is returned by the Spanner server but before + it is returned to user code. + """ + return response + def pre_create_session(self, request: spanner.CreateSessionRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.CreateSessionRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for create_session + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def post_create_session(self, response: spanner.Session) -> spanner.Session: + """Post-rpc interceptor for create_session + + Override in a subclass to manipulate the response + after it is returned by the Spanner server but before + it is returned to user code. + """ + return response + def pre_delete_session(self, request: spanner.DeleteSessionRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.DeleteSessionRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for delete_session + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def pre_execute_batch_dml(self, request: spanner.ExecuteBatchDmlRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.ExecuteBatchDmlRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for execute_batch_dml + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def post_execute_batch_dml(self, response: spanner.ExecuteBatchDmlResponse) -> spanner.ExecuteBatchDmlResponse: + """Post-rpc interceptor for execute_batch_dml + + Override in a subclass to manipulate the response + after it is returned by the Spanner server but before + it is returned to user code. + """ + return response + def pre_execute_sql(self, request: spanner.ExecuteSqlRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.ExecuteSqlRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for execute_sql + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def post_execute_sql(self, response: result_set.ResultSet) -> result_set.ResultSet: + """Post-rpc interceptor for execute_sql + + Override in a subclass to manipulate the response + after it is returned by the Spanner server but before + it is returned to user code. + """ + return response + def pre_execute_streaming_sql(self, request: spanner.ExecuteSqlRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.ExecuteSqlRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for execute_streaming_sql + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def post_execute_streaming_sql(self, response: rest_streaming.ResponseIterator) -> rest_streaming.ResponseIterator: + """Post-rpc interceptor for execute_streaming_sql + + Override in a subclass to manipulate the response + after it is returned by the Spanner server but before + it is returned to user code. + """ + return response + def pre_get_session(self, request: spanner.GetSessionRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.GetSessionRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for get_session + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def post_get_session(self, response: spanner.Session) -> spanner.Session: + """Post-rpc interceptor for get_session + + Override in a subclass to manipulate the response + after it is returned by the Spanner server but before + it is returned to user code. + """ + return response + def pre_list_sessions(self, request: spanner.ListSessionsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.ListSessionsRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for list_sessions + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def post_list_sessions(self, response: spanner.ListSessionsResponse) -> spanner.ListSessionsResponse: + """Post-rpc interceptor for list_sessions + + Override in a subclass to manipulate the response + after it is returned by the Spanner server but before + it is returned to user code. + """ + return response + def pre_partition_query(self, request: spanner.PartitionQueryRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.PartitionQueryRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for partition_query + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def post_partition_query(self, response: spanner.PartitionResponse) -> spanner.PartitionResponse: + """Post-rpc interceptor for partition_query + + Override in a subclass to manipulate the response + after it is returned by the Spanner server but before + it is returned to user code. + """ + return response + def pre_partition_read(self, request: spanner.PartitionReadRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.PartitionReadRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for partition_read + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def post_partition_read(self, response: spanner.PartitionResponse) -> spanner.PartitionResponse: + """Post-rpc interceptor for partition_read + + Override in a subclass to manipulate the response + after it is returned by the Spanner server but before + it is returned to user code. + """ + return response + def pre_read(self, request: spanner.ReadRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.ReadRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for read + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def post_read(self, response: result_set.ResultSet) -> result_set.ResultSet: + """Post-rpc interceptor for read + + Override in a subclass to manipulate the response + after it is returned by the Spanner server but before + it is returned to user code. + """ + return response + def pre_rollback(self, request: spanner.RollbackRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.RollbackRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for rollback + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def pre_streaming_read(self, request: spanner.ReadRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.ReadRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for streaming_read + + Override in a subclass to manipulate the request or metadata + before they are sent to the Spanner server. + """ + return request, metadata + + def post_streaming_read(self, response: rest_streaming.ResponseIterator) -> rest_streaming.ResponseIterator: + """Post-rpc interceptor for streaming_read + + Override in a subclass to manipulate the response + after it is returned by the Spanner server but before + it is returned to user code. + """ + return response + + +@dataclasses.dataclass +class SpannerRestStub: + _session: AuthorizedSession + _host: str + _interceptor: SpannerRestInterceptor + + +class SpannerRestTransport(SpannerTransport): + """REST backend transport for Spanner. + + Cloud Spanner API + The Cloud Spanner API can be used to manage sessions and execute + transactions on data stored in Cloud Spanner databases. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends JSON representations of protocol buffers over HTTP/1.1 + + """ + + def __init__(self, *, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + client_cert_source_for_mtls: Optional[Callable[[ + ], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = 'https', + interceptor: Optional[SpannerRestInterceptor] = None, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client + certificate to configure mutual TLS HTTP channel. It is ignored + if ``channel`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you are developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + url_scheme: the protocol scheme for the API endpoint. Normally + "https", but for testing or local servers, + "http" can be specified. + """ + # Run the base constructor + # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. + # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the + # credentials object + maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) + if maybe_url_match is None: + raise ValueError(f"Unexpected hostname structure: {host}") # pragma: NO COVER + + url_match_items = maybe_url_match.groupdict() + + host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host + + super().__init__( + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience + ) + self._session = AuthorizedSession( + self._credentials, default_host=self.DEFAULT_HOST) + if client_cert_source_for_mtls: + self._session.configure_mtls_channel(client_cert_source_for_mtls) + self._interceptor = interceptor or SpannerRestInterceptor() + self._prep_wrapped_messages(client_info) + + class _BatchCreateSessions(SpannerRestStub): + def __hash__(self): + return hash("BatchCreateSessions") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.BatchCreateSessionsRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner.BatchCreateSessionsResponse: + r"""Call the batch create sessions method over HTTP. + + Args: + request (~.spanner.BatchCreateSessionsRequest): + The request object. The request for + [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner.BatchCreateSessionsResponse: + The response for + [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{database=projects/*/instances/*/databases/*}/sessions:batchCreate', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_batch_create_sessions(request, metadata) + pb_request = spanner.BatchCreateSessionsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner.BatchCreateSessionsResponse() + pb_resp = spanner.BatchCreateSessionsResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_batch_create_sessions(resp) + return resp + + class _BeginTransaction(SpannerRestStub): + def __hash__(self): + return hash("BeginTransaction") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.BeginTransactionRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> transaction.Transaction: + r"""Call the begin transaction method over HTTP. + + Args: + request (~.spanner.BeginTransactionRequest): + The request object. The request for + [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.transaction.Transaction: + A transaction. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:beginTransaction', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_begin_transaction(request, metadata) + pb_request = spanner.BeginTransactionRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = transaction.Transaction() + pb_resp = transaction.Transaction.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_begin_transaction(resp) + return resp + + class _Commit(SpannerRestStub): + def __hash__(self): + return hash("Commit") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.CommitRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> commit_response.CommitResponse: + r"""Call the commit method over HTTP. + + Args: + request (~.spanner.CommitRequest): + The request object. The request for + [Commit][google.spanner.v1.Spanner.Commit]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.commit_response.CommitResponse: + The response for + [Commit][google.spanner.v1.Spanner.Commit]. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:commit', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_commit(request, metadata) + pb_request = spanner.CommitRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = commit_response.CommitResponse() + pb_resp = commit_response.CommitResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_commit(resp) + return resp + + class _CreateSession(SpannerRestStub): + def __hash__(self): + return hash("CreateSession") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.CreateSessionRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner.Session: + r"""Call the create session method over HTTP. + + Args: + request (~.spanner.CreateSessionRequest): + The request object. The request for + [CreateSession][google.spanner.v1.Spanner.CreateSession]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner.Session: + A session in the Cloud Spanner API. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{database=projects/*/instances/*/databases/*}/sessions', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_create_session(request, metadata) + pb_request = spanner.CreateSessionRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner.Session() + pb_resp = spanner.Session.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_session(resp) + return resp + + class _DeleteSession(SpannerRestStub): + def __hash__(self): + return hash("DeleteSession") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.DeleteSessionRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ): + r"""Call the delete session method over HTTP. + + Args: + request (~.spanner.DeleteSessionRequest): + The request object. The request for + [DeleteSession][google.spanner.v1.Spanner.DeleteSession]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'delete', + 'uri': '/v1/{name=projects/*/instances/*/databases/*/sessions/*}', + }, + ] + request, metadata = self._interceptor.pre_delete_session(request, metadata) + pb_request = spanner.DeleteSessionRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + class _ExecuteBatchDml(SpannerRestStub): + def __hash__(self): + return hash("ExecuteBatchDml") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.ExecuteBatchDmlRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner.ExecuteBatchDmlResponse: + r"""Call the execute batch dml method over HTTP. + + Args: + request (~.spanner.ExecuteBatchDmlRequest): + The request object. The request for + [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner.ExecuteBatchDmlResponse: + The response for + [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. + Contains a list of + [ResultSet][google.spanner.v1.ResultSet] messages, one + for each DML statement that has successfully executed, + in the same order as the statements in the request. If a + statement fails, the status in the response body + identifies the cause of the failure. + + To check for DML statements that failed, use the + following approach: + + 1. Check the status in the response message. The + [google.rpc.Code][google.rpc.Code] enum value ``OK`` + indicates that all statements were executed + successfully. + 2. If the status was not ``OK``, check the number of + result sets in the response. If the response contains + ``N`` [ResultSet][google.spanner.v1.ResultSet] + messages, then statement ``N+1`` in the request + failed. + + Example 1: + + - Request: 5 DML statements, all executed successfully. + - Response: 5 [ResultSet][google.spanner.v1.ResultSet] + messages, with the status ``OK``. + + Example 2: + + - Request: 5 DML statements. The third statement has a + syntax error. + - Response: 2 [ResultSet][google.spanner.v1.ResultSet] + messages, and a syntax error (``INVALID_ARGUMENT``) + status. The number of + [ResultSet][google.spanner.v1.ResultSet] messages + indicates that the third statement failed, and the + fourth and fifth statements were not executed. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeBatchDml', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_execute_batch_dml(request, metadata) + pb_request = spanner.ExecuteBatchDmlRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner.ExecuteBatchDmlResponse() + pb_resp = spanner.ExecuteBatchDmlResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_execute_batch_dml(resp) + return resp + + class _ExecuteSql(SpannerRestStub): + def __hash__(self): + return hash("ExecuteSql") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.ExecuteSqlRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> result_set.ResultSet: + r"""Call the execute sql method over HTTP. + + Args: + request (~.spanner.ExecuteSqlRequest): + The request object. The request for + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.result_set.ResultSet: + Results from [Read][google.spanner.v1.Spanner.Read] or + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeSql', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_execute_sql(request, metadata) + pb_request = spanner.ExecuteSqlRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = result_set.ResultSet() + pb_resp = result_set.ResultSet.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_execute_sql(resp) + return resp + + class _ExecuteStreamingSql(SpannerRestStub): + def __hash__(self): + return hash("ExecuteStreamingSql") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.ExecuteSqlRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> rest_streaming.ResponseIterator: + r"""Call the execute streaming sql method over HTTP. + + Args: + request (~.spanner.ExecuteSqlRequest): + The request object. The request for + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.result_set.PartialResultSet: + Partial results from a streaming read + or SQL query. Streaming reads and SQL + queries better tolerate large result + sets, large rows, and large values, but + are a little trickier to consume. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeStreamingSql', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_execute_streaming_sql(request, metadata) + pb_request = spanner.ExecuteSqlRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = rest_streaming.ResponseIterator(response, result_set.PartialResultSet) + resp = self._interceptor.post_execute_streaming_sql(resp) + return resp + + class _GetSession(SpannerRestStub): + def __hash__(self): + return hash("GetSession") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.GetSessionRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner.Session: + r"""Call the get session method over HTTP. + + Args: + request (~.spanner.GetSessionRequest): + The request object. The request for + [GetSession][google.spanner.v1.Spanner.GetSession]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner.Session: + A session in the Cloud Spanner API. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/databases/*/sessions/*}', + }, + ] + request, metadata = self._interceptor.pre_get_session(request, metadata) + pb_request = spanner.GetSessionRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner.Session() + pb_resp = spanner.Session.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_session(resp) + return resp + + class _ListSessions(SpannerRestStub): + def __hash__(self): + return hash("ListSessions") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.ListSessionsRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner.ListSessionsResponse: + r"""Call the list sessions method over HTTP. + + Args: + request (~.spanner.ListSessionsRequest): + The request object. The request for + [ListSessions][google.spanner.v1.Spanner.ListSessions]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner.ListSessionsResponse: + The response for + [ListSessions][google.spanner.v1.Spanner.ListSessions]. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{database=projects/*/instances/*/databases/*}/sessions', + }, + ] + request, metadata = self._interceptor.pre_list_sessions(request, metadata) + pb_request = spanner.ListSessionsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner.ListSessionsResponse() + pb_resp = spanner.ListSessionsResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_sessions(resp) + return resp + + class _PartitionQuery(SpannerRestStub): + def __hash__(self): + return hash("PartitionQuery") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.PartitionQueryRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner.PartitionResponse: + r"""Call the partition query method over HTTP. + + Args: + request (~.spanner.PartitionQueryRequest): + The request object. The request for + [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner.PartitionResponse: + The response for + [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] + or + [PartitionRead][google.spanner.v1.Spanner.PartitionRead] + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:partitionQuery', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_partition_query(request, metadata) + pb_request = spanner.PartitionQueryRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner.PartitionResponse() + pb_resp = spanner.PartitionResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_partition_query(resp) + return resp + + class _PartitionRead(SpannerRestStub): + def __hash__(self): + return hash("PartitionRead") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.PartitionReadRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner.PartitionResponse: + r"""Call the partition read method over HTTP. + + Args: + request (~.spanner.PartitionReadRequest): + The request object. The request for + [PartitionRead][google.spanner.v1.Spanner.PartitionRead] + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner.PartitionResponse: + The response for + [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] + or + [PartitionRead][google.spanner.v1.Spanner.PartitionRead] + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:partitionRead', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_partition_read(request, metadata) + pb_request = spanner.PartitionReadRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner.PartitionResponse() + pb_resp = spanner.PartitionResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_partition_read(resp) + return resp + + class _Read(SpannerRestStub): + def __hash__(self): + return hash("Read") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.ReadRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> result_set.ResultSet: + r"""Call the read method over HTTP. + + Args: + request (~.spanner.ReadRequest): + The request object. The request for [Read][google.spanner.v1.Spanner.Read] + and + [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.result_set.ResultSet: + Results from [Read][google.spanner.v1.Spanner.Read] or + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:read', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_read(request, metadata) + pb_request = spanner.ReadRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = result_set.ResultSet() + pb_resp = result_set.ResultSet.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_read(resp) + return resp + + class _Rollback(SpannerRestStub): + def __hash__(self): + return hash("Rollback") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.RollbackRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ): + r"""Call the rollback method over HTTP. + + Args: + request (~.spanner.RollbackRequest): + The request object. The request for + [Rollback][google.spanner.v1.Spanner.Rollback]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:rollback', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_rollback(request, metadata) + pb_request = spanner.RollbackRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + class _StreamingRead(SpannerRestStub): + def __hash__(self): + return hash("StreamingRead") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner.ReadRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> rest_streaming.ResponseIterator: + r"""Call the streaming read method over HTTP. + + Args: + request (~.spanner.ReadRequest): + The request object. The request for [Read][google.spanner.v1.Spanner.Read] + and + [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.result_set.PartialResultSet: + Partial results from a streaming read + or SQL query. Streaming reads and SQL + queries better tolerate large result + sets, large rows, and large values, but + are a little trickier to consume. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:streamingRead', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_streaming_read(request, metadata) + pb_request = spanner.ReadRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = rest_streaming.ResponseIterator(response, result_set.PartialResultSet) + resp = self._interceptor.post_streaming_read(resp) + return resp + + @property + def batch_create_sessions(self) -> Callable[ + [spanner.BatchCreateSessionsRequest], + spanner.BatchCreateSessionsResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._BatchCreateSessions(self._session, self._host, self._interceptor) # type: ignore + + @property + def begin_transaction(self) -> Callable[ + [spanner.BeginTransactionRequest], + transaction.Transaction]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._BeginTransaction(self._session, self._host, self._interceptor) # type: ignore + + @property + def commit(self) -> Callable[ + [spanner.CommitRequest], + commit_response.CommitResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._Commit(self._session, self._host, self._interceptor) # type: ignore + + @property + def create_session(self) -> Callable[ + [spanner.CreateSessionRequest], + spanner.Session]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._CreateSession(self._session, self._host, self._interceptor) # type: ignore + + @property + def delete_session(self) -> Callable[ + [spanner.DeleteSessionRequest], + empty_pb2.Empty]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._DeleteSession(self._session, self._host, self._interceptor) # type: ignore + + @property + def execute_batch_dml(self) -> Callable[ + [spanner.ExecuteBatchDmlRequest], + spanner.ExecuteBatchDmlResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ExecuteBatchDml(self._session, self._host, self._interceptor) # type: ignore + + @property + def execute_sql(self) -> Callable[ + [spanner.ExecuteSqlRequest], + result_set.ResultSet]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ExecuteSql(self._session, self._host, self._interceptor) # type: ignore + + @property + def execute_streaming_sql(self) -> Callable[ + [spanner.ExecuteSqlRequest], + result_set.PartialResultSet]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ExecuteStreamingSql(self._session, self._host, self._interceptor) # type: ignore + + @property + def get_session(self) -> Callable[ + [spanner.GetSessionRequest], + spanner.Session]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetSession(self._session, self._host, self._interceptor) # type: ignore + + @property + def list_sessions(self) -> Callable[ + [spanner.ListSessionsRequest], + spanner.ListSessionsResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListSessions(self._session, self._host, self._interceptor) # type: ignore + + @property + def partition_query(self) -> Callable[ + [spanner.PartitionQueryRequest], + spanner.PartitionResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._PartitionQuery(self._session, self._host, self._interceptor) # type: ignore + + @property + def partition_read(self) -> Callable[ + [spanner.PartitionReadRequest], + spanner.PartitionResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._PartitionRead(self._session, self._host, self._interceptor) # type: ignore + + @property + def read(self) -> Callable[ + [spanner.ReadRequest], + result_set.ResultSet]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._Read(self._session, self._host, self._interceptor) # type: ignore + + @property + def rollback(self) -> Callable[ + [spanner.RollbackRequest], + empty_pb2.Empty]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._Rollback(self._session, self._host, self._interceptor) # type: ignore + + @property + def streaming_read(self) -> Callable[ + [spanner.ReadRequest], + result_set.PartialResultSet]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._StreamingRead(self._session, self._host, self._interceptor) # type: ignore + + @property + def kind(self) -> str: + return "rest" + + def close(self): + self._session.close() + + +__all__=( + 'SpannerRestTransport', +) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/__init__.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/__init__.py new file mode 100644 index 0000000000..b4d0d630da --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/__init__.py @@ -0,0 +1,110 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .commit_response import ( + CommitResponse, +) +from .keys import ( + KeyRange, + KeySet, +) +from .mutation import ( + Mutation, +) +from .query_plan import ( + PlanNode, + QueryPlan, +) +from .result_set import ( + PartialResultSet, + ResultSet, + ResultSetMetadata, + ResultSetStats, +) +from .spanner import ( + BatchCreateSessionsRequest, + BatchCreateSessionsResponse, + BeginTransactionRequest, + CommitRequest, + CreateSessionRequest, + DeleteSessionRequest, + ExecuteBatchDmlRequest, + ExecuteBatchDmlResponse, + ExecuteSqlRequest, + GetSessionRequest, + ListSessionsRequest, + ListSessionsResponse, + Partition, + PartitionOptions, + PartitionQueryRequest, + PartitionReadRequest, + PartitionResponse, + ReadRequest, + RequestOptions, + RollbackRequest, + Session, +) +from .transaction import ( + Transaction, + TransactionOptions, + TransactionSelector, +) +from .type import ( + StructType, + Type, + TypeAnnotationCode, + TypeCode, +) + +__all__ = ( + 'CommitResponse', + 'KeyRange', + 'KeySet', + 'Mutation', + 'PlanNode', + 'QueryPlan', + 'PartialResultSet', + 'ResultSet', + 'ResultSetMetadata', + 'ResultSetStats', + 'BatchCreateSessionsRequest', + 'BatchCreateSessionsResponse', + 'BeginTransactionRequest', + 'CommitRequest', + 'CreateSessionRequest', + 'DeleteSessionRequest', + 'ExecuteBatchDmlRequest', + 'ExecuteBatchDmlResponse', + 'ExecuteSqlRequest', + 'GetSessionRequest', + 'ListSessionsRequest', + 'ListSessionsResponse', + 'Partition', + 'PartitionOptions', + 'PartitionQueryRequest', + 'PartitionReadRequest', + 'PartitionResponse', + 'ReadRequest', + 'RequestOptions', + 'RollbackRequest', + 'Session', + 'Transaction', + 'TransactionOptions', + 'TransactionSelector', + 'StructType', + 'Type', + 'TypeAnnotationCode', + 'TypeCode', +) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/commit_response.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/commit_response.py new file mode 100644 index 0000000000..086a93d37e --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/commit_response.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.spanner.v1', + manifest={ + 'CommitResponse', + }, +) + + +class CommitResponse(proto.Message): + r"""The response for [Commit][google.spanner.v1.Spanner.Commit]. + + Attributes: + commit_timestamp (google.protobuf.timestamp_pb2.Timestamp): + The Cloud Spanner timestamp at which the + transaction committed. + commit_stats (google.cloud.spanner_v1.types.CommitResponse.CommitStats): + The statistics about this Commit. Not returned by default. + For more information, see + [CommitRequest.return_commit_stats][google.spanner.v1.CommitRequest.return_commit_stats]. + """ + + class CommitStats(proto.Message): + r"""Additional statistics about a commit. + + Attributes: + mutation_count (int): + The total number of mutations for the transaction. Knowing + the ``mutation_count`` value can help you maximize the + number of mutations in a transaction and minimize the number + of API round trips. You can also monitor this value to + prevent transactions from exceeding the system + `limit `__. + If the number of mutations exceeds the limit, the server + returns + `INVALID_ARGUMENT `__. + """ + + mutation_count: int = proto.Field( + proto.INT64, + number=1, + ) + + commit_timestamp: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=1, + message=timestamp_pb2.Timestamp, + ) + commit_stats: CommitStats = proto.Field( + proto.MESSAGE, + number=2, + message=CommitStats, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/keys.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/keys.py new file mode 100644 index 0000000000..ad0814437d --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/keys.py @@ -0,0 +1,248 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.protobuf import struct_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.spanner.v1', + manifest={ + 'KeyRange', + 'KeySet', + }, +) + + +class KeyRange(proto.Message): + r"""KeyRange represents a range of rows in a table or index. + + A range has a start key and an end key. These keys can be open or + closed, indicating if the range includes rows with that key. + + Keys are represented by lists, where the ith value in the list + corresponds to the ith component of the table or index primary key. + Individual values are encoded as described + [here][google.spanner.v1.TypeCode]. + + For example, consider the following table definition: + + :: + + CREATE TABLE UserEvents ( + UserName STRING(MAX), + EventDate STRING(10) + ) PRIMARY KEY(UserName, EventDate); + + The following keys name rows in this table: + + :: + + ["Bob", "2014-09-23"] + ["Alfred", "2015-06-12"] + + Since the ``UserEvents`` table's ``PRIMARY KEY`` clause names two + columns, each ``UserEvents`` key has two elements; the first is the + ``UserName``, and the second is the ``EventDate``. + + Key ranges with multiple components are interpreted + lexicographically by component using the table or index key's + declared sort order. For example, the following range returns all + events for user ``"Bob"`` that occurred in the year 2015: + + :: + + "start_closed": ["Bob", "2015-01-01"] + "end_closed": ["Bob", "2015-12-31"] + + Start and end keys can omit trailing key components. This affects + the inclusion and exclusion of rows that exactly match the provided + key components: if the key is closed, then rows that exactly match + the provided components are included; if the key is open, then rows + that exactly match are not included. + + For example, the following range includes all events for ``"Bob"`` + that occurred during and after the year 2000: + + :: + + "start_closed": ["Bob", "2000-01-01"] + "end_closed": ["Bob"] + + The next example retrieves all events for ``"Bob"``: + + :: + + "start_closed": ["Bob"] + "end_closed": ["Bob"] + + To retrieve events before the year 2000: + + :: + + "start_closed": ["Bob"] + "end_open": ["Bob", "2000-01-01"] + + The following range includes all rows in the table: + + :: + + "start_closed": [] + "end_closed": [] + + This range returns all users whose ``UserName`` begins with any + character from A to C: + + :: + + "start_closed": ["A"] + "end_open": ["D"] + + This range returns all users whose ``UserName`` begins with B: + + :: + + "start_closed": ["B"] + "end_open": ["C"] + + Key ranges honor column sort order. For example, suppose a table is + defined as follows: + + :: + + CREATE TABLE DescendingSortedTable { + Key INT64, + ... + ) PRIMARY KEY(Key DESC); + + The following range retrieves all rows with key values between 1 and + 100 inclusive: + + :: + + "start_closed": ["100"] + "end_closed": ["1"] + + Note that 100 is passed as the start, and 1 is passed as the end, + because ``Key`` is a descending column in the schema. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + start_closed (google.protobuf.struct_pb2.ListValue): + If the start is closed, then the range includes all rows + whose first ``len(start_closed)`` key columns exactly match + ``start_closed``. + + This field is a member of `oneof`_ ``start_key_type``. + start_open (google.protobuf.struct_pb2.ListValue): + If the start is open, then the range excludes rows whose + first ``len(start_open)`` key columns exactly match + ``start_open``. + + This field is a member of `oneof`_ ``start_key_type``. + end_closed (google.protobuf.struct_pb2.ListValue): + If the end is closed, then the range includes all rows whose + first ``len(end_closed)`` key columns exactly match + ``end_closed``. + + This field is a member of `oneof`_ ``end_key_type``. + end_open (google.protobuf.struct_pb2.ListValue): + If the end is open, then the range excludes rows whose first + ``len(end_open)`` key columns exactly match ``end_open``. + + This field is a member of `oneof`_ ``end_key_type``. + """ + + start_closed: struct_pb2.ListValue = proto.Field( + proto.MESSAGE, + number=1, + oneof='start_key_type', + message=struct_pb2.ListValue, + ) + start_open: struct_pb2.ListValue = proto.Field( + proto.MESSAGE, + number=2, + oneof='start_key_type', + message=struct_pb2.ListValue, + ) + end_closed: struct_pb2.ListValue = proto.Field( + proto.MESSAGE, + number=3, + oneof='end_key_type', + message=struct_pb2.ListValue, + ) + end_open: struct_pb2.ListValue = proto.Field( + proto.MESSAGE, + number=4, + oneof='end_key_type', + message=struct_pb2.ListValue, + ) + + +class KeySet(proto.Message): + r"""``KeySet`` defines a collection of Cloud Spanner keys and/or key + ranges. All the keys are expected to be in the same table or index. + The keys need not be sorted in any particular way. + + If the same key is specified multiple times in the set (for example + if two ranges, two keys, or a key and a range overlap), Cloud + Spanner behaves as if the key were only specified once. + + Attributes: + keys (MutableSequence[google.protobuf.struct_pb2.ListValue]): + A list of specific keys. Entries in ``keys`` should have + exactly as many elements as there are columns in the primary + or index key with which this ``KeySet`` is used. Individual + key values are encoded as described + [here][google.spanner.v1.TypeCode]. + ranges (MutableSequence[google.cloud.spanner_v1.types.KeyRange]): + A list of key ranges. See + [KeyRange][google.spanner.v1.KeyRange] for more information + about key range specifications. + all_ (bool): + For convenience ``all`` can be set to ``true`` to indicate + that this ``KeySet`` matches all keys in the table or index. + Note that any keys specified in ``keys`` or ``ranges`` are + only yielded once. + """ + + keys: MutableSequence[struct_pb2.ListValue] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=struct_pb2.ListValue, + ) + ranges: MutableSequence['KeyRange'] = proto.RepeatedField( + proto.MESSAGE, + number=2, + message='KeyRange', + ) + all_: bool = proto.Field( + proto.BOOL, + number=3, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/mutation.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/mutation.py new file mode 100644 index 0000000000..8cfd519da0 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/mutation.py @@ -0,0 +1,201 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.cloud.spanner_v1.types import keys +from google.protobuf import struct_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.spanner.v1', + manifest={ + 'Mutation', + }, +) + + +class Mutation(proto.Message): + r"""A modification to one or more Cloud Spanner rows. Mutations can be + applied to a Cloud Spanner database by sending them in a + [Commit][google.spanner.v1.Spanner.Commit] call. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + insert (google.cloud.spanner_v1.types.Mutation.Write): + Insert new rows in a table. If any of the rows already + exist, the write or transaction fails with error + ``ALREADY_EXISTS``. + + This field is a member of `oneof`_ ``operation``. + update (google.cloud.spanner_v1.types.Mutation.Write): + Update existing rows in a table. If any of the rows does not + already exist, the transaction fails with error + ``NOT_FOUND``. + + This field is a member of `oneof`_ ``operation``. + insert_or_update (google.cloud.spanner_v1.types.Mutation.Write): + Like [insert][google.spanner.v1.Mutation.insert], except + that if the row already exists, then its column values are + overwritten with the ones provided. Any column values not + explicitly written are preserved. + + When using + [insert_or_update][google.spanner.v1.Mutation.insert_or_update], + just as when using + [insert][google.spanner.v1.Mutation.insert], all + ``NOT NULL`` columns in the table must be given a value. + This holds true even when the row already exists and will + therefore actually be updated. + + This field is a member of `oneof`_ ``operation``. + replace (google.cloud.spanner_v1.types.Mutation.Write): + Like [insert][google.spanner.v1.Mutation.insert], except + that if the row already exists, it is deleted, and the + column values provided are inserted instead. Unlike + [insert_or_update][google.spanner.v1.Mutation.insert_or_update], + this means any values not explicitly written become + ``NULL``. + + In an interleaved table, if you create the child table with + the ``ON DELETE CASCADE`` annotation, then replacing a + parent row also deletes the child rows. Otherwise, you must + delete the child rows before you replace the parent row. + + This field is a member of `oneof`_ ``operation``. + delete (google.cloud.spanner_v1.types.Mutation.Delete): + Delete rows from a table. Succeeds whether or + not the named rows were present. + + This field is a member of `oneof`_ ``operation``. + """ + + class Write(proto.Message): + r"""Arguments to [insert][google.spanner.v1.Mutation.insert], + [update][google.spanner.v1.Mutation.update], + [insert_or_update][google.spanner.v1.Mutation.insert_or_update], and + [replace][google.spanner.v1.Mutation.replace] operations. + + Attributes: + table (str): + Required. The table whose rows will be + written. + columns (MutableSequence[str]): + The names of the columns in + [table][google.spanner.v1.Mutation.Write.table] to be + written. + + The list of columns must contain enough columns to allow + Cloud Spanner to derive values for all primary key columns + in the row(s) to be modified. + values (MutableSequence[google.protobuf.struct_pb2.ListValue]): + The values to be written. ``values`` can contain more than + one list of values. If it does, then multiple rows are + written, one for each entry in ``values``. Each list in + ``values`` must have exactly as many entries as there are + entries in + [columns][google.spanner.v1.Mutation.Write.columns] above. + Sending multiple lists is equivalent to sending multiple + ``Mutation``\ s, each containing one ``values`` entry and + repeating [table][google.spanner.v1.Mutation.Write.table] + and [columns][google.spanner.v1.Mutation.Write.columns]. + Individual values in each list are encoded as described + [here][google.spanner.v1.TypeCode]. + """ + + table: str = proto.Field( + proto.STRING, + number=1, + ) + columns: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=2, + ) + values: MutableSequence[struct_pb2.ListValue] = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=struct_pb2.ListValue, + ) + + class Delete(proto.Message): + r"""Arguments to [delete][google.spanner.v1.Mutation.delete] operations. + + Attributes: + table (str): + Required. The table whose rows will be + deleted. + key_set (google.cloud.spanner_v1.types.KeySet): + Required. The primary keys of the rows within + [table][google.spanner.v1.Mutation.Delete.table] to delete. + The primary keys must be specified in the order in which + they appear in the ``PRIMARY KEY()`` clause of the table's + equivalent DDL statement (the DDL statement used to create + the table). Delete is idempotent. The transaction will + succeed even if some or all rows do not exist. + """ + + table: str = proto.Field( + proto.STRING, + number=1, + ) + key_set: keys.KeySet = proto.Field( + proto.MESSAGE, + number=2, + message=keys.KeySet, + ) + + insert: Write = proto.Field( + proto.MESSAGE, + number=1, + oneof='operation', + message=Write, + ) + update: Write = proto.Field( + proto.MESSAGE, + number=2, + oneof='operation', + message=Write, + ) + insert_or_update: Write = proto.Field( + proto.MESSAGE, + number=3, + oneof='operation', + message=Write, + ) + replace: Write = proto.Field( + proto.MESSAGE, + number=4, + oneof='operation', + message=Write, + ) + delete: Delete = proto.Field( + proto.MESSAGE, + number=5, + oneof='operation', + message=Delete, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/query_plan.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/query_plan.py new file mode 100644 index 0000000000..93994f76d1 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/query_plan.py @@ -0,0 +1,219 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.protobuf import struct_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.spanner.v1', + manifest={ + 'PlanNode', + 'QueryPlan', + }, +) + + +class PlanNode(proto.Message): + r"""Node information for nodes appearing in a + [QueryPlan.plan_nodes][google.spanner.v1.QueryPlan.plan_nodes]. + + Attributes: + index (int): + The ``PlanNode``'s index in [node + list][google.spanner.v1.QueryPlan.plan_nodes]. + kind (google.cloud.spanner_v1.types.PlanNode.Kind): + Used to determine the type of node. May be needed for + visualizing different kinds of nodes differently. For + example, If the node is a + [SCALAR][google.spanner.v1.PlanNode.Kind.SCALAR] node, it + will have a condensed representation which can be used to + directly embed a description of the node in its parent. + display_name (str): + The display name for the node. + child_links (MutableSequence[google.cloud.spanner_v1.types.PlanNode.ChildLink]): + List of child node ``index``\ es and their relationship to + this parent. + short_representation (google.cloud.spanner_v1.types.PlanNode.ShortRepresentation): + Condensed representation for + [SCALAR][google.spanner.v1.PlanNode.Kind.SCALAR] nodes. + metadata (google.protobuf.struct_pb2.Struct): + Attributes relevant to the node contained in a group of + key-value pairs. For example, a Parameter Reference node + could have the following information in its metadata: + + :: + + { + "parameter_reference": "param1", + "parameter_type": "array" + } + execution_stats (google.protobuf.struct_pb2.Struct): + The execution statistics associated with the + node, contained in a group of key-value pairs. + Only present if the plan was returned as a + result of a profile query. For example, number + of executions, number of rows/time per execution + etc. + """ + class Kind(proto.Enum): + r"""The kind of [PlanNode][google.spanner.v1.PlanNode]. Distinguishes + between the two different kinds of nodes that can appear in a query + plan. + + Values: + KIND_UNSPECIFIED (0): + Not specified. + RELATIONAL (1): + Denotes a Relational operator node in the expression tree. + Relational operators represent iterative processing of rows + during query execution. For example, a ``TableScan`` + operation that reads rows from a table. + SCALAR (2): + Denotes a Scalar node in the expression tree. + Scalar nodes represent non-iterable entities in + the query plan. For example, constants or + arithmetic operators appearing inside predicate + expressions or references to column names. + """ + KIND_UNSPECIFIED = 0 + RELATIONAL = 1 + SCALAR = 2 + + class ChildLink(proto.Message): + r"""Metadata associated with a parent-child relationship appearing in a + [PlanNode][google.spanner.v1.PlanNode]. + + Attributes: + child_index (int): + The node to which the link points. + type_ (str): + The type of the link. For example, in Hash + Joins this could be used to distinguish between + the build child and the probe child, or in the + case of the child being an output variable, to + represent the tag associated with the output + variable. + variable (str): + Only present if the child node is + [SCALAR][google.spanner.v1.PlanNode.Kind.SCALAR] and + corresponds to an output variable of the parent node. The + field carries the name of the output variable. For example, + a ``TableScan`` operator that reads rows from a table will + have child links to the ``SCALAR`` nodes representing the + output variables created for each column that is read by the + operator. The corresponding ``variable`` fields will be set + to the variable names assigned to the columns. + """ + + child_index: int = proto.Field( + proto.INT32, + number=1, + ) + type_: str = proto.Field( + proto.STRING, + number=2, + ) + variable: str = proto.Field( + proto.STRING, + number=3, + ) + + class ShortRepresentation(proto.Message): + r"""Condensed representation of a node and its subtree. Only present for + ``SCALAR`` [PlanNode(s)][google.spanner.v1.PlanNode]. + + Attributes: + description (str): + A string representation of the expression + subtree rooted at this node. + subqueries (MutableMapping[str, int]): + A mapping of (subquery variable name) -> (subquery node id) + for cases where the ``description`` string of this node + references a ``SCALAR`` subquery contained in the expression + subtree rooted at this node. The referenced ``SCALAR`` + subquery may not necessarily be a direct child of this node. + """ + + description: str = proto.Field( + proto.STRING, + number=1, + ) + subqueries: MutableMapping[str, int] = proto.MapField( + proto.STRING, + proto.INT32, + number=2, + ) + + index: int = proto.Field( + proto.INT32, + number=1, + ) + kind: Kind = proto.Field( + proto.ENUM, + number=2, + enum=Kind, + ) + display_name: str = proto.Field( + proto.STRING, + number=3, + ) + child_links: MutableSequence[ChildLink] = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=ChildLink, + ) + short_representation: ShortRepresentation = proto.Field( + proto.MESSAGE, + number=5, + message=ShortRepresentation, + ) + metadata: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=6, + message=struct_pb2.Struct, + ) + execution_stats: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=7, + message=struct_pb2.Struct, + ) + + +class QueryPlan(proto.Message): + r"""Contains an ordered list of nodes appearing in the query + plan. + + Attributes: + plan_nodes (MutableSequence[google.cloud.spanner_v1.types.PlanNode]): + The nodes in the query plan. Plan nodes are returned in + pre-order starting with the plan root. Each + [PlanNode][google.spanner.v1.PlanNode]'s ``id`` corresponds + to its index in ``plan_nodes``. + """ + + plan_nodes: MutableSequence['PlanNode'] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='PlanNode', + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/result_set.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/result_set.py new file mode 100644 index 0000000000..cf085ee9a9 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/result_set.py @@ -0,0 +1,341 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.cloud.spanner_v1.types import query_plan as gs_query_plan +from google.cloud.spanner_v1.types import transaction as gs_transaction +from google.cloud.spanner_v1.types import type as gs_type +from google.protobuf import struct_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.spanner.v1', + manifest={ + 'ResultSet', + 'PartialResultSet', + 'ResultSetMetadata', + 'ResultSetStats', + }, +) + + +class ResultSet(proto.Message): + r"""Results from [Read][google.spanner.v1.Spanner.Read] or + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. + + Attributes: + metadata (google.cloud.spanner_v1.types.ResultSetMetadata): + Metadata about the result set, such as row + type information. + rows (MutableSequence[google.protobuf.struct_pb2.ListValue]): + Each element in ``rows`` is a row whose format is defined by + [metadata.row_type][google.spanner.v1.ResultSetMetadata.row_type]. + The ith element in each row matches the ith field in + [metadata.row_type][google.spanner.v1.ResultSetMetadata.row_type]. + Elements are encoded based on type as described + [here][google.spanner.v1.TypeCode]. + stats (google.cloud.spanner_v1.types.ResultSetStats): + Query plan and execution statistics for the SQL statement + that produced this result set. These can be requested by + setting + [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode]. + DML statements always produce stats containing the number of + rows modified, unless executed using the + [ExecuteSqlRequest.QueryMode.PLAN][google.spanner.v1.ExecuteSqlRequest.QueryMode.PLAN] + [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode]. + Other fields may or may not be populated, based on the + [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode]. + """ + + metadata: 'ResultSetMetadata' = proto.Field( + proto.MESSAGE, + number=1, + message='ResultSetMetadata', + ) + rows: MutableSequence[struct_pb2.ListValue] = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=struct_pb2.ListValue, + ) + stats: 'ResultSetStats' = proto.Field( + proto.MESSAGE, + number=3, + message='ResultSetStats', + ) + + +class PartialResultSet(proto.Message): + r"""Partial results from a streaming read or SQL query. Streaming + reads and SQL queries better tolerate large result sets, large + rows, and large values, but are a little trickier to consume. + + Attributes: + metadata (google.cloud.spanner_v1.types.ResultSetMetadata): + Metadata about the result set, such as row + type information. Only present in the first + response. + values (MutableSequence[google.protobuf.struct_pb2.Value]): + A streamed result set consists of a stream of values, which + might be split into many ``PartialResultSet`` messages to + accommodate large rows and/or large values. Every N complete + values defines a row, where N is equal to the number of + entries in + [metadata.row_type.fields][google.spanner.v1.StructType.fields]. + + Most values are encoded based on type as described + [here][google.spanner.v1.TypeCode]. + + It is possible that the last value in values is "chunked", + meaning that the rest of the value is sent in subsequent + ``PartialResultSet``\ (s). This is denoted by the + [chunked_value][google.spanner.v1.PartialResultSet.chunked_value] + field. Two or more chunked values can be merged to form a + complete value as follows: + + - ``bool/number/null``: cannot be chunked + - ``string``: concatenate the strings + - ``list``: concatenate the lists. If the last element in a + list is a ``string``, ``list``, or ``object``, merge it + with the first element in the next list by applying these + rules recursively. + - ``object``: concatenate the (field name, field value) + pairs. If a field name is duplicated, then apply these + rules recursively to merge the field values. + + Some examples of merging: + + :: + + # Strings are concatenated. + "foo", "bar" => "foobar" + + # Lists of non-strings are concatenated. + [2, 3], [4] => [2, 3, 4] + + # Lists are concatenated, but the last and first elements are merged + # because they are strings. + ["a", "b"], ["c", "d"] => ["a", "bc", "d"] + + # Lists are concatenated, but the last and first elements are merged + # because they are lists. Recursively, the last and first elements + # of the inner lists are merged because they are strings. + ["a", ["b", "c"]], [["d"], "e"] => ["a", ["b", "cd"], "e"] + + # Non-overlapping object fields are combined. + {"a": "1"}, {"b": "2"} => {"a": "1", "b": 2"} + + # Overlapping object fields are merged. + {"a": "1"}, {"a": "2"} => {"a": "12"} + + # Examples of merging objects containing lists of strings. + {"a": ["1"]}, {"a": ["2"]} => {"a": ["12"]} + + For a more complete example, suppose a streaming SQL query + is yielding a result set whose rows contain a single string + field. The following ``PartialResultSet``\ s might be + yielded: + + :: + + { + "metadata": { ... } + "values": ["Hello", "W"] + "chunked_value": true + "resume_token": "Af65..." + } + { + "values": ["orl"] + "chunked_value": true + "resume_token": "Bqp2..." + } + { + "values": ["d"] + "resume_token": "Zx1B..." + } + + This sequence of ``PartialResultSet``\ s encodes two rows, + one containing the field value ``"Hello"``, and a second + containing the field value ``"World" = "W" + "orl" + "d"``. + chunked_value (bool): + If true, then the final value in + [values][google.spanner.v1.PartialResultSet.values] is + chunked, and must be combined with more values from + subsequent ``PartialResultSet``\ s to obtain a complete + field value. + resume_token (bytes): + Streaming calls might be interrupted for a variety of + reasons, such as TCP connection loss. If this occurs, the + stream of results can be resumed by re-sending the original + request and including ``resume_token``. Note that executing + any other transaction in the same session invalidates the + token. + stats (google.cloud.spanner_v1.types.ResultSetStats): + Query plan and execution statistics for the statement that + produced this streaming result set. These can be requested + by setting + [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode] + and are sent only once with the last response in the stream. + This field will also be present in the last response for DML + statements. + """ + + metadata: 'ResultSetMetadata' = proto.Field( + proto.MESSAGE, + number=1, + message='ResultSetMetadata', + ) + values: MutableSequence[struct_pb2.Value] = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=struct_pb2.Value, + ) + chunked_value: bool = proto.Field( + proto.BOOL, + number=3, + ) + resume_token: bytes = proto.Field( + proto.BYTES, + number=4, + ) + stats: 'ResultSetStats' = proto.Field( + proto.MESSAGE, + number=5, + message='ResultSetStats', + ) + + +class ResultSetMetadata(proto.Message): + r"""Metadata about a [ResultSet][google.spanner.v1.ResultSet] or + [PartialResultSet][google.spanner.v1.PartialResultSet]. + + Attributes: + row_type (google.cloud.spanner_v1.types.StructType): + Indicates the field names and types for the rows in the + result set. For example, a SQL query like + ``"SELECT UserId, UserName FROM Users"`` could return a + ``row_type`` value like: + + :: + + "fields": [ + { "name": "UserId", "type": { "code": "INT64" } }, + { "name": "UserName", "type": { "code": "STRING" } }, + ] + transaction (google.cloud.spanner_v1.types.Transaction): + If the read or SQL query began a transaction + as a side-effect, the information about the new + transaction is yielded here. + undeclared_parameters (google.cloud.spanner_v1.types.StructType): + A SQL query can be parameterized. In PLAN mode, these + parameters can be undeclared. This indicates the field names + and types for those undeclared parameters in the SQL query. + For example, a SQL query like + ``"SELECT * FROM Users where UserId = @userId and UserName = @userName "`` + could return a ``undeclared_parameters`` value like: + + :: + + "fields": [ + { "name": "UserId", "type": { "code": "INT64" } }, + { "name": "UserName", "type": { "code": "STRING" } }, + ] + """ + + row_type: gs_type.StructType = proto.Field( + proto.MESSAGE, + number=1, + message=gs_type.StructType, + ) + transaction: gs_transaction.Transaction = proto.Field( + proto.MESSAGE, + number=2, + message=gs_transaction.Transaction, + ) + undeclared_parameters: gs_type.StructType = proto.Field( + proto.MESSAGE, + number=3, + message=gs_type.StructType, + ) + + +class ResultSetStats(proto.Message): + r"""Additional statistics about a + [ResultSet][google.spanner.v1.ResultSet] or + [PartialResultSet][google.spanner.v1.PartialResultSet]. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + query_plan (google.cloud.spanner_v1.types.QueryPlan): + [QueryPlan][google.spanner.v1.QueryPlan] for the query + associated with this result. + query_stats (google.protobuf.struct_pb2.Struct): + Aggregated statistics from the execution of the query. Only + present when the query is profiled. For example, a query + could return the statistics as follows: + + :: + + { + "rows_returned": "3", + "elapsed_time": "1.22 secs", + "cpu_time": "1.19 secs" + } + row_count_exact (int): + Standard DML returns an exact count of rows + that were modified. + + This field is a member of `oneof`_ ``row_count``. + row_count_lower_bound (int): + Partitioned DML does not offer exactly-once + semantics, so it returns a lower bound of the + rows modified. + + This field is a member of `oneof`_ ``row_count``. + """ + + query_plan: gs_query_plan.QueryPlan = proto.Field( + proto.MESSAGE, + number=1, + message=gs_query_plan.QueryPlan, + ) + query_stats: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=2, + message=struct_pb2.Struct, + ) + row_count_exact: int = proto.Field( + proto.INT64, + number=3, + oneof='row_count', + ) + row_count_lower_bound: int = proto.Field( + proto.INT64, + number=4, + oneof='row_count', + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/spanner.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/spanner.py new file mode 100644 index 0000000000..995fb6e126 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/spanner.py @@ -0,0 +1,1327 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.cloud.spanner_v1.types import keys +from google.cloud.spanner_v1.types import mutation +from google.cloud.spanner_v1.types import result_set +from google.cloud.spanner_v1.types import transaction as gs_transaction +from google.cloud.spanner_v1.types import type as gs_type +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.spanner.v1', + manifest={ + 'CreateSessionRequest', + 'BatchCreateSessionsRequest', + 'BatchCreateSessionsResponse', + 'Session', + 'GetSessionRequest', + 'ListSessionsRequest', + 'ListSessionsResponse', + 'DeleteSessionRequest', + 'RequestOptions', + 'ExecuteSqlRequest', + 'ExecuteBatchDmlRequest', + 'ExecuteBatchDmlResponse', + 'PartitionOptions', + 'PartitionQueryRequest', + 'PartitionReadRequest', + 'Partition', + 'PartitionResponse', + 'ReadRequest', + 'BeginTransactionRequest', + 'CommitRequest', + 'RollbackRequest', + }, +) + + +class CreateSessionRequest(proto.Message): + r"""The request for + [CreateSession][google.spanner.v1.Spanner.CreateSession]. + + Attributes: + database (str): + Required. The database in which the new + session is created. + session (google.cloud.spanner_v1.types.Session): + Required. The session to create. + """ + + database: str = proto.Field( + proto.STRING, + number=1, + ) + session: 'Session' = proto.Field( + proto.MESSAGE, + number=2, + message='Session', + ) + + +class BatchCreateSessionsRequest(proto.Message): + r"""The request for + [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. + + Attributes: + database (str): + Required. The database in which the new + sessions are created. + session_template (google.cloud.spanner_v1.types.Session): + Parameters to be applied to each created + session. + session_count (int): + Required. The number of sessions to be created in this batch + call. The API may return fewer than the requested number of + sessions. If a specific number of sessions are desired, the + client can make additional calls to BatchCreateSessions + (adjusting + [session_count][google.spanner.v1.BatchCreateSessionsRequest.session_count] + as necessary). + """ + + database: str = proto.Field( + proto.STRING, + number=1, + ) + session_template: 'Session' = proto.Field( + proto.MESSAGE, + number=2, + message='Session', + ) + session_count: int = proto.Field( + proto.INT32, + number=3, + ) + + +class BatchCreateSessionsResponse(proto.Message): + r"""The response for + [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. + + Attributes: + session (MutableSequence[google.cloud.spanner_v1.types.Session]): + The freshly created sessions. + """ + + session: MutableSequence['Session'] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Session', + ) + + +class Session(proto.Message): + r"""A session in the Cloud Spanner API. + + Attributes: + name (str): + Output only. The name of the session. This is + always system-assigned. + labels (MutableMapping[str, str]): + The labels for the session. + + - Label keys must be between 1 and 63 characters long and + must conform to the following regular expression: + ``[a-z]([-a-z0-9]*[a-z0-9])?``. + - Label values must be between 0 and 63 characters long and + must conform to the regular expression + ``([a-z]([-a-z0-9]*[a-z0-9])?)?``. + - No more than 64 labels can be associated with a given + session. + + See https://goo.gl/xmQnxf for more information on and + examples of labels. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The timestamp when the session + is created. + approximate_last_use_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The approximate timestamp when + the session is last used. It is typically + earlier than the actual last use time. + creator_role (str): + The database role which created this session. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + labels: MutableMapping[str, str] = proto.MapField( + proto.STRING, + proto.STRING, + number=2, + ) + create_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + approximate_last_use_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + creator_role: str = proto.Field( + proto.STRING, + number=5, + ) + + +class GetSessionRequest(proto.Message): + r"""The request for [GetSession][google.spanner.v1.Spanner.GetSession]. + + Attributes: + name (str): + Required. The name of the session to + retrieve. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class ListSessionsRequest(proto.Message): + r"""The request for + [ListSessions][google.spanner.v1.Spanner.ListSessions]. + + Attributes: + database (str): + Required. The database in which to list + sessions. + page_size (int): + Number of sessions to be returned in the + response. If 0 or less, defaults to the server's + maximum allowed page size. + page_token (str): + If non-empty, ``page_token`` should contain a + [next_page_token][google.spanner.v1.ListSessionsResponse.next_page_token] + from a previous + [ListSessionsResponse][google.spanner.v1.ListSessionsResponse]. + filter (str): + An expression for filtering the results of the request. + Filter rules are case insensitive. The fields eligible for + filtering are: + + - ``labels.key`` where key is the name of a label + + Some examples of using filters are: + + - ``labels.env:*`` --> The session has the label "env". + - ``labels.env:dev`` --> The session has the label "env" + and the value of the label contains the string "dev". + """ + + database: str = proto.Field( + proto.STRING, + number=1, + ) + page_size: int = proto.Field( + proto.INT32, + number=2, + ) + page_token: str = proto.Field( + proto.STRING, + number=3, + ) + filter: str = proto.Field( + proto.STRING, + number=4, + ) + + +class ListSessionsResponse(proto.Message): + r"""The response for + [ListSessions][google.spanner.v1.Spanner.ListSessions]. + + Attributes: + sessions (MutableSequence[google.cloud.spanner_v1.types.Session]): + The list of requested sessions. + next_page_token (str): + ``next_page_token`` can be sent in a subsequent + [ListSessions][google.spanner.v1.Spanner.ListSessions] call + to fetch more of the matching sessions. + """ + + @property + def raw_page(self): + return self + + sessions: MutableSequence['Session'] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Session', + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + +class DeleteSessionRequest(proto.Message): + r"""The request for + [DeleteSession][google.spanner.v1.Spanner.DeleteSession]. + + Attributes: + name (str): + Required. The name of the session to delete. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class RequestOptions(proto.Message): + r"""Common request options for various APIs. + + Attributes: + priority (google.cloud.spanner_v1.types.RequestOptions.Priority): + Priority for the request. + request_tag (str): + A per-request tag which can be applied to queries or reads, + used for statistics collection. Both request_tag and + transaction_tag can be specified for a read or query that + belongs to a transaction. This field is ignored for requests + where it's not applicable (e.g. CommitRequest). Legal + characters for ``request_tag`` values are all printable + characters (ASCII 32 - 126) and the length of a request_tag + is limited to 50 characters. Values that exceed this limit + are truncated. Any leading underscore (_) characters will be + removed from the string. + transaction_tag (str): + A tag used for statistics collection about this transaction. + Both request_tag and transaction_tag can be specified for a + read or query that belongs to a transaction. The value of + transaction_tag should be the same for all requests + belonging to the same transaction. If this request doesn't + belong to any transaction, transaction_tag will be ignored. + Legal characters for ``transaction_tag`` values are all + printable characters (ASCII 32 - 126) and the length of a + transaction_tag is limited to 50 characters. Values that + exceed this limit are truncated. Any leading underscore (_) + characters will be removed from the string. + """ + class Priority(proto.Enum): + r"""The relative priority for requests. Note that priority is not + applicable for + [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction]. + + The priority acts as a hint to the Cloud Spanner scheduler and does + not guarantee priority or order of execution. For example: + + - Some parts of a write operation always execute at + ``PRIORITY_HIGH``, regardless of the specified priority. This may + cause you to see an increase in high priority workload even when + executing a low priority request. This can also potentially cause + a priority inversion where a lower priority request will be + fulfilled ahead of a higher priority request. + - If a transaction contains multiple operations with different + priorities, Cloud Spanner does not guarantee to process the + higher priority operations first. There may be other constraints + to satisfy, such as order of operations. + + Values: + PRIORITY_UNSPECIFIED (0): + ``PRIORITY_UNSPECIFIED`` is equivalent to ``PRIORITY_HIGH``. + PRIORITY_LOW (1): + This specifies that the request is low + priority. + PRIORITY_MEDIUM (2): + This specifies that the request is medium + priority. + PRIORITY_HIGH (3): + This specifies that the request is high + priority. + """ + PRIORITY_UNSPECIFIED = 0 + PRIORITY_LOW = 1 + PRIORITY_MEDIUM = 2 + PRIORITY_HIGH = 3 + + priority: Priority = proto.Field( + proto.ENUM, + number=1, + enum=Priority, + ) + request_tag: str = proto.Field( + proto.STRING, + number=2, + ) + transaction_tag: str = proto.Field( + proto.STRING, + number=3, + ) + + +class ExecuteSqlRequest(proto.Message): + r"""The request for [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] + and + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. + + Attributes: + session (str): + Required. The session in which the SQL query + should be performed. + transaction (google.cloud.spanner_v1.types.TransactionSelector): + The transaction to use. + For queries, if none is provided, the default is + a temporary read-only transaction with strong + concurrency. + + Standard DML statements require a read-write + transaction. To protect against replays, + single-use transactions are not supported. The + caller must either supply an existing + transaction ID or begin a new transaction. + Partitioned DML requires an existing Partitioned + DML transaction ID. + sql (str): + Required. The SQL string. + params (google.protobuf.struct_pb2.Struct): + Parameter names and values that bind to placeholders in the + SQL string. + + A parameter placeholder consists of the ``@`` character + followed by the parameter name (for example, + ``@firstName``). Parameter names must conform to the naming + requirements of identifiers as specified at + https://cloud.google.com/spanner/docs/lexical#identifiers. + + Parameters can appear anywhere that a literal value is + expected. The same parameter name can be used more than + once, for example: + + ``"WHERE id > @msg_id AND id < @msg_id + 100"`` + + It is an error to execute a SQL statement with unbound + parameters. + param_types (MutableMapping[str, google.cloud.spanner_v1.types.Type]): + It is not always possible for Cloud Spanner to infer the + right SQL type from a JSON value. For example, values of + type ``BYTES`` and values of type ``STRING`` both appear in + [params][google.spanner.v1.ExecuteSqlRequest.params] as JSON + strings. + + In these cases, ``param_types`` can be used to specify the + exact SQL type for some or all of the SQL statement + parameters. See the definition of + [Type][google.spanner.v1.Type] for more information about + SQL types. + resume_token (bytes): + If this request is resuming a previously interrupted SQL + statement execution, ``resume_token`` should be copied from + the last + [PartialResultSet][google.spanner.v1.PartialResultSet] + yielded before the interruption. Doing this enables the new + SQL statement execution to resume where the last one left + off. The rest of the request parameters must exactly match + the request that yielded this token. + query_mode (google.cloud.spanner_v1.types.ExecuteSqlRequest.QueryMode): + Used to control the amount of debugging information returned + in [ResultSetStats][google.spanner.v1.ResultSetStats]. If + [partition_token][google.spanner.v1.ExecuteSqlRequest.partition_token] + is set, + [query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode] + can only be set to + [QueryMode.NORMAL][google.spanner.v1.ExecuteSqlRequest.QueryMode.NORMAL]. + partition_token (bytes): + If present, results will be restricted to the specified + partition previously created using PartitionQuery(). There + must be an exact match for the values of fields common to + this message and the PartitionQueryRequest message used to + create this partition_token. + seqno (int): + A per-transaction sequence number used to + identify this request. This field makes each + request idempotent such that if the request is + received multiple times, at most one will + succeed. + + The sequence number must be monotonically + increasing within the transaction. If a request + arrives for the first time with an out-of-order + sequence number, the transaction may be aborted. + Replays of previously handled requests will + yield the same response as the first execution. + Required for DML statements. Ignored for + queries. + query_options (google.cloud.spanner_v1.types.ExecuteSqlRequest.QueryOptions): + Query optimizer configuration to use for the + given query. + request_options (google.cloud.spanner_v1.types.RequestOptions): + Common options for this request. + data_boost_enabled (bool): + If this is for a partitioned query and this field is set to + ``true``, the request will be executed via Spanner + independent compute resources. + + If the field is set to ``true`` but the request does not set + ``partition_token``, the API will return an + ``INVALID_ARGUMENT`` error. + """ + class QueryMode(proto.Enum): + r"""Mode in which the statement must be processed. + + Values: + NORMAL (0): + The default mode. Only the statement results + are returned. + PLAN (1): + This mode returns only the query plan, + without any results or execution statistics + information. + PROFILE (2): + This mode returns both the query plan and the + execution statistics along with the results. + """ + NORMAL = 0 + PLAN = 1 + PROFILE = 2 + + class QueryOptions(proto.Message): + r"""Query optimizer configuration. + + Attributes: + optimizer_version (str): + An option to control the selection of optimizer version. + + This parameter allows individual queries to pick different + query optimizer versions. + + Specifying ``latest`` as a value instructs Cloud Spanner to + use the latest supported query optimizer version. If not + specified, Cloud Spanner uses the optimizer version set at + the database level options. Any other positive integer (from + the list of supported optimizer versions) overrides the + default optimizer version for query execution. + + The list of supported optimizer versions can be queried from + SPANNER_SYS.SUPPORTED_OPTIMIZER_VERSIONS. + + Executing a SQL statement with an invalid optimizer version + fails with an ``INVALID_ARGUMENT`` error. + + See + https://cloud.google.com/spanner/docs/query-optimizer/manage-query-optimizer + for more information on managing the query optimizer. + + The ``optimizer_version`` statement hint has precedence over + this setting. + optimizer_statistics_package (str): + An option to control the selection of optimizer statistics + package. + + This parameter allows individual queries to use a different + query optimizer statistics package. + + Specifying ``latest`` as a value instructs Cloud Spanner to + use the latest generated statistics package. If not + specified, Cloud Spanner uses the statistics package set at + the database level options, or the latest package if the + database option is not set. + + The statistics package requested by the query has to be + exempt from garbage collection. This can be achieved with + the following DDL statement: + + :: + + ALTER STATISTICS SET OPTIONS (allow_gc=false) + + The list of available statistics packages can be queried + from ``INFORMATION_SCHEMA.SPANNER_STATISTICS``. + + Executing a SQL statement with an invalid optimizer + statistics package or with a statistics package that allows + garbage collection fails with an ``INVALID_ARGUMENT`` error. + """ + + optimizer_version: str = proto.Field( + proto.STRING, + number=1, + ) + optimizer_statistics_package: str = proto.Field( + proto.STRING, + number=2, + ) + + session: str = proto.Field( + proto.STRING, + number=1, + ) + transaction: gs_transaction.TransactionSelector = proto.Field( + proto.MESSAGE, + number=2, + message=gs_transaction.TransactionSelector, + ) + sql: str = proto.Field( + proto.STRING, + number=3, + ) + params: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=4, + message=struct_pb2.Struct, + ) + param_types: MutableMapping[str, gs_type.Type] = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=5, + message=gs_type.Type, + ) + resume_token: bytes = proto.Field( + proto.BYTES, + number=6, + ) + query_mode: QueryMode = proto.Field( + proto.ENUM, + number=7, + enum=QueryMode, + ) + partition_token: bytes = proto.Field( + proto.BYTES, + number=8, + ) + seqno: int = proto.Field( + proto.INT64, + number=9, + ) + query_options: QueryOptions = proto.Field( + proto.MESSAGE, + number=10, + message=QueryOptions, + ) + request_options: 'RequestOptions' = proto.Field( + proto.MESSAGE, + number=11, + message='RequestOptions', + ) + data_boost_enabled: bool = proto.Field( + proto.BOOL, + number=16, + ) + + +class ExecuteBatchDmlRequest(proto.Message): + r"""The request for + [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. + + Attributes: + session (str): + Required. The session in which the DML + statements should be performed. + transaction (google.cloud.spanner_v1.types.TransactionSelector): + Required. The transaction to use. Must be a + read-write transaction. + To protect against replays, single-use + transactions are not supported. The caller must + either supply an existing transaction ID or + begin a new transaction. + statements (MutableSequence[google.cloud.spanner_v1.types.ExecuteBatchDmlRequest.Statement]): + Required. The list of statements to execute in this batch. + Statements are executed serially, such that the effects of + statement ``i`` are visible to statement ``i+1``. Each + statement must be a DML statement. Execution stops at the + first failed statement; the remaining statements are not + executed. + + Callers must provide at least one statement. + seqno (int): + Required. A per-transaction sequence number + used to identify this request. This field makes + each request idempotent such that if the request + is received multiple times, at most one will + succeed. + + The sequence number must be monotonically + increasing within the transaction. If a request + arrives for the first time with an out-of-order + sequence number, the transaction may be aborted. + Replays of previously handled requests will + yield the same response as the first execution. + request_options (google.cloud.spanner_v1.types.RequestOptions): + Common options for this request. + """ + + class Statement(proto.Message): + r"""A single DML statement. + + Attributes: + sql (str): + Required. The DML string. + params (google.protobuf.struct_pb2.Struct): + Parameter names and values that bind to placeholders in the + DML string. + + A parameter placeholder consists of the ``@`` character + followed by the parameter name (for example, + ``@firstName``). Parameter names can contain letters, + numbers, and underscores. + + Parameters can appear anywhere that a literal value is + expected. The same parameter name can be used more than + once, for example: + + ``"WHERE id > @msg_id AND id < @msg_id + 100"`` + + It is an error to execute a SQL statement with unbound + parameters. + param_types (MutableMapping[str, google.cloud.spanner_v1.types.Type]): + It is not always possible for Cloud Spanner to infer the + right SQL type from a JSON value. For example, values of + type ``BYTES`` and values of type ``STRING`` both appear in + [params][google.spanner.v1.ExecuteBatchDmlRequest.Statement.params] + as JSON strings. + + In these cases, ``param_types`` can be used to specify the + exact SQL type for some or all of the SQL statement + parameters. See the definition of + [Type][google.spanner.v1.Type] for more information about + SQL types. + """ + + sql: str = proto.Field( + proto.STRING, + number=1, + ) + params: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=2, + message=struct_pb2.Struct, + ) + param_types: MutableMapping[str, gs_type.Type] = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=3, + message=gs_type.Type, + ) + + session: str = proto.Field( + proto.STRING, + number=1, + ) + transaction: gs_transaction.TransactionSelector = proto.Field( + proto.MESSAGE, + number=2, + message=gs_transaction.TransactionSelector, + ) + statements: MutableSequence[Statement] = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=Statement, + ) + seqno: int = proto.Field( + proto.INT64, + number=4, + ) + request_options: 'RequestOptions' = proto.Field( + proto.MESSAGE, + number=5, + message='RequestOptions', + ) + + +class ExecuteBatchDmlResponse(proto.Message): + r"""The response for + [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. + Contains a list of [ResultSet][google.spanner.v1.ResultSet] + messages, one for each DML statement that has successfully executed, + in the same order as the statements in the request. If a statement + fails, the status in the response body identifies the cause of the + failure. + + To check for DML statements that failed, use the following approach: + + 1. Check the status in the response message. The + [google.rpc.Code][google.rpc.Code] enum value ``OK`` indicates + that all statements were executed successfully. + 2. If the status was not ``OK``, check the number of result sets in + the response. If the response contains ``N`` + [ResultSet][google.spanner.v1.ResultSet] messages, then statement + ``N+1`` in the request failed. + + Example 1: + + - Request: 5 DML statements, all executed successfully. + - Response: 5 [ResultSet][google.spanner.v1.ResultSet] messages, + with the status ``OK``. + + Example 2: + + - Request: 5 DML statements. The third statement has a syntax + error. + - Response: 2 [ResultSet][google.spanner.v1.ResultSet] messages, + and a syntax error (``INVALID_ARGUMENT``) status. The number of + [ResultSet][google.spanner.v1.ResultSet] messages indicates that + the third statement failed, and the fourth and fifth statements + were not executed. + + Attributes: + result_sets (MutableSequence[google.cloud.spanner_v1.types.ResultSet]): + One [ResultSet][google.spanner.v1.ResultSet] for each + statement in the request that ran successfully, in the same + order as the statements in the request. Each + [ResultSet][google.spanner.v1.ResultSet] does not contain + any rows. The + [ResultSetStats][google.spanner.v1.ResultSetStats] in each + [ResultSet][google.spanner.v1.ResultSet] contain the number + of rows modified by the statement. + + Only the first [ResultSet][google.spanner.v1.ResultSet] in + the response contains valid + [ResultSetMetadata][google.spanner.v1.ResultSetMetadata]. + status (google.rpc.status_pb2.Status): + If all DML statements are executed successfully, the status + is ``OK``. Otherwise, the error status of the first failed + statement. + """ + + result_sets: MutableSequence[result_set.ResultSet] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=result_set.ResultSet, + ) + status: status_pb2.Status = proto.Field( + proto.MESSAGE, + number=2, + message=status_pb2.Status, + ) + + +class PartitionOptions(proto.Message): + r"""Options for a PartitionQueryRequest and + PartitionReadRequest. + + Attributes: + partition_size_bytes (int): + **Note:** This hint is currently ignored by PartitionQuery + and PartitionRead requests. + + The desired data size for each partition generated. The + default for this option is currently 1 GiB. This is only a + hint. The actual size of each partition may be smaller or + larger than this size request. + max_partitions (int): + **Note:** This hint is currently ignored by PartitionQuery + and PartitionRead requests. + + The desired maximum number of partitions to return. For + example, this may be set to the number of workers available. + The default for this option is currently 10,000. The maximum + value is currently 200,000. This is only a hint. The actual + number of partitions returned may be smaller or larger than + this maximum count request. + """ + + partition_size_bytes: int = proto.Field( + proto.INT64, + number=1, + ) + max_partitions: int = proto.Field( + proto.INT64, + number=2, + ) + + +class PartitionQueryRequest(proto.Message): + r"""The request for + [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] + + Attributes: + session (str): + Required. The session used to create the + partitions. + transaction (google.cloud.spanner_v1.types.TransactionSelector): + Read only snapshot transactions are + supported, read/write and single use + transactions are not. + sql (str): + Required. The query request to generate partitions for. The + request will fail if the query is not root partitionable. + The query plan of a root partitionable query has a single + distributed union operator. A distributed union operator + conceptually divides one or more tables into multiple + splits, remotely evaluates a subquery independently on each + split, and then unions all results. + + This must not contain DML commands, such as INSERT, UPDATE, + or DELETE. Use + [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] + with a PartitionedDml transaction for large, + partition-friendly DML operations. + params (google.protobuf.struct_pb2.Struct): + Parameter names and values that bind to placeholders in the + SQL string. + + A parameter placeholder consists of the ``@`` character + followed by the parameter name (for example, + ``@firstName``). Parameter names can contain letters, + numbers, and underscores. + + Parameters can appear anywhere that a literal value is + expected. The same parameter name can be used more than + once, for example: + + ``"WHERE id > @msg_id AND id < @msg_id + 100"`` + + It is an error to execute a SQL statement with unbound + parameters. + param_types (MutableMapping[str, google.cloud.spanner_v1.types.Type]): + It is not always possible for Cloud Spanner to infer the + right SQL type from a JSON value. For example, values of + type ``BYTES`` and values of type ``STRING`` both appear in + [params][google.spanner.v1.PartitionQueryRequest.params] as + JSON strings. + + In these cases, ``param_types`` can be used to specify the + exact SQL type for some or all of the SQL query parameters. + See the definition of [Type][google.spanner.v1.Type] for + more information about SQL types. + partition_options (google.cloud.spanner_v1.types.PartitionOptions): + Additional options that affect how many + partitions are created. + """ + + session: str = proto.Field( + proto.STRING, + number=1, + ) + transaction: gs_transaction.TransactionSelector = proto.Field( + proto.MESSAGE, + number=2, + message=gs_transaction.TransactionSelector, + ) + sql: str = proto.Field( + proto.STRING, + number=3, + ) + params: struct_pb2.Struct = proto.Field( + proto.MESSAGE, + number=4, + message=struct_pb2.Struct, + ) + param_types: MutableMapping[str, gs_type.Type] = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=5, + message=gs_type.Type, + ) + partition_options: 'PartitionOptions' = proto.Field( + proto.MESSAGE, + number=6, + message='PartitionOptions', + ) + + +class PartitionReadRequest(proto.Message): + r"""The request for + [PartitionRead][google.spanner.v1.Spanner.PartitionRead] + + Attributes: + session (str): + Required. The session used to create the + partitions. + transaction (google.cloud.spanner_v1.types.TransactionSelector): + Read only snapshot transactions are + supported, read/write and single use + transactions are not. + table (str): + Required. The name of the table in the + database to be read. + index (str): + If non-empty, the name of an index on + [table][google.spanner.v1.PartitionReadRequest.table]. This + index is used instead of the table primary key when + interpreting + [key_set][google.spanner.v1.PartitionReadRequest.key_set] + and sorting result rows. See + [key_set][google.spanner.v1.PartitionReadRequest.key_set] + for further information. + columns (MutableSequence[str]): + The columns of + [table][google.spanner.v1.PartitionReadRequest.table] to be + returned for each row matching this request. + key_set (google.cloud.spanner_v1.types.KeySet): + Required. ``key_set`` identifies the rows to be yielded. + ``key_set`` names the primary keys of the rows in + [table][google.spanner.v1.PartitionReadRequest.table] to be + yielded, unless + [index][google.spanner.v1.PartitionReadRequest.index] is + present. If + [index][google.spanner.v1.PartitionReadRequest.index] is + present, then + [key_set][google.spanner.v1.PartitionReadRequest.key_set] + instead names index keys in + [index][google.spanner.v1.PartitionReadRequest.index]. + + It is not an error for the ``key_set`` to name rows that do + not exist in the database. Read yields nothing for + nonexistent rows. + partition_options (google.cloud.spanner_v1.types.PartitionOptions): + Additional options that affect how many + partitions are created. + """ + + session: str = proto.Field( + proto.STRING, + number=1, + ) + transaction: gs_transaction.TransactionSelector = proto.Field( + proto.MESSAGE, + number=2, + message=gs_transaction.TransactionSelector, + ) + table: str = proto.Field( + proto.STRING, + number=3, + ) + index: str = proto.Field( + proto.STRING, + number=4, + ) + columns: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=5, + ) + key_set: keys.KeySet = proto.Field( + proto.MESSAGE, + number=6, + message=keys.KeySet, + ) + partition_options: 'PartitionOptions' = proto.Field( + proto.MESSAGE, + number=9, + message='PartitionOptions', + ) + + +class Partition(proto.Message): + r"""Information returned for each partition returned in a + PartitionResponse. + + Attributes: + partition_token (bytes): + This token can be passed to Read, + StreamingRead, ExecuteSql, or + ExecuteStreamingSql requests to restrict the + results to those identified by this partition + token. + """ + + partition_token: bytes = proto.Field( + proto.BYTES, + number=1, + ) + + +class PartitionResponse(proto.Message): + r"""The response for + [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] or + [PartitionRead][google.spanner.v1.Spanner.PartitionRead] + + Attributes: + partitions (MutableSequence[google.cloud.spanner_v1.types.Partition]): + Partitions created by this request. + transaction (google.cloud.spanner_v1.types.Transaction): + Transaction created by this request. + """ + + partitions: MutableSequence['Partition'] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Partition', + ) + transaction: gs_transaction.Transaction = proto.Field( + proto.MESSAGE, + number=2, + message=gs_transaction.Transaction, + ) + + +class ReadRequest(proto.Message): + r"""The request for [Read][google.spanner.v1.Spanner.Read] and + [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. + + Attributes: + session (str): + Required. The session in which the read + should be performed. + transaction (google.cloud.spanner_v1.types.TransactionSelector): + The transaction to use. If none is provided, + the default is a temporary read-only transaction + with strong concurrency. + table (str): + Required. The name of the table in the + database to be read. + index (str): + If non-empty, the name of an index on + [table][google.spanner.v1.ReadRequest.table]. This index is + used instead of the table primary key when interpreting + [key_set][google.spanner.v1.ReadRequest.key_set] and sorting + result rows. See + [key_set][google.spanner.v1.ReadRequest.key_set] for further + information. + columns (MutableSequence[str]): + Required. The columns of + [table][google.spanner.v1.ReadRequest.table] to be returned + for each row matching this request. + key_set (google.cloud.spanner_v1.types.KeySet): + Required. ``key_set`` identifies the rows to be yielded. + ``key_set`` names the primary keys of the rows in + [table][google.spanner.v1.ReadRequest.table] to be yielded, + unless [index][google.spanner.v1.ReadRequest.index] is + present. If [index][google.spanner.v1.ReadRequest.index] is + present, then + [key_set][google.spanner.v1.ReadRequest.key_set] instead + names index keys in + [index][google.spanner.v1.ReadRequest.index]. + + If the + [partition_token][google.spanner.v1.ReadRequest.partition_token] + field is empty, rows are yielded in table primary key order + (if [index][google.spanner.v1.ReadRequest.index] is empty) + or index key order (if + [index][google.spanner.v1.ReadRequest.index] is non-empty). + If the + [partition_token][google.spanner.v1.ReadRequest.partition_token] + field is not empty, rows will be yielded in an unspecified + order. + + It is not an error for the ``key_set`` to name rows that do + not exist in the database. Read yields nothing for + nonexistent rows. + limit (int): + If greater than zero, only the first ``limit`` rows are + yielded. If ``limit`` is zero, the default is no limit. A + limit cannot be specified if ``partition_token`` is set. + resume_token (bytes): + If this request is resuming a previously interrupted read, + ``resume_token`` should be copied from the last + [PartialResultSet][google.spanner.v1.PartialResultSet] + yielded before the interruption. Doing this enables the new + read to resume where the last read left off. The rest of the + request parameters must exactly match the request that + yielded this token. + partition_token (bytes): + If present, results will be restricted to the specified + partition previously created using PartitionRead(). There + must be an exact match for the values of fields common to + this message and the PartitionReadRequest message used to + create this partition_token. + request_options (google.cloud.spanner_v1.types.RequestOptions): + Common options for this request. + data_boost_enabled (bool): + If this is for a partitioned read and this field is set to + ``true``, the request will be executed via Spanner + independent compute resources. + + If the field is set to ``true`` but the request does not set + ``partition_token``, the API will return an + ``INVALID_ARGUMENT`` error. + """ + + session: str = proto.Field( + proto.STRING, + number=1, + ) + transaction: gs_transaction.TransactionSelector = proto.Field( + proto.MESSAGE, + number=2, + message=gs_transaction.TransactionSelector, + ) + table: str = proto.Field( + proto.STRING, + number=3, + ) + index: str = proto.Field( + proto.STRING, + number=4, + ) + columns: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=5, + ) + key_set: keys.KeySet = proto.Field( + proto.MESSAGE, + number=6, + message=keys.KeySet, + ) + limit: int = proto.Field( + proto.INT64, + number=8, + ) + resume_token: bytes = proto.Field( + proto.BYTES, + number=9, + ) + partition_token: bytes = proto.Field( + proto.BYTES, + number=10, + ) + request_options: 'RequestOptions' = proto.Field( + proto.MESSAGE, + number=11, + message='RequestOptions', + ) + data_boost_enabled: bool = proto.Field( + proto.BOOL, + number=15, + ) + + +class BeginTransactionRequest(proto.Message): + r"""The request for + [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction]. + + Attributes: + session (str): + Required. The session in which the + transaction runs. + options (google.cloud.spanner_v1.types.TransactionOptions): + Required. Options for the new transaction. + request_options (google.cloud.spanner_v1.types.RequestOptions): + Common options for this request. Priority is ignored for + this request. Setting the priority in this request_options + struct will not do anything. To set the priority for a + transaction, set it on the reads and writes that are part of + this transaction instead. + """ + + session: str = proto.Field( + proto.STRING, + number=1, + ) + options: gs_transaction.TransactionOptions = proto.Field( + proto.MESSAGE, + number=2, + message=gs_transaction.TransactionOptions, + ) + request_options: 'RequestOptions' = proto.Field( + proto.MESSAGE, + number=3, + message='RequestOptions', + ) + + +class CommitRequest(proto.Message): + r"""The request for [Commit][google.spanner.v1.Spanner.Commit]. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + session (str): + Required. The session in which the + transaction to be committed is running. + transaction_id (bytes): + Commit a previously-started transaction. + + This field is a member of `oneof`_ ``transaction``. + single_use_transaction (google.cloud.spanner_v1.types.TransactionOptions): + Execute mutations in a temporary transaction. Note that + unlike commit of a previously-started transaction, commit + with a temporary transaction is non-idempotent. That is, if + the ``CommitRequest`` is sent to Cloud Spanner more than + once (for instance, due to retries in the application, or in + the transport library), it is possible that the mutations + are executed more than once. If this is undesirable, use + [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction] + and [Commit][google.spanner.v1.Spanner.Commit] instead. + + This field is a member of `oneof`_ ``transaction``. + mutations (MutableSequence[google.cloud.spanner_v1.types.Mutation]): + The mutations to be executed when this + transaction commits. All mutations are applied + atomically, in the order they appear in this + list. + return_commit_stats (bool): + If ``true``, then statistics related to the transaction will + be included in the + [CommitResponse][google.spanner.v1.CommitResponse.commit_stats]. + Default value is ``false``. + request_options (google.cloud.spanner_v1.types.RequestOptions): + Common options for this request. + """ + + session: str = proto.Field( + proto.STRING, + number=1, + ) + transaction_id: bytes = proto.Field( + proto.BYTES, + number=2, + oneof='transaction', + ) + single_use_transaction: gs_transaction.TransactionOptions = proto.Field( + proto.MESSAGE, + number=3, + oneof='transaction', + message=gs_transaction.TransactionOptions, + ) + mutations: MutableSequence[mutation.Mutation] = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=mutation.Mutation, + ) + return_commit_stats: bool = proto.Field( + proto.BOOL, + number=5, + ) + request_options: 'RequestOptions' = proto.Field( + proto.MESSAGE, + number=6, + message='RequestOptions', + ) + + +class RollbackRequest(proto.Message): + r"""The request for [Rollback][google.spanner.v1.Spanner.Rollback]. + + Attributes: + session (str): + Required. The session in which the + transaction to roll back is running. + transaction_id (bytes): + Required. The transaction to roll back. + """ + + session: str = proto.Field( + proto.STRING, + number=1, + ) + transaction_id: bytes = proto.Field( + proto.BYTES, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/transaction.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/transaction.py new file mode 100644 index 0000000000..d66d95a04d --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/transaction.py @@ -0,0 +1,673 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.protobuf import duration_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.spanner.v1', + manifest={ + 'TransactionOptions', + 'Transaction', + 'TransactionSelector', + }, +) + + +class TransactionOptions(proto.Message): + r"""Transactions: + + Each session can have at most one active transaction at a time (note + that standalone reads and queries use a transaction internally and + do count towards the one transaction limit). After the active + transaction is completed, the session can immediately be re-used for + the next transaction. It is not necessary to create a new session + for each transaction. + + Transaction modes: + + Cloud Spanner supports three transaction modes: + + 1. Locking read-write. This type of transaction is the only way to + write data into Cloud Spanner. These transactions rely on + pessimistic locking and, if necessary, two-phase commit. Locking + read-write transactions may abort, requiring the application to + retry. + + 2. Snapshot read-only. Snapshot read-only transactions provide + guaranteed consistency across several reads, but do not allow + writes. Snapshot read-only transactions can be configured to read + at timestamps in the past, or configured to perform a strong read + (where Spanner will select a timestamp such that the read is + guaranteed to see the effects of all transactions that have + committed before the start of the read). Snapshot read-only + transactions do not need to be committed. + + Queries on change streams must be performed with the snapshot + read-only transaction mode, specifying a strong read. Please see + [TransactionOptions.ReadOnly.strong][google.spanner.v1.TransactionOptions.ReadOnly.strong] + for more details. + + 3. Partitioned DML. This type of transaction is used to execute a + single Partitioned DML statement. Partitioned DML partitions the + key space and runs the DML statement over each partition in + parallel using separate, internal transactions that commit + independently. Partitioned DML transactions do not need to be + committed. + + For transactions that only read, snapshot read-only transactions + provide simpler semantics and are almost always faster. In + particular, read-only transactions do not take locks, so they do not + conflict with read-write transactions. As a consequence of not + taking locks, they also do not abort, so retry loops are not needed. + + Transactions may only read-write data in a single database. They + may, however, read-write data in different tables within that + database. + + Locking read-write transactions: + + Locking transactions may be used to atomically read-modify-write + data anywhere in a database. This type of transaction is externally + consistent. + + Clients should attempt to minimize the amount of time a transaction + is active. Faster transactions commit with higher probability and + cause less contention. Cloud Spanner attempts to keep read locks + active as long as the transaction continues to do reads, and the + transaction has not been terminated by + [Commit][google.spanner.v1.Spanner.Commit] or + [Rollback][google.spanner.v1.Spanner.Rollback]. Long periods of + inactivity at the client may cause Cloud Spanner to release a + transaction's locks and abort it. + + Conceptually, a read-write transaction consists of zero or more + reads or SQL statements followed by + [Commit][google.spanner.v1.Spanner.Commit]. At any time before + [Commit][google.spanner.v1.Spanner.Commit], the client can send a + [Rollback][google.spanner.v1.Spanner.Rollback] request to abort the + transaction. + + Semantics: + + Cloud Spanner can commit the transaction if all read locks it + acquired are still valid at commit time, and it is able to acquire + write locks for all writes. Cloud Spanner can abort the transaction + for any reason. If a commit attempt returns ``ABORTED``, Cloud + Spanner guarantees that the transaction has not modified any user + data in Cloud Spanner. + + Unless the transaction commits, Cloud Spanner makes no guarantees + about how long the transaction's locks were held for. It is an error + to use Cloud Spanner locks for any sort of mutual exclusion other + than between Cloud Spanner transactions themselves. + + Retrying aborted transactions: + + When a transaction aborts, the application can choose to retry the + whole transaction again. To maximize the chances of successfully + committing the retry, the client should execute the retry in the + same session as the original attempt. The original session's lock + priority increases with each consecutive abort, meaning that each + attempt has a slightly better chance of success than the previous. + + Under some circumstances (for example, many transactions attempting + to modify the same row(s)), a transaction can abort many times in a + short period before successfully committing. Thus, it is not a good + idea to cap the number of retries a transaction can attempt; + instead, it is better to limit the total amount of time spent + retrying. + + Idle transactions: + + A transaction is considered idle if it has no outstanding reads or + SQL queries and has not started a read or SQL query within the last + 10 seconds. Idle transactions can be aborted by Cloud Spanner so + that they don't hold on to locks indefinitely. If an idle + transaction is aborted, the commit will fail with error ``ABORTED``. + + If this behavior is undesirable, periodically executing a simple SQL + query in the transaction (for example, ``SELECT 1``) prevents the + transaction from becoming idle. + + Snapshot read-only transactions: + + Snapshot read-only transactions provides a simpler method than + locking read-write transactions for doing several consistent reads. + However, this type of transaction does not support writes. + + Snapshot transactions do not take locks. Instead, they work by + choosing a Cloud Spanner timestamp, then executing all reads at that + timestamp. Since they do not acquire locks, they do not block + concurrent read-write transactions. + + Unlike locking read-write transactions, snapshot read-only + transactions never abort. They can fail if the chosen read timestamp + is garbage collected; however, the default garbage collection policy + is generous enough that most applications do not need to worry about + this in practice. + + Snapshot read-only transactions do not need to call + [Commit][google.spanner.v1.Spanner.Commit] or + [Rollback][google.spanner.v1.Spanner.Rollback] (and in fact are not + permitted to do so). + + To execute a snapshot transaction, the client specifies a timestamp + bound, which tells Cloud Spanner how to choose a read timestamp. + + The types of timestamp bound are: + + - Strong (the default). + - Bounded staleness. + - Exact staleness. + + If the Cloud Spanner database to be read is geographically + distributed, stale read-only transactions can execute more quickly + than strong or read-write transactions, because they are able to + execute far from the leader replica. + + Each type of timestamp bound is discussed in detail below. + + Strong: Strong reads are guaranteed to see the effects of all + transactions that have committed before the start of the read. + Furthermore, all rows yielded by a single read are consistent with + each other -- if any part of the read observes a transaction, all + parts of the read see the transaction. + + Strong reads are not repeatable: two consecutive strong read-only + transactions might return inconsistent results if there are + concurrent writes. If consistency across reads is required, the + reads should be executed within a transaction or at an exact read + timestamp. + + Queries on change streams (see below for more details) must also + specify the strong read timestamp bound. + + See + [TransactionOptions.ReadOnly.strong][google.spanner.v1.TransactionOptions.ReadOnly.strong]. + + Exact staleness: + + These timestamp bounds execute reads at a user-specified timestamp. + Reads at a timestamp are guaranteed to see a consistent prefix of + the global transaction history: they observe modifications done by + all transactions with a commit timestamp less than or equal to the + read timestamp, and observe none of the modifications done by + transactions with a larger commit timestamp. They will block until + all conflicting transactions that may be assigned commit timestamps + <= the read timestamp have finished. + + The timestamp can either be expressed as an absolute Cloud Spanner + commit timestamp or a staleness relative to the current time. + + These modes do not require a "negotiation phase" to pick a + timestamp. As a result, they execute slightly faster than the + equivalent boundedly stale concurrency modes. On the other hand, + boundedly stale reads usually return fresher results. + + See + [TransactionOptions.ReadOnly.read_timestamp][google.spanner.v1.TransactionOptions.ReadOnly.read_timestamp] + and + [TransactionOptions.ReadOnly.exact_staleness][google.spanner.v1.TransactionOptions.ReadOnly.exact_staleness]. + + Bounded staleness: + + Bounded staleness modes allow Cloud Spanner to pick the read + timestamp, subject to a user-provided staleness bound. Cloud Spanner + chooses the newest timestamp within the staleness bound that allows + execution of the reads at the closest available replica without + blocking. + + All rows yielded are consistent with each other -- if any part of + the read observes a transaction, all parts of the read see the + transaction. Boundedly stale reads are not repeatable: two stale + reads, even if they use the same staleness bound, can execute at + different timestamps and thus return inconsistent results. + + Boundedly stale reads execute in two phases: the first phase + negotiates a timestamp among all replicas needed to serve the read. + In the second phase, reads are executed at the negotiated timestamp. + + As a result of the two phase execution, bounded staleness reads are + usually a little slower than comparable exact staleness reads. + However, they are typically able to return fresher results, and are + more likely to execute at the closest replica. + + Because the timestamp negotiation requires up-front knowledge of + which rows will be read, it can only be used with single-use + read-only transactions. + + See + [TransactionOptions.ReadOnly.max_staleness][google.spanner.v1.TransactionOptions.ReadOnly.max_staleness] + and + [TransactionOptions.ReadOnly.min_read_timestamp][google.spanner.v1.TransactionOptions.ReadOnly.min_read_timestamp]. + + Old read timestamps and garbage collection: + + Cloud Spanner continuously garbage collects deleted and overwritten + data in the background to reclaim storage space. This process is + known as "version GC". By default, version GC reclaims versions + after they are one hour old. Because of this, Cloud Spanner cannot + perform reads at read timestamps more than one hour in the past. + This restriction also applies to in-progress reads and/or SQL + queries whose timestamp become too old while executing. Reads and + SQL queries with too-old read timestamps fail with the error + ``FAILED_PRECONDITION``. + + You can configure and extend the ``VERSION_RETENTION_PERIOD`` of a + database up to a period as long as one week, which allows Cloud + Spanner to perform reads up to one week in the past. + + Querying change Streams: + + A Change Stream is a schema object that can be configured to watch + data changes on the entire database, a set of tables, or a set of + columns in a database. + + When a change stream is created, Spanner automatically defines a + corresponding SQL Table-Valued Function (TVF) that can be used to + query the change records in the associated change stream using the + ExecuteStreamingSql API. The name of the TVF for a change stream is + generated from the name of the change stream: + READ_. + + All queries on change stream TVFs must be executed using the + ExecuteStreamingSql API with a single-use read-only transaction with + a strong read-only timestamp_bound. The change stream TVF allows + users to specify the start_timestamp and end_timestamp for the time + range of interest. All change records within the retention period is + accessible using the strong read-only timestamp_bound. All other + TransactionOptions are invalid for change stream queries. + + In addition, if TransactionOptions.read_only.return_read_timestamp + is set to true, a special value of 2^63 - 2 will be returned in the + [Transaction][google.spanner.v1.Transaction] message that describes + the transaction, instead of a valid read timestamp. This special + value should be discarded and not used for any subsequent queries. + + Please see https://cloud.google.com/spanner/docs/change-streams for + more details on how to query the change stream TVFs. + + Partitioned DML transactions: + + Partitioned DML transactions are used to execute DML statements with + a different execution strategy that provides different, and often + better, scalability properties for large, table-wide operations than + DML in a ReadWrite transaction. Smaller scoped statements, such as + an OLTP workload, should prefer using ReadWrite transactions. + + Partitioned DML partitions the keyspace and runs the DML statement + on each partition in separate, internal transactions. These + transactions commit automatically when complete, and run + independently from one another. + + To reduce lock contention, this execution strategy only acquires + read locks on rows that match the WHERE clause of the statement. + Additionally, the smaller per-partition transactions hold locks for + less time. + + That said, Partitioned DML is not a drop-in replacement for standard + DML used in ReadWrite transactions. + + - The DML statement must be fully-partitionable. Specifically, the + statement must be expressible as the union of many statements + which each access only a single row of the table. + + - The statement is not applied atomically to all rows of the table. + Rather, the statement is applied atomically to partitions of the + table, in independent transactions. Secondary index rows are + updated atomically with the base table rows. + + - Partitioned DML does not guarantee exactly-once execution + semantics against a partition. The statement will be applied at + least once to each partition. It is strongly recommended that the + DML statement should be idempotent to avoid unexpected results. + For instance, it is potentially dangerous to run a statement such + as ``UPDATE table SET column = column + 1`` as it could be run + multiple times against some rows. + + - The partitions are committed automatically - there is no support + for Commit or Rollback. If the call returns an error, or if the + client issuing the ExecuteSql call dies, it is possible that some + rows had the statement executed on them successfully. It is also + possible that statement was never executed against other rows. + + - Partitioned DML transactions may only contain the execution of a + single DML statement via ExecuteSql or ExecuteStreamingSql. + + - If any error is encountered during the execution of the + partitioned DML operation (for instance, a UNIQUE INDEX + violation, division by zero, or a value that cannot be stored due + to schema constraints), then the operation is stopped at that + point and an error is returned. It is possible that at this + point, some partitions have been committed (or even committed + multiple times), and other partitions have not been run at all. + + Given the above, Partitioned DML is good fit for large, + database-wide, operations that are idempotent, such as deleting old + rows from a very large table. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + read_write (google.cloud.spanner_v1.types.TransactionOptions.ReadWrite): + Transaction may write. + + Authorization to begin a read-write transaction requires + ``spanner.databases.beginOrRollbackReadWriteTransaction`` + permission on the ``session`` resource. + + This field is a member of `oneof`_ ``mode``. + partitioned_dml (google.cloud.spanner_v1.types.TransactionOptions.PartitionedDml): + Partitioned DML transaction. + + Authorization to begin a Partitioned DML transaction + requires + ``spanner.databases.beginPartitionedDmlTransaction`` + permission on the ``session`` resource. + + This field is a member of `oneof`_ ``mode``. + read_only (google.cloud.spanner_v1.types.TransactionOptions.ReadOnly): + Transaction will not write. + + Authorization to begin a read-only transaction requires + ``spanner.databases.beginReadOnlyTransaction`` permission on + the ``session`` resource. + + This field is a member of `oneof`_ ``mode``. + """ + + class ReadWrite(proto.Message): + r"""Message type to initiate a read-write transaction. Currently + this transaction type has no options. + + Attributes: + read_lock_mode (google.cloud.spanner_v1.types.TransactionOptions.ReadWrite.ReadLockMode): + Read lock mode for the transaction. + """ + class ReadLockMode(proto.Enum): + r"""``ReadLockMode`` is used to set the read lock mode for read-write + transactions. + + Values: + READ_LOCK_MODE_UNSPECIFIED (0): + Default value. + If the value is not specified, the pessimistic + read lock is used. + PESSIMISTIC (1): + Pessimistic lock mode. + Read locks are acquired immediately on read. + OPTIMISTIC (2): + Optimistic lock mode. + Locks for reads within the transaction are not + acquired on read. Instead the locks are acquired + on a commit to validate that read/queried data + has not changed since the transaction started. + """ + READ_LOCK_MODE_UNSPECIFIED = 0 + PESSIMISTIC = 1 + OPTIMISTIC = 2 + + read_lock_mode: 'TransactionOptions.ReadWrite.ReadLockMode' = proto.Field( + proto.ENUM, + number=1, + enum='TransactionOptions.ReadWrite.ReadLockMode', + ) + + class PartitionedDml(proto.Message): + r"""Message type to initiate a Partitioned DML transaction. + """ + + class ReadOnly(proto.Message): + r"""Message type to initiate a read-only transaction. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + strong (bool): + Read at a timestamp where all previously + committed transactions are visible. + + This field is a member of `oneof`_ ``timestamp_bound``. + min_read_timestamp (google.protobuf.timestamp_pb2.Timestamp): + Executes all reads at a timestamp >= ``min_read_timestamp``. + + This is useful for requesting fresher data than some + previous read, or data that is fresh enough to observe the + effects of some previously committed transaction whose + timestamp is known. + + Note that this option can only be used in single-use + transactions. + + A timestamp in RFC3339 UTC "Zulu" format, accurate to + nanoseconds. Example: ``"2014-10-02T15:01:23.045123456Z"``. + + This field is a member of `oneof`_ ``timestamp_bound``. + max_staleness (google.protobuf.duration_pb2.Duration): + Read data at a timestamp >= ``NOW - max_staleness`` seconds. + Guarantees that all writes that have committed more than the + specified number of seconds ago are visible. Because Cloud + Spanner chooses the exact timestamp, this mode works even if + the client's local clock is substantially skewed from Cloud + Spanner commit timestamps. + + Useful for reading the freshest data available at a nearby + replica, while bounding the possible staleness if the local + replica has fallen behind. + + Note that this option can only be used in single-use + transactions. + + This field is a member of `oneof`_ ``timestamp_bound``. + read_timestamp (google.protobuf.timestamp_pb2.Timestamp): + Executes all reads at the given timestamp. Unlike other + modes, reads at a specific timestamp are repeatable; the + same read at the same timestamp always returns the same + data. If the timestamp is in the future, the read will block + until the specified timestamp, modulo the read's deadline. + + Useful for large scale consistent reads such as mapreduces, + or for coordinating many reads against a consistent snapshot + of the data. + + A timestamp in RFC3339 UTC "Zulu" format, accurate to + nanoseconds. Example: ``"2014-10-02T15:01:23.045123456Z"``. + + This field is a member of `oneof`_ ``timestamp_bound``. + exact_staleness (google.protobuf.duration_pb2.Duration): + Executes all reads at a timestamp that is + ``exact_staleness`` old. The timestamp is chosen soon after + the read is started. + + Guarantees that all writes that have committed more than the + specified number of seconds ago are visible. Because Cloud + Spanner chooses the exact timestamp, this mode works even if + the client's local clock is substantially skewed from Cloud + Spanner commit timestamps. + + Useful for reading at nearby replicas without the + distributed timestamp negotiation overhead of + ``max_staleness``. + + This field is a member of `oneof`_ ``timestamp_bound``. + return_read_timestamp (bool): + If true, the Cloud Spanner-selected read timestamp is + included in the [Transaction][google.spanner.v1.Transaction] + message that describes the transaction. + """ + + strong: bool = proto.Field( + proto.BOOL, + number=1, + oneof='timestamp_bound', + ) + min_read_timestamp: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=2, + oneof='timestamp_bound', + message=timestamp_pb2.Timestamp, + ) + max_staleness: duration_pb2.Duration = proto.Field( + proto.MESSAGE, + number=3, + oneof='timestamp_bound', + message=duration_pb2.Duration, + ) + read_timestamp: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=4, + oneof='timestamp_bound', + message=timestamp_pb2.Timestamp, + ) + exact_staleness: duration_pb2.Duration = proto.Field( + proto.MESSAGE, + number=5, + oneof='timestamp_bound', + message=duration_pb2.Duration, + ) + return_read_timestamp: bool = proto.Field( + proto.BOOL, + number=6, + ) + + read_write: ReadWrite = proto.Field( + proto.MESSAGE, + number=1, + oneof='mode', + message=ReadWrite, + ) + partitioned_dml: PartitionedDml = proto.Field( + proto.MESSAGE, + number=3, + oneof='mode', + message=PartitionedDml, + ) + read_only: ReadOnly = proto.Field( + proto.MESSAGE, + number=2, + oneof='mode', + message=ReadOnly, + ) + + +class Transaction(proto.Message): + r"""A transaction. + + Attributes: + id (bytes): + ``id`` may be used to identify the transaction in subsequent + [Read][google.spanner.v1.Spanner.Read], + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], + [Commit][google.spanner.v1.Spanner.Commit], or + [Rollback][google.spanner.v1.Spanner.Rollback] calls. + + Single-use read-only transactions do not have IDs, because + single-use transactions do not support multiple requests. + read_timestamp (google.protobuf.timestamp_pb2.Timestamp): + For snapshot read-only transactions, the read timestamp + chosen for the transaction. Not returned by default: see + [TransactionOptions.ReadOnly.return_read_timestamp][google.spanner.v1.TransactionOptions.ReadOnly.return_read_timestamp]. + + A timestamp in RFC3339 UTC "Zulu" format, accurate to + nanoseconds. Example: ``"2014-10-02T15:01:23.045123456Z"``. + """ + + id: bytes = proto.Field( + proto.BYTES, + number=1, + ) + read_timestamp: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + + +class TransactionSelector(proto.Message): + r"""This message is used to select the transaction in which a + [Read][google.spanner.v1.Spanner.Read] or + [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] call runs. + + See [TransactionOptions][google.spanner.v1.TransactionOptions] for + more information about transactions. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + single_use (google.cloud.spanner_v1.types.TransactionOptions): + Execute the read or SQL query in a temporary + transaction. This is the most efficient way to + execute a transaction that consists of a single + SQL query. + + This field is a member of `oneof`_ ``selector``. + id (bytes): + Execute the read or SQL query in a + previously-started transaction. + + This field is a member of `oneof`_ ``selector``. + begin (google.cloud.spanner_v1.types.TransactionOptions): + Begin a new transaction and execute this read or SQL query + in it. The transaction ID of the new transaction is returned + in + [ResultSetMetadata.transaction][google.spanner.v1.ResultSetMetadata.transaction], + which is a [Transaction][google.spanner.v1.Transaction]. + + This field is a member of `oneof`_ ``selector``. + """ + + single_use: 'TransactionOptions' = proto.Field( + proto.MESSAGE, + number=1, + oneof='selector', + message='TransactionOptions', + ) + id: bytes = proto.Field( + proto.BYTES, + number=2, + oneof='selector', + ) + begin: 'TransactionOptions' = proto.Field( + proto.MESSAGE, + number=3, + oneof='selector', + message='TransactionOptions', + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/type.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/type.py new file mode 100644 index 0000000000..6b49415ec6 --- /dev/null +++ b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/type.py @@ -0,0 +1,248 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + + +__protobuf__ = proto.module( + package='google.spanner.v1', + manifest={ + 'TypeCode', + 'TypeAnnotationCode', + 'Type', + 'StructType', + }, +) + + +class TypeCode(proto.Enum): + r"""``TypeCode`` is used as part of [Type][google.spanner.v1.Type] to + indicate the type of a Cloud Spanner value. + + Each legal value of a type can be encoded to or decoded from a JSON + value, using the encodings described below. All Cloud Spanner values + can be ``null``, regardless of type; ``null``\ s are always encoded + as a JSON ``null``. + + Values: + TYPE_CODE_UNSPECIFIED (0): + Not specified. + BOOL (1): + Encoded as JSON ``true`` or ``false``. + INT64 (2): + Encoded as ``string``, in decimal format. + FLOAT64 (3): + Encoded as ``number``, or the strings ``"NaN"``, + ``"Infinity"``, or ``"-Infinity"``. + TIMESTAMP (4): + Encoded as ``string`` in RFC 3339 timestamp format. The time + zone must be present, and must be ``"Z"``. + + If the schema has the column option + ``allow_commit_timestamp=true``, the placeholder string + ``"spanner.commit_timestamp()"`` can be used to instruct the + system to insert the commit timestamp associated with the + transaction commit. + DATE (5): + Encoded as ``string`` in RFC 3339 date format. + STRING (6): + Encoded as ``string``. + BYTES (7): + Encoded as a base64-encoded ``string``, as described in RFC + 4648, section 4. + ARRAY (8): + Encoded as ``list``, where the list elements are represented + according to + [array_element_type][google.spanner.v1.Type.array_element_type]. + STRUCT (9): + Encoded as ``list``, where list element ``i`` is represented + according to + [struct_type.fields[i]][google.spanner.v1.StructType.fields]. + NUMERIC (10): + Encoded as ``string``, in decimal format or scientific + notation format. Decimal format: \ ``[+-]Digits[.[Digits]]`` + or \ ``[+-][Digits].Digits`` + + Scientific notation: + \ ``[+-]Digits[.[Digits]][ExponentIndicator[+-]Digits]`` or + \ ``[+-][Digits].Digits[ExponentIndicator[+-]Digits]`` + (ExponentIndicator is ``"e"`` or ``"E"``) + JSON (11): + Encoded as a JSON-formatted ``string`` as described in RFC + 7159. The following rules are applied when parsing JSON + input: + + - Whitespace characters are not preserved. + - If a JSON object has duplicate keys, only the first key + is preserved. + - Members of a JSON object are not guaranteed to have their + order preserved. + - JSON array elements will have their order preserved. + """ + TYPE_CODE_UNSPECIFIED = 0 + BOOL = 1 + INT64 = 2 + FLOAT64 = 3 + TIMESTAMP = 4 + DATE = 5 + STRING = 6 + BYTES = 7 + ARRAY = 8 + STRUCT = 9 + NUMERIC = 10 + JSON = 11 + + +class TypeAnnotationCode(proto.Enum): + r"""``TypeAnnotationCode`` is used as a part of + [Type][google.spanner.v1.Type] to disambiguate SQL types that should + be used for a given Cloud Spanner value. Disambiguation is needed + because the same Cloud Spanner type can be mapped to different SQL + types depending on SQL dialect. TypeAnnotationCode doesn't affect + the way value is serialized. + + Values: + TYPE_ANNOTATION_CODE_UNSPECIFIED (0): + Not specified. + PG_NUMERIC (2): + PostgreSQL compatible NUMERIC type. This annotation needs to + be applied to [Type][google.spanner.v1.Type] instances + having [NUMERIC][google.spanner.v1.TypeCode.NUMERIC] type + code to specify that values of this type should be treated + as PostgreSQL NUMERIC values. Currently this annotation is + always needed for + [NUMERIC][google.spanner.v1.TypeCode.NUMERIC] when a client + interacts with PostgreSQL-enabled Spanner databases. + PG_JSONB (3): + PostgreSQL compatible JSONB type. This annotation needs to + be applied to [Type][google.spanner.v1.Type] instances + having [JSON][google.spanner.v1.TypeCode.JSON] type code to + specify that values of this type should be treated as + PostgreSQL JSONB values. Currently this annotation is always + needed for [JSON][google.spanner.v1.TypeCode.JSON] when a + client interacts with PostgreSQL-enabled Spanner databases. + """ + TYPE_ANNOTATION_CODE_UNSPECIFIED = 0 + PG_NUMERIC = 2 + PG_JSONB = 3 + + +class Type(proto.Message): + r"""``Type`` indicates the type of a Cloud Spanner value, as might be + stored in a table cell or returned from an SQL query. + + Attributes: + code (google.cloud.spanner_v1.types.TypeCode): + Required. The [TypeCode][google.spanner.v1.TypeCode] for + this type. + array_element_type (google.cloud.spanner_v1.types.Type): + If [code][google.spanner.v1.Type.code] == + [ARRAY][google.spanner.v1.TypeCode.ARRAY], then + ``array_element_type`` is the type of the array elements. + struct_type (google.cloud.spanner_v1.types.StructType): + If [code][google.spanner.v1.Type.code] == + [STRUCT][google.spanner.v1.TypeCode.STRUCT], then + ``struct_type`` provides type information for the struct's + fields. + type_annotation (google.cloud.spanner_v1.types.TypeAnnotationCode): + The + [TypeAnnotationCode][google.spanner.v1.TypeAnnotationCode] + that disambiguates SQL type that Spanner will use to + represent values of this type during query processing. This + is necessary for some type codes because a single + [TypeCode][google.spanner.v1.TypeCode] can be mapped to + different SQL types depending on the SQL dialect. + [type_annotation][google.spanner.v1.Type.type_annotation] + typically is not needed to process the content of a value + (it doesn't affect serialization) and clients can ignore it + on the read path. + """ + + code: 'TypeCode' = proto.Field( + proto.ENUM, + number=1, + enum='TypeCode', + ) + array_element_type: 'Type' = proto.Field( + proto.MESSAGE, + number=2, + message='Type', + ) + struct_type: 'StructType' = proto.Field( + proto.MESSAGE, + number=3, + message='StructType', + ) + type_annotation: 'TypeAnnotationCode' = proto.Field( + proto.ENUM, + number=4, + enum='TypeAnnotationCode', + ) + + +class StructType(proto.Message): + r"""``StructType`` defines the fields of a + [STRUCT][google.spanner.v1.TypeCode.STRUCT] type. + + Attributes: + fields (MutableSequence[google.cloud.spanner_v1.types.StructType.Field]): + The list of fields that make up this struct. Order is + significant, because values of this struct type are + represented as lists, where the order of field values + matches the order of fields in the + [StructType][google.spanner.v1.StructType]. In turn, the + order of fields matches the order of columns in a read + request, or the order of fields in the ``SELECT`` clause of + a query. + """ + + class Field(proto.Message): + r"""Message representing a single field of a struct. + + Attributes: + name (str): + The name of the field. For reads, this is the column name. + For SQL queries, it is the column alias (e.g., ``"Word"`` in + the query ``"SELECT 'hello' AS Word"``), or the column name + (e.g., ``"ColName"`` in the query + ``"SELECT ColName FROM Table"``). Some columns might have an + empty name (e.g., ``"SELECT UPPER(ColName)"``). Note that a + query result can contain multiple fields with the same name. + type_ (google.cloud.spanner_v1.types.Type): + The type of the field. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + type_: 'Type' = proto.Field( + proto.MESSAGE, + number=2, + message='Type', + ) + + fields: MutableSequence[Field] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=Field, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/mypy.ini b/owl-bot-staging/spanner/v1/mypy.ini new file mode 100644 index 0000000000..574c5aed39 --- /dev/null +++ b/owl-bot-staging/spanner/v1/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.7 +namespace_packages = True diff --git a/owl-bot-staging/spanner/v1/noxfile.py b/owl-bot-staging/spanner/v1/noxfile.py new file mode 100644 index 0000000000..cdf1942502 --- /dev/null +++ b/owl-bot-staging/spanner/v1/noxfile.py @@ -0,0 +1,184 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import pathlib +import shutil +import subprocess +import sys + + +import nox # type: ignore + +ALL_PYTHON = [ + "3.7", + "3.8", + "3.9", + "3.10", + "3.11", +] + +CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() + +LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" +PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8") + +BLACK_VERSION = "black==22.3.0" +BLACK_PATHS = ["docs", "google", "tests", "samples", "noxfile.py", "setup.py"] +DEFAULT_PYTHON_VERSION = "3.11" + +nox.sessions = [ + "unit", + "cover", + "mypy", + "check_lower_bounds" + # exclude update_lower_bounds from default + "docs", + "blacken", + "lint", + "lint_setup_py", +] + +@nox.session(python=ALL_PYTHON) +def unit(session): + """Run the unit test suite.""" + + session.install('coverage', 'pytest', 'pytest-cov', 'pytest-asyncio', 'asyncmock; python_version < "3.8"') + session.install('-e', '.') + + session.run( + 'py.test', + '--quiet', + '--cov=google/cloud/spanner_v1/', + '--cov=tests/', + '--cov-config=.coveragerc', + '--cov-report=term', + '--cov-report=html', + os.path.join('tests', 'unit', ''.join(session.posargs)) + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def cover(session): + """Run the final coverage report. + This outputs the coverage report aggregating coverage from the unit + test runs (not system test runs), and then erases coverage data. + """ + session.install("coverage", "pytest-cov") + session.run("coverage", "report", "--show-missing", "--fail-under=100") + + session.run("coverage", "erase") + + +@nox.session(python=ALL_PYTHON) +def mypy(session): + """Run the type checker.""" + session.install( + 'mypy', + 'types-requests', + 'types-protobuf' + ) + session.install('.') + session.run( + 'mypy', + '--explicit-package-bases', + 'google', + ) + + +@nox.session +def update_lower_bounds(session): + """Update lower bounds in constraints.txt to match setup.py""" + session.install('google-cloud-testutils') + session.install('.') + + session.run( + 'lower-bound-checker', + 'update', + '--package-name', + PACKAGE_NAME, + '--constraints-file', + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + + +@nox.session +def check_lower_bounds(session): + """Check lower bounds in setup.py are reflected in constraints file""" + session.install('google-cloud-testutils') + session.install('.') + + session.run( + 'lower-bound-checker', + 'check', + '--package-name', + PACKAGE_NAME, + '--constraints-file', + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def docs(session): + """Build the docs for this library.""" + + session.install("-e", ".") + session.install("sphinx==4.0.1", "alabaster", "recommonmark") + + shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) + session.run( + "sphinx-build", + "-W", # warnings as errors + "-T", # show full traceback on exception + "-N", # no colors + "-b", + "html", + "-d", + os.path.join("docs", "_build", "doctrees", ""), + os.path.join("docs", ""), + os.path.join("docs", "_build", "html", ""), + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def lint(session): + """Run linters. + + Returns a failure if the linters find linting errors or sufficiently + serious code quality issues. + """ + session.install("flake8", BLACK_VERSION) + session.run( + "black", + "--check", + *BLACK_PATHS, + ) + session.run("flake8", "google", "tests", "samples") + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def blacken(session): + """Run black. Format code to uniform standard.""" + session.install(BLACK_VERSION) + session.run( + "black", + *BLACK_PATHS, + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def lint_setup_py(session): + """Verify that setup.py is valid (including RST check).""" + session.install("docutils", "pygments") + session.run("python", "setup.py", "check", "--restructuredtext", "--strict") diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/snippet_metadata_google.spanner.v1.json b/owl-bot-staging/spanner/v1/samples/generated_samples/snippet_metadata_google.spanner.v1.json new file mode 100644 index 0000000000..a8e8be3ae3 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/snippet_metadata_google.spanner.v1.json @@ -0,0 +1,2410 @@ +{ + "clientLibrary": { + "apis": [ + { + "id": "google.spanner.v1", + "version": "v1" + } + ], + "language": "PYTHON", + "name": "google-cloud-spanner", + "version": "0.1.0" + }, + "snippets": [ + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.batch_create_sessions", + "method": { + "fullName": "google.spanner.v1.Spanner.BatchCreateSessions", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "BatchCreateSessions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.BatchCreateSessionsRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "session_count", + "type": "int" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.BatchCreateSessionsResponse", + "shortName": "batch_create_sessions" + }, + "description": "Sample for BatchCreateSessions", + "file": "spanner_v1_generated_spanner_batch_create_sessions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_BatchCreateSessions_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_batch_create_sessions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.batch_create_sessions", + "method": { + "fullName": "google.spanner.v1.Spanner.BatchCreateSessions", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "BatchCreateSessions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.BatchCreateSessionsRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "session_count", + "type": "int" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.BatchCreateSessionsResponse", + "shortName": "batch_create_sessions" + }, + "description": "Sample for BatchCreateSessions", + "file": "spanner_v1_generated_spanner_batch_create_sessions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_BatchCreateSessions_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_batch_create_sessions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.begin_transaction", + "method": { + "fullName": "google.spanner.v1.Spanner.BeginTransaction", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "BeginTransaction" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.BeginTransactionRequest" + }, + { + "name": "session", + "type": "str" + }, + { + "name": "options", + "type": "google.cloud.spanner_v1.types.TransactionOptions" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.Transaction", + "shortName": "begin_transaction" + }, + "description": "Sample for BeginTransaction", + "file": "spanner_v1_generated_spanner_begin_transaction_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_BeginTransaction_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_begin_transaction_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.begin_transaction", + "method": { + "fullName": "google.spanner.v1.Spanner.BeginTransaction", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "BeginTransaction" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.BeginTransactionRequest" + }, + { + "name": "session", + "type": "str" + }, + { + "name": "options", + "type": "google.cloud.spanner_v1.types.TransactionOptions" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.Transaction", + "shortName": "begin_transaction" + }, + "description": "Sample for BeginTransaction", + "file": "spanner_v1_generated_spanner_begin_transaction_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_BeginTransaction_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_begin_transaction_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.commit", + "method": { + "fullName": "google.spanner.v1.Spanner.Commit", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "Commit" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.CommitRequest" + }, + { + "name": "session", + "type": "str" + }, + { + "name": "transaction_id", + "type": "bytes" + }, + { + "name": "mutations", + "type": "MutableSequence[google.cloud.spanner_v1.types.Mutation]" + }, + { + "name": "single_use_transaction", + "type": "google.cloud.spanner_v1.types.TransactionOptions" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.CommitResponse", + "shortName": "commit" + }, + "description": "Sample for Commit", + "file": "spanner_v1_generated_spanner_commit_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_Commit_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_commit_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.commit", + "method": { + "fullName": "google.spanner.v1.Spanner.Commit", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "Commit" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.CommitRequest" + }, + { + "name": "session", + "type": "str" + }, + { + "name": "transaction_id", + "type": "bytes" + }, + { + "name": "mutations", + "type": "MutableSequence[google.cloud.spanner_v1.types.Mutation]" + }, + { + "name": "single_use_transaction", + "type": "google.cloud.spanner_v1.types.TransactionOptions" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.CommitResponse", + "shortName": "commit" + }, + "description": "Sample for Commit", + "file": "spanner_v1_generated_spanner_commit_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_Commit_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_commit_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.create_session", + "method": { + "fullName": "google.spanner.v1.Spanner.CreateSession", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "CreateSession" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.CreateSessionRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.Session", + "shortName": "create_session" + }, + "description": "Sample for CreateSession", + "file": "spanner_v1_generated_spanner_create_session_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_CreateSession_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_create_session_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.create_session", + "method": { + "fullName": "google.spanner.v1.Spanner.CreateSession", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "CreateSession" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.CreateSessionRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.Session", + "shortName": "create_session" + }, + "description": "Sample for CreateSession", + "file": "spanner_v1_generated_spanner_create_session_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_CreateSession_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_create_session_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.delete_session", + "method": { + "fullName": "google.spanner.v1.Spanner.DeleteSession", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "DeleteSession" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.DeleteSessionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_session" + }, + "description": "Sample for DeleteSession", + "file": "spanner_v1_generated_spanner_delete_session_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_DeleteSession_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_delete_session_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.delete_session", + "method": { + "fullName": "google.spanner.v1.Spanner.DeleteSession", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "DeleteSession" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.DeleteSessionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_session" + }, + "description": "Sample for DeleteSession", + "file": "spanner_v1_generated_spanner_delete_session_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_DeleteSession_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_delete_session_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.execute_batch_dml", + "method": { + "fullName": "google.spanner.v1.Spanner.ExecuteBatchDml", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ExecuteBatchDml" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ExecuteBatchDmlRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.ExecuteBatchDmlResponse", + "shortName": "execute_batch_dml" + }, + "description": "Sample for ExecuteBatchDml", + "file": "spanner_v1_generated_spanner_execute_batch_dml_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ExecuteBatchDml_async", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 50, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 51, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_execute_batch_dml_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.execute_batch_dml", + "method": { + "fullName": "google.spanner.v1.Spanner.ExecuteBatchDml", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ExecuteBatchDml" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ExecuteBatchDmlRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.ExecuteBatchDmlResponse", + "shortName": "execute_batch_dml" + }, + "description": "Sample for ExecuteBatchDml", + "file": "spanner_v1_generated_spanner_execute_batch_dml_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ExecuteBatchDml_sync", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 50, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 51, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_execute_batch_dml_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.execute_sql", + "method": { + "fullName": "google.spanner.v1.Spanner.ExecuteSql", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ExecuteSql" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ExecuteSqlRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.ResultSet", + "shortName": "execute_sql" + }, + "description": "Sample for ExecuteSql", + "file": "spanner_v1_generated_spanner_execute_sql_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ExecuteSql_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_execute_sql_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.execute_sql", + "method": { + "fullName": "google.spanner.v1.Spanner.ExecuteSql", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ExecuteSql" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ExecuteSqlRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.ResultSet", + "shortName": "execute_sql" + }, + "description": "Sample for ExecuteSql", + "file": "spanner_v1_generated_spanner_execute_sql_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ExecuteSql_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_execute_sql_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.execute_streaming_sql", + "method": { + "fullName": "google.spanner.v1.Spanner.ExecuteStreamingSql", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ExecuteStreamingSql" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ExecuteSqlRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.spanner_v1.types.PartialResultSet]", + "shortName": "execute_streaming_sql" + }, + "description": "Sample for ExecuteStreamingSql", + "file": "spanner_v1_generated_spanner_execute_streaming_sql_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ExecuteStreamingSql_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_execute_streaming_sql_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.execute_streaming_sql", + "method": { + "fullName": "google.spanner.v1.Spanner.ExecuteStreamingSql", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ExecuteStreamingSql" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ExecuteSqlRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.spanner_v1.types.PartialResultSet]", + "shortName": "execute_streaming_sql" + }, + "description": "Sample for ExecuteStreamingSql", + "file": "spanner_v1_generated_spanner_execute_streaming_sql_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ExecuteStreamingSql_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_execute_streaming_sql_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.get_session", + "method": { + "fullName": "google.spanner.v1.Spanner.GetSession", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "GetSession" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.GetSessionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.Session", + "shortName": "get_session" + }, + "description": "Sample for GetSession", + "file": "spanner_v1_generated_spanner_get_session_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_GetSession_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_get_session_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.get_session", + "method": { + "fullName": "google.spanner.v1.Spanner.GetSession", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "GetSession" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.GetSessionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.Session", + "shortName": "get_session" + }, + "description": "Sample for GetSession", + "file": "spanner_v1_generated_spanner_get_session_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_GetSession_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_get_session_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.list_sessions", + "method": { + "fullName": "google.spanner.v1.Spanner.ListSessions", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ListSessions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ListSessionsRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.services.spanner.pagers.ListSessionsAsyncPager", + "shortName": "list_sessions" + }, + "description": "Sample for ListSessions", + "file": "spanner_v1_generated_spanner_list_sessions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ListSessions_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_list_sessions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.list_sessions", + "method": { + "fullName": "google.spanner.v1.Spanner.ListSessions", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "ListSessions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ListSessionsRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.services.spanner.pagers.ListSessionsPager", + "shortName": "list_sessions" + }, + "description": "Sample for ListSessions", + "file": "spanner_v1_generated_spanner_list_sessions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_ListSessions_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_list_sessions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.partition_query", + "method": { + "fullName": "google.spanner.v1.Spanner.PartitionQuery", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "PartitionQuery" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.PartitionQueryRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.PartitionResponse", + "shortName": "partition_query" + }, + "description": "Sample for PartitionQuery", + "file": "spanner_v1_generated_spanner_partition_query_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_PartitionQuery_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_partition_query_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.partition_query", + "method": { + "fullName": "google.spanner.v1.Spanner.PartitionQuery", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "PartitionQuery" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.PartitionQueryRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.PartitionResponse", + "shortName": "partition_query" + }, + "description": "Sample for PartitionQuery", + "file": "spanner_v1_generated_spanner_partition_query_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_PartitionQuery_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_partition_query_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.partition_read", + "method": { + "fullName": "google.spanner.v1.Spanner.PartitionRead", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "PartitionRead" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.PartitionReadRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.PartitionResponse", + "shortName": "partition_read" + }, + "description": "Sample for PartitionRead", + "file": "spanner_v1_generated_spanner_partition_read_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_PartitionRead_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_partition_read_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.partition_read", + "method": { + "fullName": "google.spanner.v1.Spanner.PartitionRead", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "PartitionRead" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.PartitionReadRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.PartitionResponse", + "shortName": "partition_read" + }, + "description": "Sample for PartitionRead", + "file": "spanner_v1_generated_spanner_partition_read_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_PartitionRead_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_partition_read_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.read", + "method": { + "fullName": "google.spanner.v1.Spanner.Read", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "Read" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ReadRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.ResultSet", + "shortName": "read" + }, + "description": "Sample for Read", + "file": "spanner_v1_generated_spanner_read_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_Read_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_read_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.read", + "method": { + "fullName": "google.spanner.v1.Spanner.Read", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "Read" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ReadRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_v1.types.ResultSet", + "shortName": "read" + }, + "description": "Sample for Read", + "file": "spanner_v1_generated_spanner_read_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_Read_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_read_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.rollback", + "method": { + "fullName": "google.spanner.v1.Spanner.Rollback", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "Rollback" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.RollbackRequest" + }, + { + "name": "session", + "type": "str" + }, + { + "name": "transaction_id", + "type": "bytes" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "rollback" + }, + "description": "Sample for Rollback", + "file": "spanner_v1_generated_spanner_rollback_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_Rollback_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_rollback_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.rollback", + "method": { + "fullName": "google.spanner.v1.Spanner.Rollback", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "Rollback" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.RollbackRequest" + }, + { + "name": "session", + "type": "str" + }, + { + "name": "transaction_id", + "type": "bytes" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "rollback" + }, + "description": "Sample for Rollback", + "file": "spanner_v1_generated_spanner_rollback_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_Rollback_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_rollback_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", + "shortName": "SpannerAsyncClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.streaming_read", + "method": { + "fullName": "google.spanner.v1.Spanner.StreamingRead", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "StreamingRead" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ReadRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.spanner_v1.types.PartialResultSet]", + "shortName": "streaming_read" + }, + "description": "Sample for StreamingRead", + "file": "spanner_v1_generated_spanner_streaming_read_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_StreamingRead_async", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_streaming_read_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_v1.SpannerClient", + "shortName": "SpannerClient" + }, + "fullName": "google.cloud.spanner_v1.SpannerClient.streaming_read", + "method": { + "fullName": "google.spanner.v1.Spanner.StreamingRead", + "service": { + "fullName": "google.spanner.v1.Spanner", + "shortName": "Spanner" + }, + "shortName": "StreamingRead" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_v1.types.ReadRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.spanner_v1.types.PartialResultSet]", + "shortName": "streaming_read" + }, + "description": "Sample for StreamingRead", + "file": "spanner_v1_generated_spanner_streaming_read_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_Spanner_StreamingRead_sync", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_spanner_streaming_read_sync.py" + } + ] +} diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_async.py new file mode 100644 index 0000000000..44c9850315 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateSessions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_BatchCreateSessions_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_batch_create_sessions(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.BatchCreateSessionsRequest( + database="database_value", + session_count=1420, + ) + + # Make the request + response = await client.batch_create_sessions(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_BatchCreateSessions_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_sync.py new file mode 100644 index 0000000000..35e256e2fb --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateSessions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_BatchCreateSessions_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_batch_create_sessions(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.BatchCreateSessionsRequest( + database="database_value", + session_count=1420, + ) + + # Make the request + response = client.batch_create_sessions(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_BatchCreateSessions_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_async.py new file mode 100644 index 0000000000..86b292e2d9 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BeginTransaction +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_BeginTransaction_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_begin_transaction(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.BeginTransactionRequest( + session="session_value", + ) + + # Make the request + response = await client.begin_transaction(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_BeginTransaction_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_sync.py new file mode 100644 index 0000000000..7a7cecad3a --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BeginTransaction +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_BeginTransaction_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_begin_transaction(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.BeginTransactionRequest( + session="session_value", + ) + + # Make the request + response = client.begin_transaction(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_BeginTransaction_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_async.py new file mode 100644 index 0000000000..2f60d31995 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Commit +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_Commit_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_commit(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.CommitRequest( + transaction_id=b'transaction_id_blob', + session="session_value", + ) + + # Make the request + response = await client.commit(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_Commit_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_sync.py new file mode 100644 index 0000000000..8badd1cbf3 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Commit +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_Commit_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_commit(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.CommitRequest( + transaction_id=b'transaction_id_blob', + session="session_value", + ) + + # Make the request + response = client.commit(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_Commit_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_async.py new file mode 100644 index 0000000000..e55a750deb --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateSession +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_CreateSession_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_create_session(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.CreateSessionRequest( + database="database_value", + ) + + # Make the request + response = await client.create_session(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_CreateSession_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_sync.py new file mode 100644 index 0000000000..e5d8d5561d --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateSession +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_CreateSession_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_create_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.CreateSessionRequest( + database="database_value", + ) + + # Make the request + response = client.create_session(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_CreateSession_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_async.py new file mode 100644 index 0000000000..b81c530274 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSession +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_DeleteSession_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_delete_session(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.DeleteSessionRequest( + name="name_value", + ) + + # Make the request + await client.delete_session(request=request) + + +# [END spanner_v1_generated_Spanner_DeleteSession_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_sync.py new file mode 100644 index 0000000000..fedf7a3f6f --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSession +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_DeleteSession_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_delete_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.DeleteSessionRequest( + name="name_value", + ) + + # Make the request + client.delete_session(request=request) + + +# [END spanner_v1_generated_Spanner_DeleteSession_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_async.py new file mode 100644 index 0000000000..971b21fbdf --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_async.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExecuteBatchDml +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ExecuteBatchDml_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_execute_batch_dml(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + statements = spanner_v1.Statement() + statements.sql = "sql_value" + + request = spanner_v1.ExecuteBatchDmlRequest( + session="session_value", + statements=statements, + seqno=550, + ) + + # Make the request + response = await client.execute_batch_dml(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_ExecuteBatchDml_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_sync.py new file mode 100644 index 0000000000..9bce572521 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_sync.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExecuteBatchDml +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ExecuteBatchDml_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_execute_batch_dml(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + statements = spanner_v1.Statement() + statements.sql = "sql_value" + + request = spanner_v1.ExecuteBatchDmlRequest( + session="session_value", + statements=statements, + seqno=550, + ) + + # Make the request + response = client.execute_batch_dml(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_ExecuteBatchDml_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_async.py new file mode 100644 index 0000000000..b904386d10 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExecuteSql +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ExecuteSql_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_execute_sql(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = await client.execute_sql(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_ExecuteSql_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_sync.py new file mode 100644 index 0000000000..2591106775 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExecuteSql +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ExecuteSql_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_execute_sql(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = client.execute_sql(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_ExecuteSql_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_async.py new file mode 100644 index 0000000000..0165a9e66c --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExecuteStreamingSql +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ExecuteStreamingSql_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_execute_streaming_sql(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + stream = await client.execute_streaming_sql(request=request) + + # Handle the response + async for response in stream: + print(response) + +# [END spanner_v1_generated_Spanner_ExecuteStreamingSql_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_sync.py new file mode 100644 index 0000000000..9f6d434588 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExecuteStreamingSql +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ExecuteStreamingSql_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_execute_streaming_sql(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ExecuteSqlRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + stream = client.execute_streaming_sql(request=request) + + # Handle the response + for response in stream: + print(response) + +# [END spanner_v1_generated_Spanner_ExecuteStreamingSql_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_async.py new file mode 100644 index 0000000000..f2400b8631 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSession +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_GetSession_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_get_session(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.GetSessionRequest( + name="name_value", + ) + + # Make the request + response = await client.get_session(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_GetSession_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_sync.py new file mode 100644 index 0000000000..157f7d60fc --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSession +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_GetSession_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_get_session(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.GetSessionRequest( + name="name_value", + ) + + # Make the request + response = client.get_session(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_GetSession_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_async.py new file mode 100644 index 0000000000..35205eadd4 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSessions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ListSessions_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_list_sessions(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ListSessionsRequest( + database="database_value", + ) + + # Make the request + page_result = client.list_sessions(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_Spanner_ListSessions_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_sync.py new file mode 100644 index 0000000000..0cc98c4366 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSessions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_ListSessions_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_list_sessions(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ListSessionsRequest( + database="database_value", + ) + + # Make the request + page_result = client.list_sessions(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_Spanner_ListSessions_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_async.py new file mode 100644 index 0000000000..4c821844b1 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PartitionQuery +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_PartitionQuery_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_partition_query(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionQueryRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = await client.partition_query(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_PartitionQuery_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_sync.py new file mode 100644 index 0000000000..1008022404 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PartitionQuery +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_PartitionQuery_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_partition_query(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionQueryRequest( + session="session_value", + sql="sql_value", + ) + + # Make the request + response = client.partition_query(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_PartitionQuery_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_async.py new file mode 100644 index 0000000000..050dd4028b --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PartitionRead +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_PartitionRead_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_partition_read(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionReadRequest( + session="session_value", + table="table_value", + ) + + # Make the request + response = await client.partition_read(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_PartitionRead_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_sync.py new file mode 100644 index 0000000000..52bfcb48c3 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PartitionRead +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_PartitionRead_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_partition_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.PartitionReadRequest( + session="session_value", + table="table_value", + ) + + # Make the request + response = client.partition_read(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_PartitionRead_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_async.py new file mode 100644 index 0000000000..8d79db7524 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Read +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_Read_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_read(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value1', 'columns_value2'], + ) + + # Make the request + response = await client.read(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_Read_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_sync.py new file mode 100644 index 0000000000..512e29c917 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Read +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_Read_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value1', 'columns_value2'], + ) + + # Make the request + response = client.read(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_Spanner_Read_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_async.py new file mode 100644 index 0000000000..edfd86d457 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Rollback +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_Rollback_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_rollback(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.RollbackRequest( + session="session_value", + transaction_id=b'transaction_id_blob', + ) + + # Make the request + await client.rollback(request=request) + + +# [END spanner_v1_generated_Spanner_Rollback_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_sync.py new file mode 100644 index 0000000000..6fe90e6678 --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Rollback +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_Rollback_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_rollback(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.RollbackRequest( + session="session_value", + transaction_id=b'transaction_id_blob', + ) + + # Make the request + client.rollback(request=request) + + +# [END spanner_v1_generated_Spanner_Rollback_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_async.py new file mode 100644 index 0000000000..9709b040ea --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_async.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StreamingRead +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_StreamingRead_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +async def sample_streaming_read(): + # Create a client + client = spanner_v1.SpannerAsyncClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value1', 'columns_value2'], + ) + + # Make the request + stream = await client.streaming_read(request=request) + + # Handle the response + async for response in stream: + print(response) + +# [END spanner_v1_generated_Spanner_StreamingRead_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_sync.py new file mode 100644 index 0000000000..3d5636eadb --- /dev/null +++ b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_sync.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StreamingRead +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner + + +# [START spanner_v1_generated_Spanner_StreamingRead_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_v1 + + +def sample_streaming_read(): + # Create a client + client = spanner_v1.SpannerClient() + + # Initialize request argument(s) + request = spanner_v1.ReadRequest( + session="session_value", + table="table_value", + columns=['columns_value1', 'columns_value2'], + ) + + # Make the request + stream = client.streaming_read(request=request) + + # Handle the response + for response in stream: + print(response) + +# [END spanner_v1_generated_Spanner_StreamingRead_sync] diff --git a/owl-bot-staging/spanner/v1/scripts/fixup_spanner_v1_keywords.py b/owl-bot-staging/spanner/v1/scripts/fixup_spanner_v1_keywords.py new file mode 100644 index 0000000000..b897807106 --- /dev/null +++ b/owl-bot-staging/spanner/v1/scripts/fixup_spanner_v1_keywords.py @@ -0,0 +1,190 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import argparse +import os +import libcst as cst +import pathlib +import sys +from typing import (Any, Callable, Dict, List, Sequence, Tuple) + + +def partition( + predicate: Callable[[Any], bool], + iterator: Sequence[Any] +) -> Tuple[List[Any], List[Any]]: + """A stable, out-of-place partition.""" + results = ([], []) + + for i in iterator: + results[int(predicate(i))].append(i) + + # Returns trueList, falseList + return results[1], results[0] + + +class spannerCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'batch_create_sessions': ('database', 'session_count', 'session_template', ), + 'begin_transaction': ('session', 'options', 'request_options', ), + 'commit': ('session', 'transaction_id', 'single_use_transaction', 'mutations', 'return_commit_stats', 'request_options', ), + 'create_session': ('database', 'session', ), + 'delete_session': ('name', ), + 'execute_batch_dml': ('session', 'transaction', 'statements', 'seqno', 'request_options', ), + 'execute_sql': ('session', 'sql', 'transaction', 'params', 'param_types', 'resume_token', 'query_mode', 'partition_token', 'seqno', 'query_options', 'request_options', 'data_boost_enabled', ), + 'execute_streaming_sql': ('session', 'sql', 'transaction', 'params', 'param_types', 'resume_token', 'query_mode', 'partition_token', 'seqno', 'query_options', 'request_options', 'data_boost_enabled', ), + 'get_session': ('name', ), + 'list_sessions': ('database', 'page_size', 'page_token', 'filter', ), + 'partition_query': ('session', 'sql', 'transaction', 'params', 'param_types', 'partition_options', ), + 'partition_read': ('session', 'table', 'key_set', 'transaction', 'index', 'columns', 'partition_options', ), + 'read': ('session', 'table', 'columns', 'key_set', 'transaction', 'index', 'limit', 'resume_token', 'partition_token', 'request_options', 'data_boost_enabled', ), + 'rollback': ('session', 'transaction_id', ), + 'streaming_read': ('session', 'table', 'columns', 'key_set', 'transaction', 'index', 'limit', 'resume_token', 'partition_token', 'request_options', 'data_boost_enabled', ), + } + + def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: + try: + key = original.func.attr.value + kword_params = self.METHOD_TO_PARAMS[key] + except (AttributeError, KeyError): + # Either not a method from the API or too convoluted to be sure. + return updated + + # If the existing code is valid, keyword args come after positional args. + # Therefore, all positional args must map to the first parameters. + args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) + if any(k.keyword.value == "request" for k in kwargs): + # We've already fixed this file, don't fix it again. + return updated + + kwargs, ctrl_kwargs = partition( + lambda a: a.keyword.value not in self.CTRL_PARAMS, + kwargs + ) + + args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] + ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) + for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) + + request_arg = cst.Arg( + value=cst.Dict([ + cst.DictElement( + cst.SimpleString("'{}'".format(name)), +cst.Element(value=arg.value) + ) + # Note: the args + kwargs looks silly, but keep in mind that + # the control parameters had to be stripped out, and that + # those could have been passed positionally or by keyword. + for name, arg in zip(kword_params, args + kwargs)]), + keyword=cst.Name("request") + ) + + return updated.with_changes( + args=[request_arg] + ctrl_kwargs + ) + + +def fix_files( + in_dir: pathlib.Path, + out_dir: pathlib.Path, + *, + transformer=spannerCallTransformer(), +): + """Duplicate the input dir to the output dir, fixing file method calls. + + Preconditions: + * in_dir is a real directory + * out_dir is a real, empty directory + """ + pyfile_gen = ( + pathlib.Path(os.path.join(root, f)) + for root, _, files in os.walk(in_dir) + for f in files if os.path.splitext(f)[1] == ".py" + ) + + for fpath in pyfile_gen: + with open(fpath, 'r') as f: + src = f.read() + + # Parse the code and insert method call fixes. + tree = cst.parse_module(src) + updated = tree.visit(transformer) + + # Create the path and directory structure for the new file. + updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) + updated_path.parent.mkdir(parents=True, exist_ok=True) + + # Generate the updated source file at the corresponding path. + with open(updated_path, 'w') as f: + f.write(updated.code) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description="""Fix up source that uses the spanner client library. + +The existing sources are NOT overwritten but are copied to output_dir with changes made. + +Note: This tool operates at a best-effort level at converting positional + parameters in client method calls to keyword based parameters. + Cases where it WILL FAIL include + A) * or ** expansion in a method call. + B) Calls via function or method alias (includes free function calls) + C) Indirect or dispatched calls (e.g. the method is looked up dynamically) + + These all constitute false negatives. The tool will also detect false + positives when an API method shares a name with another method. +""") + parser.add_argument( + '-d', + '--input-directory', + required=True, + dest='input_dir', + help='the input directory to walk for python files to fix up', + ) + parser.add_argument( + '-o', + '--output-directory', + required=True, + dest='output_dir', + help='the directory to output files fixed via un-flattening', + ) + args = parser.parse_args() + input_dir = pathlib.Path(args.input_dir) + output_dir = pathlib.Path(args.output_dir) + if not input_dir.is_dir(): + print( + f"input directory '{input_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if not output_dir.is_dir(): + print( + f"output directory '{output_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if os.listdir(output_dir): + print( + f"output directory '{output_dir}' is not empty", + file=sys.stderr, + ) + sys.exit(-1) + + fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/spanner/v1/setup.py b/owl-bot-staging/spanner/v1/setup.py new file mode 100644 index 0000000000..322e535102 --- /dev/null +++ b/owl-bot-staging/spanner/v1/setup.py @@ -0,0 +1,90 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import io +import os + +import setuptools # type: ignore + +package_root = os.path.abspath(os.path.dirname(__file__)) + +name = 'google-cloud-spanner' + + +description = "Google Cloud Spanner API client library" + +version = {} +with open(os.path.join(package_root, 'google/cloud/spanner/gapic_version.py')) as fp: + exec(fp.read(), version) +version = version["__version__"] + +if version[0] == "0": + release_status = "Development Status :: 4 - Beta" +else: + release_status = "Development Status :: 5 - Production/Stable" + +dependencies = [ + "google-api-core[grpc] >= 1.34.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "proto-plus >= 1.22.0, <2.0.0dev", + "proto-plus >= 1.22.2, <2.0.0dev; python_version>='3.11'", + "protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", +] +url = "https://github.com/googleapis/python-spanner" + +package_root = os.path.abspath(os.path.dirname(__file__)) + +readme_filename = os.path.join(package_root, "README.rst") +with io.open(readme_filename, encoding="utf-8") as readme_file: + readme = readme_file.read() + +packages = [ + package + for package in setuptools.PEP420PackageFinder.find() + if package.startswith("google") +] + +namespaces = ["google", "google.cloud"] + +setuptools.setup( + name=name, + version=version, + description=description, + long_description=readme, + author="Google LLC", + author_email="googleapis-packages@google.com", + license="Apache 2.0", + url=url, + classifiers=[ + release_status, + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Operating System :: OS Independent", + "Topic :: Internet", + ], + platforms="Posix; MacOS X; Windows", + packages=packages, + python_requires=">=3.7", + namespace_packages=namespaces, + install_requires=dependencies, + include_package_data=True, + zip_safe=False, +) diff --git a/owl-bot-staging/spanner/v1/testing/constraints-3.10.txt b/owl-bot-staging/spanner/v1/testing/constraints-3.10.txt new file mode 100644 index 0000000000..ed7f9aed25 --- /dev/null +++ b/owl-bot-staging/spanner/v1/testing/constraints-3.10.txt @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf diff --git a/owl-bot-staging/spanner/v1/testing/constraints-3.11.txt b/owl-bot-staging/spanner/v1/testing/constraints-3.11.txt new file mode 100644 index 0000000000..ed7f9aed25 --- /dev/null +++ b/owl-bot-staging/spanner/v1/testing/constraints-3.11.txt @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf diff --git a/owl-bot-staging/spanner/v1/testing/constraints-3.12.txt b/owl-bot-staging/spanner/v1/testing/constraints-3.12.txt new file mode 100644 index 0000000000..ed7f9aed25 --- /dev/null +++ b/owl-bot-staging/spanner/v1/testing/constraints-3.12.txt @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf diff --git a/owl-bot-staging/spanner/v1/testing/constraints-3.7.txt b/owl-bot-staging/spanner/v1/testing/constraints-3.7.txt new file mode 100644 index 0000000000..6c44adfea7 --- /dev/null +++ b/owl-bot-staging/spanner/v1/testing/constraints-3.7.txt @@ -0,0 +1,9 @@ +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file. +# Pin the version to the lower bound. +# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", +# Then this file should have google-cloud-foo==1.14.0 +google-api-core==1.34.0 +proto-plus==1.22.0 +protobuf==3.19.5 diff --git a/owl-bot-staging/spanner/v1/testing/constraints-3.8.txt b/owl-bot-staging/spanner/v1/testing/constraints-3.8.txt new file mode 100644 index 0000000000..ed7f9aed25 --- /dev/null +++ b/owl-bot-staging/spanner/v1/testing/constraints-3.8.txt @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf diff --git a/owl-bot-staging/spanner/v1/testing/constraints-3.9.txt b/owl-bot-staging/spanner/v1/testing/constraints-3.9.txt new file mode 100644 index 0000000000..ed7f9aed25 --- /dev/null +++ b/owl-bot-staging/spanner/v1/testing/constraints-3.9.txt @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf diff --git a/owl-bot-staging/spanner/v1/tests/__init__.py b/owl-bot-staging/spanner/v1/tests/__init__.py new file mode 100644 index 0000000000..231bc12501 --- /dev/null +++ b/owl-bot-staging/spanner/v1/tests/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner/v1/tests/unit/__init__.py b/owl-bot-staging/spanner/v1/tests/unit/__init__.py new file mode 100644 index 0000000000..231bc12501 --- /dev/null +++ b/owl-bot-staging/spanner/v1/tests/unit/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner/v1/tests/unit/gapic/__init__.py b/owl-bot-staging/spanner/v1/tests/unit/gapic/__init__.py new file mode 100644 index 0000000000..231bc12501 --- /dev/null +++ b/owl-bot-staging/spanner/v1/tests/unit/gapic/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/__init__.py b/owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/__init__.py new file mode 100644 index 0000000000..231bc12501 --- /dev/null +++ b/owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/test_spanner.py b/owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/test_spanner.py new file mode 100644 index 0000000000..e6954d4dbd --- /dev/null +++ b/owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/test_spanner.py @@ -0,0 +1,7665 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock # pragma: NO COVER +except ImportError: # pragma: NO COVER + import mock + +import grpc +from grpc.experimental import aio +from collections.abc import Iterable +from google.protobuf import json_format +import json +import math +import pytest +from proto.marshal.rules.dates import DurationRule, TimestampRule +from proto.marshal.rules import wrappers +from requests import Response +from requests import Request, PreparedRequest +from requests.sessions import Session +from google.protobuf import json_format + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.spanner_v1.services.spanner import SpannerAsyncClient +from google.cloud.spanner_v1.services.spanner import SpannerClient +from google.cloud.spanner_v1.services.spanner import pagers +from google.cloud.spanner_v1.services.spanner import transports +from google.cloud.spanner_v1.types import commit_response +from google.cloud.spanner_v1.types import keys +from google.cloud.spanner_v1.types import mutation +from google.cloud.spanner_v1.types import result_set +from google.cloud.spanner_v1.types import spanner +from google.cloud.spanner_v1.types import transaction +from google.cloud.spanner_v1.types import type as gs_type +from google.oauth2 import service_account +from google.protobuf import duration_pb2 # type: ignore +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +import google.auth + + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert SpannerClient._get_default_mtls_endpoint(None) is None + assert SpannerClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert SpannerClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert SpannerClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert SpannerClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert SpannerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class,transport_name", [ + (SpannerClient, "grpc"), + (SpannerAsyncClient, "grpc_asyncio"), + (SpannerClient, "rest"), +]) +def test_spanner_client_from_service_account_info(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info, transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ( + 'spanner.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://spanner.googleapis.com' + ) + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.SpannerGrpcTransport, "grpc"), + (transports.SpannerGrpcAsyncIOTransport, "grpc_asyncio"), + (transports.SpannerRestTransport, "rest"), +]) +def test_spanner_client_service_account_always_use_jwt(transport_class, transport_name): + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class,transport_name", [ + (SpannerClient, "grpc"), + (SpannerAsyncClient, "grpc_asyncio"), + (SpannerClient, "rest"), +]) +def test_spanner_client_from_service_account_file(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: + factory.return_value = creds + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ( + 'spanner.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://spanner.googleapis.com' + ) + + +def test_spanner_client_get_transport_class(): + transport = SpannerClient.get_transport_class() + available_transports = [ + transports.SpannerGrpcTransport, + transports.SpannerRestTransport, + ] + assert transport in available_transports + + transport = SpannerClient.get_transport_class("grpc") + assert transport == transports.SpannerGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (SpannerClient, transports.SpannerGrpcTransport, "grpc"), + (SpannerAsyncClient, transports.SpannerGrpcAsyncIOTransport, "grpc_asyncio"), + (SpannerClient, transports.SpannerRestTransport, "rest"), +]) +@mock.patch.object(SpannerClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SpannerClient)) +@mock.patch.object(SpannerAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SpannerAsyncClient)) +def test_spanner_client_client_options(client_class, transport_class, transport_name): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(SpannerClient, 'get_transport_class') as gtc: + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(SpannerClient, 'get_transport_class') as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name, client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class(transport=transport_name) + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError): + client = client_class(transport=transport_name) + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + # Check the case api_endpoint is provided + options = client_options.ClientOptions(api_audience="https://language.googleapis.com") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience="https://language.googleapis.com" + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (SpannerClient, transports.SpannerGrpcTransport, "grpc", "true"), + (SpannerAsyncClient, transports.SpannerGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (SpannerClient, transports.SpannerGrpcTransport, "grpc", "false"), + (SpannerAsyncClient, transports.SpannerGrpcAsyncIOTransport, "grpc_asyncio", "false"), + (SpannerClient, transports.SpannerRestTransport, "rest", "true"), + (SpannerClient, transports.SpannerRestTransport, "rest", "false"), +]) +@mock.patch.object(SpannerClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SpannerClient)) +@mock.patch.object(SpannerAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SpannerAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_spanner_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + +@pytest.mark.parametrize("client_class", [ + SpannerClient, SpannerAsyncClient +]) +@mock.patch.object(SpannerClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SpannerClient)) +@mock.patch.object(SpannerAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SpannerAsyncClient)) +def test_spanner_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_client_cert_source): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (SpannerClient, transports.SpannerGrpcTransport, "grpc"), + (SpannerAsyncClient, transports.SpannerGrpcAsyncIOTransport, "grpc_asyncio"), + (SpannerClient, transports.SpannerRestTransport, "rest"), +]) +def test_spanner_client_client_options_scopes(client_class, transport_class, transport_name): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ + (SpannerClient, transports.SpannerGrpcTransport, "grpc", grpc_helpers), + (SpannerAsyncClient, transports.SpannerGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), + (SpannerClient, transports.SpannerRestTransport, "rest", None), +]) +def test_spanner_client_client_options_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + +def test_spanner_client_client_options_from_dict(): + with mock.patch('google.cloud.spanner_v1.services.spanner.transports.SpannerGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = SpannerClient( + client_options={'api_endpoint': 'squid.clam.whelk'} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ + (SpannerClient, transports.SpannerGrpcTransport, "grpc", grpc_helpers), + (SpannerAsyncClient, transports.SpannerGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), +]) +def test_spanner_client_create_channel_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "spanner.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.data', +), + scopes=None, + default_host="spanner.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.CreateSessionRequest, + dict, +]) +def test_create_session(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_session), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.Session( + name='name_value', + creator_role='creator_role_value', + ) + response = client.create_session(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.CreateSessionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.Session) + assert response.name == 'name_value' + assert response.creator_role == 'creator_role_value' + + +def test_create_session_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_session), + '__call__') as call: + client.create_session() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.CreateSessionRequest() + +@pytest.mark.asyncio +async def test_create_session_async(transport: str = 'grpc_asyncio', request_type=spanner.CreateSessionRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_session), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner.Session( + name='name_value', + creator_role='creator_role_value', + )) + response = await client.create_session(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.CreateSessionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.Session) + assert response.name == 'name_value' + assert response.creator_role == 'creator_role_value' + + +@pytest.mark.asyncio +async def test_create_session_async_from_dict(): + await test_create_session_async(request_type=dict) + + +def test_create_session_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.CreateSessionRequest() + + request.database = 'database_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_session), + '__call__') as call: + call.return_value = spanner.Session() + client.create_session(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'database=database_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_create_session_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.CreateSessionRequest() + + request.database = 'database_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_session), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.Session()) + await client.create_session(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'database=database_value', + ) in kw['metadata'] + + +def test_create_session_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_session), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.Session() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_session( + database='database_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = 'database_value' + assert arg == mock_val + + +def test_create_session_flattened_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_session( + spanner.CreateSessionRequest(), + database='database_value', + ) + +@pytest.mark.asyncio +async def test_create_session_flattened_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_session), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.Session() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.Session()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_session( + database='database_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = 'database_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_create_session_flattened_error_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_session( + spanner.CreateSessionRequest(), + database='database_value', + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.BatchCreateSessionsRequest, + dict, +]) +def test_batch_create_sessions(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_sessions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.BatchCreateSessionsResponse( + ) + response = client.batch_create_sessions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.BatchCreateSessionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.BatchCreateSessionsResponse) + + +def test_batch_create_sessions_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_sessions), + '__call__') as call: + client.batch_create_sessions() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.BatchCreateSessionsRequest() + +@pytest.mark.asyncio +async def test_batch_create_sessions_async(transport: str = 'grpc_asyncio', request_type=spanner.BatchCreateSessionsRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_sessions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner.BatchCreateSessionsResponse( + )) + response = await client.batch_create_sessions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.BatchCreateSessionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.BatchCreateSessionsResponse) + + +@pytest.mark.asyncio +async def test_batch_create_sessions_async_from_dict(): + await test_batch_create_sessions_async(request_type=dict) + + +def test_batch_create_sessions_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.BatchCreateSessionsRequest() + + request.database = 'database_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_sessions), + '__call__') as call: + call.return_value = spanner.BatchCreateSessionsResponse() + client.batch_create_sessions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'database=database_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_batch_create_sessions_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.BatchCreateSessionsRequest() + + request.database = 'database_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_sessions), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.BatchCreateSessionsResponse()) + await client.batch_create_sessions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'database=database_value', + ) in kw['metadata'] + + +def test_batch_create_sessions_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_sessions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.BatchCreateSessionsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_create_sessions( + database='database_value', + session_count=1420, + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = 'database_value' + assert arg == mock_val + arg = args[0].session_count + mock_val = 1420 + assert arg == mock_val + + +def test_batch_create_sessions_flattened_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.batch_create_sessions( + spanner.BatchCreateSessionsRequest(), + database='database_value', + session_count=1420, + ) + +@pytest.mark.asyncio +async def test_batch_create_sessions_flattened_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_sessions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.BatchCreateSessionsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.BatchCreateSessionsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_create_sessions( + database='database_value', + session_count=1420, + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = 'database_value' + assert arg == mock_val + arg = args[0].session_count + mock_val = 1420 + assert arg == mock_val + +@pytest.mark.asyncio +async def test_batch_create_sessions_flattened_error_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.batch_create_sessions( + spanner.BatchCreateSessionsRequest(), + database='database_value', + session_count=1420, + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.GetSessionRequest, + dict, +]) +def test_get_session(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_session), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.Session( + name='name_value', + creator_role='creator_role_value', + ) + response = client.get_session(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.GetSessionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.Session) + assert response.name == 'name_value' + assert response.creator_role == 'creator_role_value' + + +def test_get_session_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_session), + '__call__') as call: + client.get_session() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.GetSessionRequest() + +@pytest.mark.asyncio +async def test_get_session_async(transport: str = 'grpc_asyncio', request_type=spanner.GetSessionRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_session), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner.Session( + name='name_value', + creator_role='creator_role_value', + )) + response = await client.get_session(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.GetSessionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.Session) + assert response.name == 'name_value' + assert response.creator_role == 'creator_role_value' + + +@pytest.mark.asyncio +async def test_get_session_async_from_dict(): + await test_get_session_async(request_type=dict) + + +def test_get_session_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.GetSessionRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_session), + '__call__') as call: + call.return_value = spanner.Session() + client.get_session(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_get_session_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.GetSessionRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_session), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.Session()) + await client.get_session(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +def test_get_session_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_session), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.Session() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_session( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + + +def test_get_session_flattened_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_session( + spanner.GetSessionRequest(), + name='name_value', + ) + +@pytest.mark.asyncio +async def test_get_session_flattened_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_session), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.Session() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.Session()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_session( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_get_session_flattened_error_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_session( + spanner.GetSessionRequest(), + name='name_value', + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.ListSessionsRequest, + dict, +]) +def test_list_sessions(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_sessions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.ListSessionsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_sessions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ListSessionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListSessionsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_sessions_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_sessions), + '__call__') as call: + client.list_sessions() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ListSessionsRequest() + +@pytest.mark.asyncio +async def test_list_sessions_async(transport: str = 'grpc_asyncio', request_type=spanner.ListSessionsRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_sessions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner.ListSessionsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_sessions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ListSessionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListSessionsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_sessions_async_from_dict(): + await test_list_sessions_async(request_type=dict) + + +def test_list_sessions_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.ListSessionsRequest() + + request.database = 'database_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_sessions), + '__call__') as call: + call.return_value = spanner.ListSessionsResponse() + client.list_sessions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'database=database_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_list_sessions_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.ListSessionsRequest() + + request.database = 'database_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_sessions), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.ListSessionsResponse()) + await client.list_sessions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'database=database_value', + ) in kw['metadata'] + + +def test_list_sessions_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_sessions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.ListSessionsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_sessions( + database='database_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = 'database_value' + assert arg == mock_val + + +def test_list_sessions_flattened_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_sessions( + spanner.ListSessionsRequest(), + database='database_value', + ) + +@pytest.mark.asyncio +async def test_list_sessions_flattened_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_sessions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.ListSessionsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.ListSessionsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_sessions( + database='database_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = 'database_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_list_sessions_flattened_error_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_sessions( + spanner.ListSessionsRequest(), + database='database_value', + ) + + +def test_list_sessions_pager(transport_name: str = "grpc"): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_sessions), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + spanner.Session(), + spanner.Session(), + ], + next_page_token='abc', + ), + spanner.ListSessionsResponse( + sessions=[], + next_page_token='def', + ), + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + ], + next_page_token='ghi', + ), + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + spanner.Session(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('database', ''), + )), + ) + pager = client.list_sessions(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, spanner.Session) + for i in results) +def test_list_sessions_pages(transport_name: str = "grpc"): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_sessions), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + spanner.Session(), + spanner.Session(), + ], + next_page_token='abc', + ), + spanner.ListSessionsResponse( + sessions=[], + next_page_token='def', + ), + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + ], + next_page_token='ghi', + ), + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + spanner.Session(), + ], + ), + RuntimeError, + ) + pages = list(client.list_sessions(request={}).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.asyncio +async def test_list_sessions_async_pager(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_sessions), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + spanner.Session(), + spanner.Session(), + ], + next_page_token='abc', + ), + spanner.ListSessionsResponse( + sessions=[], + next_page_token='def', + ), + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + ], + next_page_token='ghi', + ), + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + spanner.Session(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_sessions(request={},) + assert async_pager.next_page_token == 'abc' + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, spanner.Session) + for i in responses) + + +@pytest.mark.asyncio +async def test_list_sessions_async_pages(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_sessions), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + spanner.Session(), + spanner.Session(), + ], + next_page_token='abc', + ), + spanner.ListSessionsResponse( + sessions=[], + next_page_token='def', + ), + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + ], + next_page_token='ghi', + ), + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + spanner.Session(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_sessions(request={})).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.parametrize("request_type", [ + spanner.DeleteSessionRequest, + dict, +]) +def test_delete_session(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_session), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_session(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.DeleteSessionRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_session_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_session), + '__call__') as call: + client.delete_session() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.DeleteSessionRequest() + +@pytest.mark.asyncio +async def test_delete_session_async(transport: str = 'grpc_asyncio', request_type=spanner.DeleteSessionRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_session), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_session(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.DeleteSessionRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_session_async_from_dict(): + await test_delete_session_async(request_type=dict) + + +def test_delete_session_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.DeleteSessionRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_session), + '__call__') as call: + call.return_value = None + client.delete_session(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_delete_session_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.DeleteSessionRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_session), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_session(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +def test_delete_session_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_session), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_session( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + + +def test_delete_session_flattened_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_session( + spanner.DeleteSessionRequest(), + name='name_value', + ) + +@pytest.mark.asyncio +async def test_delete_session_flattened_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_session), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_session( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_delete_session_flattened_error_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_session( + spanner.DeleteSessionRequest(), + name='name_value', + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.ExecuteSqlRequest, + dict, +]) +def test_execute_sql(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_sql), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = result_set.ResultSet( + ) + response = client.execute_sql(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ExecuteSqlRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, result_set.ResultSet) + + +def test_execute_sql_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_sql), + '__call__') as call: + client.execute_sql() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ExecuteSqlRequest() + +@pytest.mark.asyncio +async def test_execute_sql_async(transport: str = 'grpc_asyncio', request_type=spanner.ExecuteSqlRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_sql), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(result_set.ResultSet( + )) + response = await client.execute_sql(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ExecuteSqlRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, result_set.ResultSet) + + +@pytest.mark.asyncio +async def test_execute_sql_async_from_dict(): + await test_execute_sql_async(request_type=dict) + + +def test_execute_sql_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.ExecuteSqlRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_sql), + '__call__') as call: + call.return_value = result_set.ResultSet() + client.execute_sql(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_execute_sql_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.ExecuteSqlRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_sql), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(result_set.ResultSet()) + await client.execute_sql(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.parametrize("request_type", [ + spanner.ExecuteSqlRequest, + dict, +]) +def test_execute_streaming_sql(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_streaming_sql), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = iter([result_set.PartialResultSet()]) + response = client.execute_streaming_sql(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ExecuteSqlRequest() + + # Establish that the response is the type that we expect. + for message in response: + assert isinstance(message, result_set.PartialResultSet) + + +def test_execute_streaming_sql_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_streaming_sql), + '__call__') as call: + client.execute_streaming_sql() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ExecuteSqlRequest() + +@pytest.mark.asyncio +async def test_execute_streaming_sql_async(transport: str = 'grpc_asyncio', request_type=spanner.ExecuteSqlRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_streaming_sql), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + call.return_value.read = mock.AsyncMock(side_effect=[result_set.PartialResultSet()]) + response = await client.execute_streaming_sql(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ExecuteSqlRequest() + + # Establish that the response is the type that we expect. + message = await response.read() + assert isinstance(message, result_set.PartialResultSet) + + +@pytest.mark.asyncio +async def test_execute_streaming_sql_async_from_dict(): + await test_execute_streaming_sql_async(request_type=dict) + + +def test_execute_streaming_sql_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.ExecuteSqlRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_streaming_sql), + '__call__') as call: + call.return_value = iter([result_set.PartialResultSet()]) + client.execute_streaming_sql(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_execute_streaming_sql_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.ExecuteSqlRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_streaming_sql), + '__call__') as call: + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + call.return_value.read = mock.AsyncMock(side_effect=[result_set.PartialResultSet()]) + await client.execute_streaming_sql(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.parametrize("request_type", [ + spanner.ExecuteBatchDmlRequest, + dict, +]) +def test_execute_batch_dml(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_batch_dml), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.ExecuteBatchDmlResponse( + ) + response = client.execute_batch_dml(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ExecuteBatchDmlRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.ExecuteBatchDmlResponse) + + +def test_execute_batch_dml_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_batch_dml), + '__call__') as call: + client.execute_batch_dml() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ExecuteBatchDmlRequest() + +@pytest.mark.asyncio +async def test_execute_batch_dml_async(transport: str = 'grpc_asyncio', request_type=spanner.ExecuteBatchDmlRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_batch_dml), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner.ExecuteBatchDmlResponse( + )) + response = await client.execute_batch_dml(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ExecuteBatchDmlRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.ExecuteBatchDmlResponse) + + +@pytest.mark.asyncio +async def test_execute_batch_dml_async_from_dict(): + await test_execute_batch_dml_async(request_type=dict) + + +def test_execute_batch_dml_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.ExecuteBatchDmlRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_batch_dml), + '__call__') as call: + call.return_value = spanner.ExecuteBatchDmlResponse() + client.execute_batch_dml(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_execute_batch_dml_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.ExecuteBatchDmlRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.execute_batch_dml), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.ExecuteBatchDmlResponse()) + await client.execute_batch_dml(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.parametrize("request_type", [ + spanner.ReadRequest, + dict, +]) +def test_read(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = result_set.ResultSet( + ) + response = client.read(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ReadRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, result_set.ResultSet) + + +def test_read_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read), + '__call__') as call: + client.read() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ReadRequest() + +@pytest.mark.asyncio +async def test_read_async(transport: str = 'grpc_asyncio', request_type=spanner.ReadRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(result_set.ResultSet( + )) + response = await client.read(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ReadRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, result_set.ResultSet) + + +@pytest.mark.asyncio +async def test_read_async_from_dict(): + await test_read_async(request_type=dict) + + +def test_read_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.ReadRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read), + '__call__') as call: + call.return_value = result_set.ResultSet() + client.read(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_read_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.ReadRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(result_set.ResultSet()) + await client.read(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.parametrize("request_type", [ + spanner.ReadRequest, + dict, +]) +def test_streaming_read(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.streaming_read), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = iter([result_set.PartialResultSet()]) + response = client.streaming_read(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ReadRequest() + + # Establish that the response is the type that we expect. + for message in response: + assert isinstance(message, result_set.PartialResultSet) + + +def test_streaming_read_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.streaming_read), + '__call__') as call: + client.streaming_read() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ReadRequest() + +@pytest.mark.asyncio +async def test_streaming_read_async(transport: str = 'grpc_asyncio', request_type=spanner.ReadRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.streaming_read), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + call.return_value.read = mock.AsyncMock(side_effect=[result_set.PartialResultSet()]) + response = await client.streaming_read(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.ReadRequest() + + # Establish that the response is the type that we expect. + message = await response.read() + assert isinstance(message, result_set.PartialResultSet) + + +@pytest.mark.asyncio +async def test_streaming_read_async_from_dict(): + await test_streaming_read_async(request_type=dict) + + +def test_streaming_read_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.ReadRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.streaming_read), + '__call__') as call: + call.return_value = iter([result_set.PartialResultSet()]) + client.streaming_read(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_streaming_read_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.ReadRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.streaming_read), + '__call__') as call: + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + call.return_value.read = mock.AsyncMock(side_effect=[result_set.PartialResultSet()]) + await client.streaming_read(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.parametrize("request_type", [ + spanner.BeginTransactionRequest, + dict, +]) +def test_begin_transaction(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.begin_transaction), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = transaction.Transaction( + id=b'id_blob', + ) + response = client.begin_transaction(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.BeginTransactionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, transaction.Transaction) + assert response.id == b'id_blob' + + +def test_begin_transaction_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.begin_transaction), + '__call__') as call: + client.begin_transaction() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.BeginTransactionRequest() + +@pytest.mark.asyncio +async def test_begin_transaction_async(transport: str = 'grpc_asyncio', request_type=spanner.BeginTransactionRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.begin_transaction), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(transaction.Transaction( + id=b'id_blob', + )) + response = await client.begin_transaction(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.BeginTransactionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, transaction.Transaction) + assert response.id == b'id_blob' + + +@pytest.mark.asyncio +async def test_begin_transaction_async_from_dict(): + await test_begin_transaction_async(request_type=dict) + + +def test_begin_transaction_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.BeginTransactionRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.begin_transaction), + '__call__') as call: + call.return_value = transaction.Transaction() + client.begin_transaction(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_begin_transaction_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.BeginTransactionRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.begin_transaction), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(transaction.Transaction()) + await client.begin_transaction(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +def test_begin_transaction_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.begin_transaction), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = transaction.Transaction() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.begin_transaction( + session='session_value', + options=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].session + mock_val = 'session_value' + assert arg == mock_val + arg = args[0].options + mock_val = transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)) + assert arg == mock_val + + +def test_begin_transaction_flattened_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.begin_transaction( + spanner.BeginTransactionRequest(), + session='session_value', + options=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), + ) + +@pytest.mark.asyncio +async def test_begin_transaction_flattened_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.begin_transaction), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = transaction.Transaction() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(transaction.Transaction()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.begin_transaction( + session='session_value', + options=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].session + mock_val = 'session_value' + assert arg == mock_val + arg = args[0].options + mock_val = transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)) + assert arg == mock_val + +@pytest.mark.asyncio +async def test_begin_transaction_flattened_error_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.begin_transaction( + spanner.BeginTransactionRequest(), + session='session_value', + options=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.CommitRequest, + dict, +]) +def test_commit(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.commit), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = commit_response.CommitResponse( + ) + response = client.commit(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.CommitRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, commit_response.CommitResponse) + + +def test_commit_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.commit), + '__call__') as call: + client.commit() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.CommitRequest() + +@pytest.mark.asyncio +async def test_commit_async(transport: str = 'grpc_asyncio', request_type=spanner.CommitRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.commit), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(commit_response.CommitResponse( + )) + response = await client.commit(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.CommitRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, commit_response.CommitResponse) + + +@pytest.mark.asyncio +async def test_commit_async_from_dict(): + await test_commit_async(request_type=dict) + + +def test_commit_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.CommitRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.commit), + '__call__') as call: + call.return_value = commit_response.CommitResponse() + client.commit(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_commit_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.CommitRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.commit), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(commit_response.CommitResponse()) + await client.commit(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +def test_commit_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.commit), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = commit_response.CommitResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.commit( + session='session_value', + transaction_id=b'transaction_id_blob', + mutations=[mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))], + single_use_transaction=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].session + mock_val = 'session_value' + assert arg == mock_val + arg = args[0].mutations + mock_val = [mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))] + assert arg == mock_val + assert args[0].single_use_transaction == transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)) + + +def test_commit_flattened_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.commit( + spanner.CommitRequest(), + session='session_value', + transaction_id=b'transaction_id_blob', + mutations=[mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))], + single_use_transaction=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), + ) + +@pytest.mark.asyncio +async def test_commit_flattened_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.commit), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = commit_response.CommitResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(commit_response.CommitResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.commit( + session='session_value', + transaction_id=b'transaction_id_blob', + mutations=[mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))], + single_use_transaction=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].session + mock_val = 'session_value' + assert arg == mock_val + arg = args[0].mutations + mock_val = [mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))] + assert arg == mock_val + assert args[0].single_use_transaction == transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)) + +@pytest.mark.asyncio +async def test_commit_flattened_error_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.commit( + spanner.CommitRequest(), + session='session_value', + transaction_id=b'transaction_id_blob', + mutations=[mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))], + single_use_transaction=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.RollbackRequest, + dict, +]) +def test_rollback(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.rollback), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.rollback(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.RollbackRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_rollback_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.rollback), + '__call__') as call: + client.rollback() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.RollbackRequest() + +@pytest.mark.asyncio +async def test_rollback_async(transport: str = 'grpc_asyncio', request_type=spanner.RollbackRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.rollback), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.rollback(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.RollbackRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_rollback_async_from_dict(): + await test_rollback_async(request_type=dict) + + +def test_rollback_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.RollbackRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.rollback), + '__call__') as call: + call.return_value = None + client.rollback(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_rollback_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.RollbackRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.rollback), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.rollback(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +def test_rollback_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.rollback), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.rollback( + session='session_value', + transaction_id=b'transaction_id_blob', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].session + mock_val = 'session_value' + assert arg == mock_val + arg = args[0].transaction_id + mock_val = b'transaction_id_blob' + assert arg == mock_val + + +def test_rollback_flattened_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.rollback( + spanner.RollbackRequest(), + session='session_value', + transaction_id=b'transaction_id_blob', + ) + +@pytest.mark.asyncio +async def test_rollback_flattened_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.rollback), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.rollback( + session='session_value', + transaction_id=b'transaction_id_blob', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].session + mock_val = 'session_value' + assert arg == mock_val + arg = args[0].transaction_id + mock_val = b'transaction_id_blob' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_rollback_flattened_error_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.rollback( + spanner.RollbackRequest(), + session='session_value', + transaction_id=b'transaction_id_blob', + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.PartitionQueryRequest, + dict, +]) +def test_partition_query(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.partition_query), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.PartitionResponse( + ) + response = client.partition_query(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.PartitionQueryRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.PartitionResponse) + + +def test_partition_query_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.partition_query), + '__call__') as call: + client.partition_query() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.PartitionQueryRequest() + +@pytest.mark.asyncio +async def test_partition_query_async(transport: str = 'grpc_asyncio', request_type=spanner.PartitionQueryRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.partition_query), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner.PartitionResponse( + )) + response = await client.partition_query(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.PartitionQueryRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.PartitionResponse) + + +@pytest.mark.asyncio +async def test_partition_query_async_from_dict(): + await test_partition_query_async(request_type=dict) + + +def test_partition_query_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.PartitionQueryRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.partition_query), + '__call__') as call: + call.return_value = spanner.PartitionResponse() + client.partition_query(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_partition_query_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.PartitionQueryRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.partition_query), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.PartitionResponse()) + await client.partition_query(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.parametrize("request_type", [ + spanner.PartitionReadRequest, + dict, +]) +def test_partition_read(request_type, transport: str = 'grpc'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.partition_read), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner.PartitionResponse( + ) + response = client.partition_read(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.PartitionReadRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.PartitionResponse) + + +def test_partition_read_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.partition_read), + '__call__') as call: + client.partition_read() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.PartitionReadRequest() + +@pytest.mark.asyncio +async def test_partition_read_async(transport: str = 'grpc_asyncio', request_type=spanner.PartitionReadRequest): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.partition_read), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner.PartitionResponse( + )) + response = await client.partition_read(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner.PartitionReadRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.PartitionResponse) + + +@pytest.mark.asyncio +async def test_partition_read_async_from_dict(): + await test_partition_read_async(request_type=dict) + + +def test_partition_read_field_headers(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.PartitionReadRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.partition_read), + '__call__') as call: + call.return_value = spanner.PartitionResponse() + client.partition_read(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_partition_read_field_headers_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner.PartitionReadRequest() + + request.session = 'session_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.partition_read), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.PartitionResponse()) + await client.partition_read(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'session=session_value', + ) in kw['metadata'] + + +@pytest.mark.parametrize("request_type", [ + spanner.CreateSessionRequest, + dict, +]) +def test_create_session_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner.Session( + name='name_value', + creator_role='creator_role_value', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner.Session.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.create_session(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.Session) + assert response.name == 'name_value' + assert response.creator_role == 'creator_role_value' + + +def test_create_session_rest_required_fields(request_type=spanner.CreateSessionRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["database"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_session._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["database"] = 'database_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_session._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "database" in jsonified_request + assert jsonified_request["database"] == 'database_value' + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner.Session() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner.Session.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.create_session(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_create_session_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.create_session._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("database", "session", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_session_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "post_create_session") as post, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_create_session") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner.CreateSessionRequest.pb(spanner.CreateSessionRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner.Session.to_json(spanner.Session()) + + request = spanner.CreateSessionRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner.Session() + + client.create_session(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_create_session_rest_bad_request(transport: str = 'rest', request_type=spanner.CreateSessionRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.create_session(request) + + +def test_create_session_rest_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner.Session() + + # get arguments that satisfy an http rule for this method + sample_request = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + + # get truthy value for each flattened field + mock_args = dict( + database='database_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner.Session.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.create_session(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{database=projects/*/instances/*/databases/*}/sessions" % client.transport._host, args[1]) + + +def test_create_session_rest_flattened_error(transport: str = 'rest'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_session( + spanner.CreateSessionRequest(), + database='database_value', + ) + + +def test_create_session_rest_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.BatchCreateSessionsRequest, + dict, +]) +def test_batch_create_sessions_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner.BatchCreateSessionsResponse( + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner.BatchCreateSessionsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.batch_create_sessions(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.BatchCreateSessionsResponse) + + +def test_batch_create_sessions_rest_required_fields(request_type=spanner.BatchCreateSessionsRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["database"] = "" + request_init["session_count"] = 0 + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).batch_create_sessions._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["database"] = 'database_value' + jsonified_request["sessionCount"] = 1420 + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).batch_create_sessions._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "database" in jsonified_request + assert jsonified_request["database"] == 'database_value' + assert "sessionCount" in jsonified_request + assert jsonified_request["sessionCount"] == 1420 + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner.BatchCreateSessionsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner.BatchCreateSessionsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.batch_create_sessions(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_batch_create_sessions_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.batch_create_sessions._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("database", "sessionCount", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_batch_create_sessions_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "post_batch_create_sessions") as post, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_batch_create_sessions") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner.BatchCreateSessionsRequest.pb(spanner.BatchCreateSessionsRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner.BatchCreateSessionsResponse.to_json(spanner.BatchCreateSessionsResponse()) + + request = spanner.BatchCreateSessionsRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner.BatchCreateSessionsResponse() + + client.batch_create_sessions(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_batch_create_sessions_rest_bad_request(transport: str = 'rest', request_type=spanner.BatchCreateSessionsRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.batch_create_sessions(request) + + +def test_batch_create_sessions_rest_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner.BatchCreateSessionsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + + # get truthy value for each flattened field + mock_args = dict( + database='database_value', + session_count=1420, + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner.BatchCreateSessionsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.batch_create_sessions(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{database=projects/*/instances/*/databases/*}/sessions:batchCreate" % client.transport._host, args[1]) + + +def test_batch_create_sessions_rest_flattened_error(transport: str = 'rest'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.batch_create_sessions( + spanner.BatchCreateSessionsRequest(), + database='database_value', + session_count=1420, + ) + + +def test_batch_create_sessions_rest_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.GetSessionRequest, + dict, +]) +def test_get_session_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner.Session( + name='name_value', + creator_role='creator_role_value', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner.Session.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.get_session(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.Session) + assert response.name == 'name_value' + assert response.creator_role == 'creator_role_value' + + +def test_get_session_rest_required_fields(request_type=spanner.GetSessionRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_session._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = 'name_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_session._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == 'name_value' + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner.Session() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner.Session.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.get_session(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_get_session_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.get_session._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_session_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "post_get_session") as post, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_get_session") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner.GetSessionRequest.pb(spanner.GetSessionRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner.Session.to_json(spanner.Session()) + + request = spanner.GetSessionRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner.Session() + + client.get_session(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_get_session_rest_bad_request(transport: str = 'rest', request_type=spanner.GetSessionRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.get_session(request) + + +def test_get_session_rest_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner.Session() + + # get arguments that satisfy an http rule for this method + sample_request = {'name': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + + # get truthy value for each flattened field + mock_args = dict( + name='name_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner.Session.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.get_session(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{name=projects/*/instances/*/databases/*/sessions/*}" % client.transport._host, args[1]) + + +def test_get_session_rest_flattened_error(transport: str = 'rest'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_session( + spanner.GetSessionRequest(), + name='name_value', + ) + + +def test_get_session_rest_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.ListSessionsRequest, + dict, +]) +def test_list_sessions_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner.ListSessionsResponse( + next_page_token='next_page_token_value', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner.ListSessionsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.list_sessions(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListSessionsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_sessions_rest_required_fields(request_type=spanner.ListSessionsRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["database"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_sessions._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["database"] = 'database_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_sessions._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("filter", "page_size", "page_token", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "database" in jsonified_request + assert jsonified_request["database"] == 'database_value' + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner.ListSessionsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner.ListSessionsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.list_sessions(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_list_sessions_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.list_sessions._get_unset_required_fields({}) + assert set(unset_fields) == (set(("filter", "pageSize", "pageToken", )) & set(("database", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_sessions_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "post_list_sessions") as post, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_list_sessions") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner.ListSessionsRequest.pb(spanner.ListSessionsRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner.ListSessionsResponse.to_json(spanner.ListSessionsResponse()) + + request = spanner.ListSessionsRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner.ListSessionsResponse() + + client.list_sessions(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_list_sessions_rest_bad_request(transport: str = 'rest', request_type=spanner.ListSessionsRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.list_sessions(request) + + +def test_list_sessions_rest_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner.ListSessionsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + + # get truthy value for each flattened field + mock_args = dict( + database='database_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner.ListSessionsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.list_sessions(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{database=projects/*/instances/*/databases/*}/sessions" % client.transport._host, args[1]) + + +def test_list_sessions_rest_flattened_error(transport: str = 'rest'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_sessions( + spanner.ListSessionsRequest(), + database='database_value', + ) + + +def test_list_sessions_rest_pager(transport: str = 'rest'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + #with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + spanner.Session(), + spanner.Session(), + ], + next_page_token='abc', + ), + spanner.ListSessionsResponse( + sessions=[], + next_page_token='def', + ), + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + ], + next_page_token='ghi', + ), + spanner.ListSessionsResponse( + sessions=[ + spanner.Session(), + spanner.Session(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(spanner.ListSessionsResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode('UTF-8') + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + + pager = client.list_sessions(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, spanner.Session) + for i in results) + + pages = list(client.list_sessions(request=sample_request).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize("request_type", [ + spanner.DeleteSessionRequest, + dict, +]) +def test_delete_session_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.delete_session(request) + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_session_rest_required_fields(request_type=spanner.DeleteSessionRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_session._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = 'name_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_session._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == 'name_value' + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = None + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "delete", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.delete_session(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_delete_session_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.delete_session._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_session_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_delete_session") as pre: + pre.assert_not_called() + pb_message = spanner.DeleteSessionRequest.pb(spanner.DeleteSessionRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + + request = spanner.DeleteSessionRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + + client.delete_session(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + + +def test_delete_session_rest_bad_request(transport: str = 'rest', request_type=spanner.DeleteSessionRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.delete_session(request) + + +def test_delete_session_rest_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # get arguments that satisfy an http rule for this method + sample_request = {'name': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + + # get truthy value for each flattened field + mock_args = dict( + name='name_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.delete_session(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{name=projects/*/instances/*/databases/*/sessions/*}" % client.transport._host, args[1]) + + +def test_delete_session_rest_flattened_error(transport: str = 'rest'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_session( + spanner.DeleteSessionRequest(), + name='name_value', + ) + + +def test_delete_session_rest_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.ExecuteSqlRequest, + dict, +]) +def test_execute_sql_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = result_set.ResultSet( + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = result_set.ResultSet.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.execute_sql(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, result_set.ResultSet) + + +def test_execute_sql_rest_required_fields(request_type=spanner.ExecuteSqlRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["session"] = "" + request_init["sql"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).execute_sql._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["session"] = 'session_value' + jsonified_request["sql"] = 'sql_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).execute_sql._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "session" in jsonified_request + assert jsonified_request["session"] == 'session_value' + assert "sql" in jsonified_request + assert jsonified_request["sql"] == 'sql_value' + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = result_set.ResultSet() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = result_set.ResultSet.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.execute_sql(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_execute_sql_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.execute_sql._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("session", "sql", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_execute_sql_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "post_execute_sql") as post, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_execute_sql") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner.ExecuteSqlRequest.pb(spanner.ExecuteSqlRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = result_set.ResultSet.to_json(result_set.ResultSet()) + + request = spanner.ExecuteSqlRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = result_set.ResultSet() + + client.execute_sql(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_execute_sql_rest_bad_request(transport: str = 'rest', request_type=spanner.ExecuteSqlRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.execute_sql(request) + + +def test_execute_sql_rest_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.ExecuteSqlRequest, + dict, +]) +def test_execute_streaming_sql_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = result_set.PartialResultSet( + chunked_value=True, + resume_token=b'resume_token_blob', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = result_set.PartialResultSet.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + json_return_value = "[{}]".format(json_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + with mock.patch.object(response_value, 'iter_content') as iter_content: + iter_content.return_value = iter(json_return_value) + response = client.execute_streaming_sql(request) + + assert isinstance(response, Iterable) + response = next(response) + + # Establish that the response is the type that we expect. + assert isinstance(response, result_set.PartialResultSet) + assert response.chunked_value is True + assert response.resume_token == b'resume_token_blob' + + +def test_execute_streaming_sql_rest_required_fields(request_type=spanner.ExecuteSqlRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["session"] = "" + request_init["sql"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).execute_streaming_sql._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["session"] = 'session_value' + jsonified_request["sql"] = 'sql_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).execute_streaming_sql._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "session" in jsonified_request + assert jsonified_request["session"] == 'session_value' + assert "sql" in jsonified_request + assert jsonified_request["sql"] == 'sql_value' + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = result_set.PartialResultSet() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = result_set.PartialResultSet.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + json_return_value = "[{}]".format(json_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + with mock.patch.object(response_value, 'iter_content') as iter_content: + iter_content.return_value = iter(json_return_value) + response = client.execute_streaming_sql(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_execute_streaming_sql_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.execute_streaming_sql._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("session", "sql", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_execute_streaming_sql_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "post_execute_streaming_sql") as post, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_execute_streaming_sql") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner.ExecuteSqlRequest.pb(spanner.ExecuteSqlRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = result_set.PartialResultSet.to_json(result_set.PartialResultSet()) + req.return_value._content = "[{}]".format(req.return_value._content) + + request = spanner.ExecuteSqlRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = result_set.PartialResultSet() + + client.execute_streaming_sql(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_execute_streaming_sql_rest_bad_request(transport: str = 'rest', request_type=spanner.ExecuteSqlRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.execute_streaming_sql(request) + + +def test_execute_streaming_sql_rest_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.ExecuteBatchDmlRequest, + dict, +]) +def test_execute_batch_dml_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner.ExecuteBatchDmlResponse( + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner.ExecuteBatchDmlResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.execute_batch_dml(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.ExecuteBatchDmlResponse) + + +def test_execute_batch_dml_rest_required_fields(request_type=spanner.ExecuteBatchDmlRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["session"] = "" + request_init["seqno"] = 0 + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).execute_batch_dml._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["session"] = 'session_value' + jsonified_request["seqno"] = 550 + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).execute_batch_dml._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "session" in jsonified_request + assert jsonified_request["session"] == 'session_value' + assert "seqno" in jsonified_request + assert jsonified_request["seqno"] == 550 + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner.ExecuteBatchDmlResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner.ExecuteBatchDmlResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.execute_batch_dml(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_execute_batch_dml_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.execute_batch_dml._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("session", "transaction", "statements", "seqno", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_execute_batch_dml_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "post_execute_batch_dml") as post, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_execute_batch_dml") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner.ExecuteBatchDmlRequest.pb(spanner.ExecuteBatchDmlRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner.ExecuteBatchDmlResponse.to_json(spanner.ExecuteBatchDmlResponse()) + + request = spanner.ExecuteBatchDmlRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner.ExecuteBatchDmlResponse() + + client.execute_batch_dml(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_execute_batch_dml_rest_bad_request(transport: str = 'rest', request_type=spanner.ExecuteBatchDmlRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.execute_batch_dml(request) + + +def test_execute_batch_dml_rest_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.ReadRequest, + dict, +]) +def test_read_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = result_set.ResultSet( + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = result_set.ResultSet.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.read(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, result_set.ResultSet) + + +def test_read_rest_required_fields(request_type=spanner.ReadRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["session"] = "" + request_init["table"] = "" + request_init["columns"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).read._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["session"] = 'session_value' + jsonified_request["table"] = 'table_value' + jsonified_request["columns"] = 'columns_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).read._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "session" in jsonified_request + assert jsonified_request["session"] == 'session_value' + assert "table" in jsonified_request + assert jsonified_request["table"] == 'table_value' + assert "columns" in jsonified_request + assert jsonified_request["columns"] == 'columns_value' + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = result_set.ResultSet() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = result_set.ResultSet.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.read(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_read_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.read._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("session", "table", "columns", "keySet", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_read_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "post_read") as post, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_read") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner.ReadRequest.pb(spanner.ReadRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = result_set.ResultSet.to_json(result_set.ResultSet()) + + request = spanner.ReadRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = result_set.ResultSet() + + client.read(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_read_rest_bad_request(transport: str = 'rest', request_type=spanner.ReadRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.read(request) + + +def test_read_rest_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.ReadRequest, + dict, +]) +def test_streaming_read_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = result_set.PartialResultSet( + chunked_value=True, + resume_token=b'resume_token_blob', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = result_set.PartialResultSet.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + json_return_value = "[{}]".format(json_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + with mock.patch.object(response_value, 'iter_content') as iter_content: + iter_content.return_value = iter(json_return_value) + response = client.streaming_read(request) + + assert isinstance(response, Iterable) + response = next(response) + + # Establish that the response is the type that we expect. + assert isinstance(response, result_set.PartialResultSet) + assert response.chunked_value is True + assert response.resume_token == b'resume_token_blob' + + +def test_streaming_read_rest_required_fields(request_type=spanner.ReadRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["session"] = "" + request_init["table"] = "" + request_init["columns"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).streaming_read._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["session"] = 'session_value' + jsonified_request["table"] = 'table_value' + jsonified_request["columns"] = 'columns_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).streaming_read._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "session" in jsonified_request + assert jsonified_request["session"] == 'session_value' + assert "table" in jsonified_request + assert jsonified_request["table"] == 'table_value' + assert "columns" in jsonified_request + assert jsonified_request["columns"] == 'columns_value' + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = result_set.PartialResultSet() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = result_set.PartialResultSet.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + json_return_value = "[{}]".format(json_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + with mock.patch.object(response_value, 'iter_content') as iter_content: + iter_content.return_value = iter(json_return_value) + response = client.streaming_read(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_streaming_read_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.streaming_read._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("session", "table", "columns", "keySet", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_streaming_read_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "post_streaming_read") as post, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_streaming_read") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner.ReadRequest.pb(spanner.ReadRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = result_set.PartialResultSet.to_json(result_set.PartialResultSet()) + req.return_value._content = "[{}]".format(req.return_value._content) + + request = spanner.ReadRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = result_set.PartialResultSet() + + client.streaming_read(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_streaming_read_rest_bad_request(transport: str = 'rest', request_type=spanner.ReadRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.streaming_read(request) + + +def test_streaming_read_rest_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.BeginTransactionRequest, + dict, +]) +def test_begin_transaction_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = transaction.Transaction( + id=b'id_blob', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = transaction.Transaction.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.begin_transaction(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, transaction.Transaction) + assert response.id == b'id_blob' + + +def test_begin_transaction_rest_required_fields(request_type=spanner.BeginTransactionRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["session"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).begin_transaction._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["session"] = 'session_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).begin_transaction._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "session" in jsonified_request + assert jsonified_request["session"] == 'session_value' + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = transaction.Transaction() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = transaction.Transaction.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.begin_transaction(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_begin_transaction_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.begin_transaction._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("session", "options", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_begin_transaction_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "post_begin_transaction") as post, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_begin_transaction") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner.BeginTransactionRequest.pb(spanner.BeginTransactionRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = transaction.Transaction.to_json(transaction.Transaction()) + + request = spanner.BeginTransactionRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = transaction.Transaction() + + client.begin_transaction(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_begin_transaction_rest_bad_request(transport: str = 'rest', request_type=spanner.BeginTransactionRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.begin_transaction(request) + + +def test_begin_transaction_rest_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = transaction.Transaction() + + # get arguments that satisfy an http rule for this method + sample_request = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + + # get truthy value for each flattened field + mock_args = dict( + session='session_value', + options=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = transaction.Transaction.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.begin_transaction(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{session=projects/*/instances/*/databases/*/sessions/*}:beginTransaction" % client.transport._host, args[1]) + + +def test_begin_transaction_rest_flattened_error(transport: str = 'rest'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.begin_transaction( + spanner.BeginTransactionRequest(), + session='session_value', + options=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), + ) + + +def test_begin_transaction_rest_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.CommitRequest, + dict, +]) +def test_commit_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = commit_response.CommitResponse( + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = commit_response.CommitResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.commit(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, commit_response.CommitResponse) + + +def test_commit_rest_required_fields(request_type=spanner.CommitRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["session"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).commit._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["session"] = 'session_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).commit._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "session" in jsonified_request + assert jsonified_request["session"] == 'session_value' + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = commit_response.CommitResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = commit_response.CommitResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.commit(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_commit_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.commit._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("session", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_commit_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "post_commit") as post, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_commit") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner.CommitRequest.pb(spanner.CommitRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = commit_response.CommitResponse.to_json(commit_response.CommitResponse()) + + request = spanner.CommitRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = commit_response.CommitResponse() + + client.commit(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_commit_rest_bad_request(transport: str = 'rest', request_type=spanner.CommitRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.commit(request) + + +def test_commit_rest_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = commit_response.CommitResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + + # get truthy value for each flattened field + mock_args = dict( + session='session_value', + mutations=[mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))], + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = commit_response.CommitResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.commit(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{session=projects/*/instances/*/databases/*/sessions/*}:commit" % client.transport._host, args[1]) + + +def test_commit_rest_flattened_error(transport: str = 'rest'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.commit( + spanner.CommitRequest(), + session='session_value', + transaction_id=b'transaction_id_blob', + mutations=[mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))], + single_use_transaction=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), + ) + + +def test_commit_rest_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.RollbackRequest, + dict, +]) +def test_rollback_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.rollback(request) + + # Establish that the response is the type that we expect. + assert response is None + + +def test_rollback_rest_required_fields(request_type=spanner.RollbackRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["session"] = "" + request_init["transaction_id"] = b'' + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).rollback._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["session"] = 'session_value' + jsonified_request["transactionId"] = b'transaction_id_blob' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).rollback._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "session" in jsonified_request + assert jsonified_request["session"] == 'session_value' + assert "transactionId" in jsonified_request + assert jsonified_request["transactionId"] == b'transaction_id_blob' + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = None + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.rollback(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_rollback_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.rollback._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("session", "transactionId", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_rollback_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_rollback") as pre: + pre.assert_not_called() + pb_message = spanner.RollbackRequest.pb(spanner.RollbackRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + + request = spanner.RollbackRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + + client.rollback(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + + +def test_rollback_rest_bad_request(transport: str = 'rest', request_type=spanner.RollbackRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.rollback(request) + + +def test_rollback_rest_flattened(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # get arguments that satisfy an http rule for this method + sample_request = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + + # get truthy value for each flattened field + mock_args = dict( + session='session_value', + transaction_id=b'transaction_id_blob', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.rollback(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{session=projects/*/instances/*/databases/*/sessions/*}:rollback" % client.transport._host, args[1]) + + +def test_rollback_rest_flattened_error(transport: str = 'rest'): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.rollback( + spanner.RollbackRequest(), + session='session_value', + transaction_id=b'transaction_id_blob', + ) + + +def test_rollback_rest_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.PartitionQueryRequest, + dict, +]) +def test_partition_query_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner.PartitionResponse( + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner.PartitionResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.partition_query(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.PartitionResponse) + + +def test_partition_query_rest_required_fields(request_type=spanner.PartitionQueryRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["session"] = "" + request_init["sql"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).partition_query._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["session"] = 'session_value' + jsonified_request["sql"] = 'sql_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).partition_query._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "session" in jsonified_request + assert jsonified_request["session"] == 'session_value' + assert "sql" in jsonified_request + assert jsonified_request["sql"] == 'sql_value' + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner.PartitionResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner.PartitionResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.partition_query(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_partition_query_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.partition_query._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("session", "sql", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_partition_query_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "post_partition_query") as post, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_partition_query") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner.PartitionQueryRequest.pb(spanner.PartitionQueryRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner.PartitionResponse.to_json(spanner.PartitionResponse()) + + request = spanner.PartitionQueryRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner.PartitionResponse() + + client.partition_query(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_partition_query_rest_bad_request(transport: str = 'rest', request_type=spanner.PartitionQueryRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.partition_query(request) + + +def test_partition_query_rest_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner.PartitionReadRequest, + dict, +]) +def test_partition_read_rest(request_type): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner.PartitionResponse( + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner.PartitionResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.partition_read(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner.PartitionResponse) + + +def test_partition_read_rest_required_fields(request_type=spanner.PartitionReadRequest): + transport_class = transports.SpannerRestTransport + + request_init = {} + request_init["session"] = "" + request_init["table"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).partition_read._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["session"] = 'session_value' + jsonified_request["table"] = 'table_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).partition_read._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "session" in jsonified_request + assert jsonified_request["session"] == 'session_value' + assert "table" in jsonified_request + assert jsonified_request["table"] == 'table_value' + + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner.PartitionResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner.PartitionResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.partition_read(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_partition_read_rest_unset_required_fields(): + transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.partition_read._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("session", "table", "keySet", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_partition_read_rest_interceptors(null_interceptor): + transport = transports.SpannerRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), + ) + client = SpannerClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.SpannerRestInterceptor, "post_partition_read") as post, \ + mock.patch.object(transports.SpannerRestInterceptor, "pre_partition_read") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner.PartitionReadRequest.pb(spanner.PartitionReadRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner.PartitionResponse.to_json(spanner.PartitionResponse()) + + request = spanner.PartitionReadRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner.PartitionResponse() + + client.partition_read(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_partition_read_rest_bad_request(transport: str = 'rest', request_type=spanner.PartitionReadRequest): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.partition_read(request) + + +def test_partition_read_rest_error(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.SpannerGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.SpannerGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = SpannerClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.SpannerGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = SpannerClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = SpannerClient( + client_options=options, + credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.SpannerGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = SpannerClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.SpannerGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = SpannerClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.SpannerGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.SpannerGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.SpannerGrpcTransport, + transports.SpannerGrpcAsyncIOTransport, + transports.SpannerRestTransport, +]) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "rest", +]) +def test_transport_kind(transport_name): + transport = SpannerClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.SpannerGrpcTransport, + ) + +def test_spanner_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.SpannerTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_spanner_base_transport(): + # Instantiate the base transport. + with mock.patch('google.cloud.spanner_v1.services.spanner.transports.SpannerTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.SpannerTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'create_session', + 'batch_create_sessions', + 'get_session', + 'list_sessions', + 'delete_session', + 'execute_sql', + 'execute_streaming_sql', + 'execute_batch_dml', + 'read', + 'streaming_read', + 'begin_transaction', + 'commit', + 'rollback', + 'partition_query', + 'partition_read', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Catch all for all remaining methods and properties + remainder = [ + 'kind', + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_spanner_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.spanner_v1.services.spanner.transports.SpannerTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.SpannerTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.data', +), + quota_project_id="octopus", + ) + + +def test_spanner_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.cloud.spanner_v1.services.spanner.transports.SpannerTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.SpannerTransport() + adc.assert_called_once() + + +def test_spanner_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + SpannerClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.data', +), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.SpannerGrpcTransport, + transports.SpannerGrpcAsyncIOTransport, + ], +) +def test_spanner_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/spanner.data',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.SpannerGrpcTransport, + transports.SpannerGrpcAsyncIOTransport, + transports.SpannerRestTransport, + ], +) +def test_spanner_transport_auth_gdch_credentials(transport_class): + host = 'https://language.com' + api_audience_tests = [None, 'https://language2.com'] + api_audience_expect = [host, 'https://language2.com'] + for t, e in zip(api_audience_tests, api_audience_expect): + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + gdch_mock = mock.MagicMock() + type(gdch_mock).with_gdch_audience = mock.PropertyMock(return_value=gdch_mock) + adc.return_value = (gdch_mock, None) + transport_class(host=host, api_audience=t) + gdch_mock.with_gdch_audience.assert_called_once_with( + e + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.SpannerGrpcTransport, grpc_helpers), + (transports.SpannerGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_spanner_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class( + quota_project_id="octopus", + scopes=["1", "2"] + ) + + create_channel.assert_called_with( + "spanner.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.data', +), + scopes=["1", "2"], + default_host="spanner.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.SpannerGrpcTransport, transports.SpannerGrpcAsyncIOTransport]) +def test_spanner_grpc_transport_client_cert_source_for_mtls( + transport_class +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, + private_key=expected_key + ) + +def test_spanner_http_transport_client_cert_source_for_mtls(): + cred = ga_credentials.AnonymousCredentials() + with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel") as mock_configure_mtls_channel: + transports.SpannerRestTransport ( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) + + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", + "rest", +]) +def test_spanner_host_no_port(transport_name): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='spanner.googleapis.com'), + transport=transport_name, + ) + assert client.transport._host == ( + 'spanner.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://spanner.googleapis.com' + ) + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", + "rest", +]) +def test_spanner_host_with_port(transport_name): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='spanner.googleapis.com:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + 'spanner.googleapis.com:8000' + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://spanner.googleapis.com:8000' + ) + +@pytest.mark.parametrize("transport_name", [ + "rest", +]) +def test_spanner_client_transport_session_collision(transport_name): + creds1 = ga_credentials.AnonymousCredentials() + creds2 = ga_credentials.AnonymousCredentials() + client1 = SpannerClient( + credentials=creds1, + transport=transport_name, + ) + client2 = SpannerClient( + credentials=creds2, + transport=transport_name, + ) + session1 = client1.transport.create_session._session + session2 = client2.transport.create_session._session + assert session1 != session2 + session1 = client1.transport.batch_create_sessions._session + session2 = client2.transport.batch_create_sessions._session + assert session1 != session2 + session1 = client1.transport.get_session._session + session2 = client2.transport.get_session._session + assert session1 != session2 + session1 = client1.transport.list_sessions._session + session2 = client2.transport.list_sessions._session + assert session1 != session2 + session1 = client1.transport.delete_session._session + session2 = client2.transport.delete_session._session + assert session1 != session2 + session1 = client1.transport.execute_sql._session + session2 = client2.transport.execute_sql._session + assert session1 != session2 + session1 = client1.transport.execute_streaming_sql._session + session2 = client2.transport.execute_streaming_sql._session + assert session1 != session2 + session1 = client1.transport.execute_batch_dml._session + session2 = client2.transport.execute_batch_dml._session + assert session1 != session2 + session1 = client1.transport.read._session + session2 = client2.transport.read._session + assert session1 != session2 + session1 = client1.transport.streaming_read._session + session2 = client2.transport.streaming_read._session + assert session1 != session2 + session1 = client1.transport.begin_transaction._session + session2 = client2.transport.begin_transaction._session + assert session1 != session2 + session1 = client1.transport.commit._session + session2 = client2.transport.commit._session + assert session1 != session2 + session1 = client1.transport.rollback._session + session2 = client2.transport.rollback._session + assert session1 != session2 + session1 = client1.transport.partition_query._session + session2 = client2.transport.partition_query._session + assert session1 != session2 + session1 = client1.transport.partition_read._session + session2 = client2.transport.partition_read._session + assert session1 != session2 +def test_spanner_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.SpannerGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_spanner_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.SpannerGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.SpannerGrpcTransport, transports.SpannerGrpcAsyncIOTransport]) +def test_spanner_transport_channel_mtls_with_client_cert_source( + transport_class +): + with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.SpannerGrpcTransport, transports.SpannerGrpcAsyncIOTransport]) +def test_spanner_transport_channel_mtls_with_adc( + transport_class +): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_database_path(): + project = "squid" + instance = "clam" + database = "whelk" + expected = "projects/{project}/instances/{instance}/databases/{database}".format(project=project, instance=instance, database=database, ) + actual = SpannerClient.database_path(project, instance, database) + assert expected == actual + + +def test_parse_database_path(): + expected = { + "project": "octopus", + "instance": "oyster", + "database": "nudibranch", + } + path = SpannerClient.database_path(**expected) + + # Check that the path construction is reversible. + actual = SpannerClient.parse_database_path(path) + assert expected == actual + +def test_session_path(): + project = "cuttlefish" + instance = "mussel" + database = "winkle" + session = "nautilus" + expected = "projects/{project}/instances/{instance}/databases/{database}/sessions/{session}".format(project=project, instance=instance, database=database, session=session, ) + actual = SpannerClient.session_path(project, instance, database, session) + assert expected == actual + + +def test_parse_session_path(): + expected = { + "project": "scallop", + "instance": "abalone", + "database": "squid", + "session": "clam", + } + path = SpannerClient.session_path(**expected) + + # Check that the path construction is reversible. + actual = SpannerClient.parse_session_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "whelk" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = SpannerClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "octopus", + } + path = SpannerClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = SpannerClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "oyster" + expected = "folders/{folder}".format(folder=folder, ) + actual = SpannerClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "nudibranch", + } + path = SpannerClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = SpannerClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "cuttlefish" + expected = "organizations/{organization}".format(organization=organization, ) + actual = SpannerClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "mussel", + } + path = SpannerClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = SpannerClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "winkle" + expected = "projects/{project}".format(project=project, ) + actual = SpannerClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "nautilus", + } + path = SpannerClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = SpannerClient.parse_common_project_path(path) + assert expected == actual + +def test_common_location_path(): + project = "scallop" + location = "abalone" + expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + actual = SpannerClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "squid", + "location": "clam", + } + path = SpannerClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = SpannerClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object(transports.SpannerTransport, '_prep_wrapped_messages') as prep: + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.SpannerTransport, '_prep_wrapped_messages') as prep: + transport_class = SpannerClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = SpannerAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "rest": "_session", + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + +def test_client_ctx(): + transports = [ + 'rest', + 'grpc', + ] + for transport in transports: + client = SpannerClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + +@pytest.mark.parametrize("client_class,transport_class", [ + (SpannerClient, transports.SpannerGrpcTransport), + (SpannerAsyncClient, transports.SpannerGrpcAsyncIOTransport), +]) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) diff --git a/owl-bot-staging/spanner_admin_database/v1/.coveragerc b/owl-bot-staging/spanner_admin_database/v1/.coveragerc new file mode 100644 index 0000000000..6085d54da4 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/.coveragerc @@ -0,0 +1,13 @@ +[run] +branch = True + +[report] +show_missing = True +omit = + google/cloud/spanner_admin_database/__init__.py + google/cloud/spanner_admin_database/gapic_version.py +exclude_lines = + # Re-enable the standard pragma + pragma: NO COVER + # Ignore debug-only repr + def __repr__ diff --git a/owl-bot-staging/spanner_admin_database/v1/.flake8 b/owl-bot-staging/spanner_admin_database/v1/.flake8 new file mode 100644 index 0000000000..29227d4cf4 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/.flake8 @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Generated by synthtool. DO NOT EDIT! +[flake8] +ignore = E203, E266, E501, W503 +exclude = + # Exclude generated code. + **/proto/** + **/gapic/** + **/services/** + **/types/** + *_pb2.py + + # Standard linting exemptions. + **/.nox/** + __pycache__, + .git, + *.pyc, + conf.py diff --git a/owl-bot-staging/spanner_admin_database/v1/MANIFEST.in b/owl-bot-staging/spanner_admin_database/v1/MANIFEST.in new file mode 100644 index 0000000000..550e337e01 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include google/cloud/spanner_admin_database *.py +recursive-include google/cloud/spanner_admin_database_v1 *.py diff --git a/owl-bot-staging/spanner_admin_database/v1/README.rst b/owl-bot-staging/spanner_admin_database/v1/README.rst new file mode 100644 index 0000000000..12e0ba69de --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/README.rst @@ -0,0 +1,49 @@ +Python Client for Google Cloud Spanner Admin Database API +================================================= + +Quick Start +----------- + +In order to use this library, you first need to go through the following steps: + +1. `Select or create a Cloud Platform project.`_ +2. `Enable billing for your project.`_ +3. Enable the Google Cloud Spanner Admin Database API. +4. `Setup Authentication.`_ + +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project +.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html + +Installation +~~~~~~~~~~~~ + +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to +create isolated Python environments. The basic problem it addresses is one of +dependencies and versions, and indirectly permissions. + +With `virtualenv`_, it's possible to install this library without needing system +install permissions, and without clashing with the installed system +dependencies. + +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ + + +Mac/Linux +^^^^^^^^^ + +.. code-block:: console + + python3 -m venv + source /bin/activate + /bin/pip install /path/to/library + + +Windows +^^^^^^^ + +.. code-block:: console + + python3 -m venv + \Scripts\activate + \Scripts\pip.exe install \path\to\library diff --git a/owl-bot-staging/spanner_admin_database/v1/docs/conf.py b/owl-bot-staging/spanner_admin_database/v1/docs/conf.py new file mode 100644 index 0000000000..16ce340ec0 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/docs/conf.py @@ -0,0 +1,376 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# google-cloud-spanner-admin-database documentation build configuration file +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os +import shlex + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath("..")) + +__version__ = "0.1.0" + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +needs_sphinx = "4.0.1" + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.intersphinx", + "sphinx.ext.coverage", + "sphinx.ext.napoleon", + "sphinx.ext.todo", + "sphinx.ext.viewcode", +] + +# autodoc/autosummary flags +autoclass_content = "both" +autodoc_default_flags = ["members"] +autosummary_generate = True + + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# Allow markdown includes (so releases.md can include CHANGLEOG.md) +# http://www.sphinx-doc.org/en/master/markdown.html +source_parsers = {".md": "recommonmark.parser.CommonMarkParser"} + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +source_suffix = [".rst", ".md"] + +# The encoding of source files. +# source_encoding = 'utf-8-sig' + +# The root toctree document. +root_doc = "index" + +# General information about the project. +project = u"google-cloud-spanner-admin-database" +copyright = u"2022, Google, LLC" +author = u"Google APIs" # TODO: autogenerate this bit + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The full version, including alpha/beta/rc tags. +release = __version__ +# The short X.Y version. +version = ".".join(release.split(".")[0:2]) + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# today = '' +# Else, today_fmt is used as the format for a strftime call. +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ["_build"] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = "sphinx" + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = "alabaster" + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +html_theme_options = { + "description": "Google Cloud Client Libraries for Python", + "github_user": "googleapis", + "github_repo": "google-cloud-python", + "github_banner": True, + "font_family": "'Roboto', Georgia, sans", + "head_font_family": "'Roboto', Georgia, serif", + "code_font_family": "'Roboto Mono', 'Consolas', monospace", +} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +# html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +# html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +# html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# html_additional_pages = {} + +# If false, no module index is generated. +# html_domain_indices = True + +# If false, no index is generated. +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' +# html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# Now only 'ja' uses this config value +# html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +# html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = "google-cloud-spanner-admin-database-doc" + +# -- Options for warnings ------------------------------------------------------ + + +suppress_warnings = [ + # Temporarily suppress this to avoid "more than one target found for + # cross-reference" warning, which are intractable for us to avoid while in + # a mono-repo. + # See https://github.com/sphinx-doc/sphinx/blob + # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 + "ref.python" +] + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # 'preamble': '', + # Latex figure (float) alignment + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ( + root_doc, + "google-cloud-spanner-admin-database.tex", + u"google-cloud-spanner-admin-database Documentation", + author, + "manual", + ) +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# latex_use_parts = False + +# If true, show page references after internal links. +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# latex_appendices = [] + +# If false, no module index is generated. +# latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ( + root_doc, + "google-cloud-spanner-admin-database", + u"Google Cloud Spanner Admin Database Documentation", + [author], + 1, + ) +] + +# If true, show URL addresses after external links. +# man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ( + root_doc, + "google-cloud-spanner-admin-database", + u"google-cloud-spanner-admin-database Documentation", + author, + "google-cloud-spanner-admin-database", + "GAPIC library for Google Cloud Spanner Admin Database API", + "APIs", + ) +] + +# Documents to append as an appendix to all manuals. +# texinfo_appendices = [] + +# If false, no module index is generated. +# texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +# texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +# texinfo_no_detailmenu = False + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = { + "python": ("http://python.readthedocs.org/en/latest/", None), + "gax": ("https://gax-python.readthedocs.org/en/latest/", None), + "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), + "google-gax": ("https://gax-python.readthedocs.io/en/latest/", None), + "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None), + "grpc": ("https://grpc.io/grpc/python/", None), + "requests": ("http://requests.kennethreitz.org/en/stable/", None), + "proto": ("https://proto-plus-python.readthedocs.io/en/stable", None), + "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), +} + + +# Napoleon settings +napoleon_google_docstring = True +napoleon_numpy_docstring = True +napoleon_include_private_with_doc = False +napoleon_include_special_with_doc = True +napoleon_use_admonition_for_examples = False +napoleon_use_admonition_for_notes = False +napoleon_use_admonition_for_references = False +napoleon_use_ivar = False +napoleon_use_param = True +napoleon_use_rtype = True diff --git a/owl-bot-staging/spanner_admin_database/v1/docs/index.rst b/owl-bot-staging/spanner_admin_database/v1/docs/index.rst new file mode 100644 index 0000000000..e2947e7442 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/docs/index.rst @@ -0,0 +1,7 @@ +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + spanner_admin_database_v1/services + spanner_admin_database_v1/types diff --git a/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/database_admin.rst b/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/database_admin.rst new file mode 100644 index 0000000000..bd6aab00e4 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/database_admin.rst @@ -0,0 +1,10 @@ +DatabaseAdmin +------------------------------- + +.. automodule:: google.cloud.spanner_admin_database_v1.services.database_admin + :members: + :inherited-members: + +.. automodule:: google.cloud.spanner_admin_database_v1.services.database_admin.pagers + :members: + :inherited-members: diff --git a/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/services.rst b/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/services.rst new file mode 100644 index 0000000000..55e57d8dc0 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/services.rst @@ -0,0 +1,6 @@ +Services for Google Cloud Spanner Admin Database v1 API +======================================================= +.. toctree:: + :maxdepth: 2 + + database_admin diff --git a/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/types.rst b/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/types.rst new file mode 100644 index 0000000000..fe6c27778b --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/types.rst @@ -0,0 +1,6 @@ +Types for Google Cloud Spanner Admin Database v1 API +==================================================== + +.. automodule:: google.cloud.spanner_admin_database_v1.types + :members: + :show-inheritance: diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/__init__.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/__init__.py new file mode 100644 index 0000000000..4333b2d92f --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/__init__.py @@ -0,0 +1,113 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from google.cloud.spanner_admin_database import gapic_version as package_version + +__version__ = package_version.__version__ + + +from google.cloud.spanner_admin_database_v1.services.database_admin.client import DatabaseAdminClient +from google.cloud.spanner_admin_database_v1.services.database_admin.async_client import DatabaseAdminAsyncClient + +from google.cloud.spanner_admin_database_v1.types.backup import Backup +from google.cloud.spanner_admin_database_v1.types.backup import BackupInfo +from google.cloud.spanner_admin_database_v1.types.backup import CopyBackupEncryptionConfig +from google.cloud.spanner_admin_database_v1.types.backup import CopyBackupMetadata +from google.cloud.spanner_admin_database_v1.types.backup import CopyBackupRequest +from google.cloud.spanner_admin_database_v1.types.backup import CreateBackupEncryptionConfig +from google.cloud.spanner_admin_database_v1.types.backup import CreateBackupMetadata +from google.cloud.spanner_admin_database_v1.types.backup import CreateBackupRequest +from google.cloud.spanner_admin_database_v1.types.backup import DeleteBackupRequest +from google.cloud.spanner_admin_database_v1.types.backup import GetBackupRequest +from google.cloud.spanner_admin_database_v1.types.backup import ListBackupOperationsRequest +from google.cloud.spanner_admin_database_v1.types.backup import ListBackupOperationsResponse +from google.cloud.spanner_admin_database_v1.types.backup import ListBackupsRequest +from google.cloud.spanner_admin_database_v1.types.backup import ListBackupsResponse +from google.cloud.spanner_admin_database_v1.types.backup import UpdateBackupRequest +from google.cloud.spanner_admin_database_v1.types.common import EncryptionConfig +from google.cloud.spanner_admin_database_v1.types.common import EncryptionInfo +from google.cloud.spanner_admin_database_v1.types.common import OperationProgress +from google.cloud.spanner_admin_database_v1.types.common import DatabaseDialect +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import CreateDatabaseMetadata +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import CreateDatabaseRequest +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import Database +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import DatabaseRole +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import DropDatabaseRequest +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import GetDatabaseDdlRequest +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import GetDatabaseDdlResponse +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import GetDatabaseRequest +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import ListDatabaseOperationsRequest +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import ListDatabaseOperationsResponse +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import ListDatabaseRolesRequest +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import ListDatabaseRolesResponse +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import ListDatabasesRequest +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import ListDatabasesResponse +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import OptimizeRestoredDatabaseMetadata +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import RestoreDatabaseEncryptionConfig +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import RestoreDatabaseMetadata +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import RestoreDatabaseRequest +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import RestoreInfo +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import UpdateDatabaseDdlMetadata +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import UpdateDatabaseDdlRequest +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import UpdateDatabaseMetadata +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import UpdateDatabaseRequest +from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import RestoreSourceType + +__all__ = ('DatabaseAdminClient', + 'DatabaseAdminAsyncClient', + 'Backup', + 'BackupInfo', + 'CopyBackupEncryptionConfig', + 'CopyBackupMetadata', + 'CopyBackupRequest', + 'CreateBackupEncryptionConfig', + 'CreateBackupMetadata', + 'CreateBackupRequest', + 'DeleteBackupRequest', + 'GetBackupRequest', + 'ListBackupOperationsRequest', + 'ListBackupOperationsResponse', + 'ListBackupsRequest', + 'ListBackupsResponse', + 'UpdateBackupRequest', + 'EncryptionConfig', + 'EncryptionInfo', + 'OperationProgress', + 'DatabaseDialect', + 'CreateDatabaseMetadata', + 'CreateDatabaseRequest', + 'Database', + 'DatabaseRole', + 'DropDatabaseRequest', + 'GetDatabaseDdlRequest', + 'GetDatabaseDdlResponse', + 'GetDatabaseRequest', + 'ListDatabaseOperationsRequest', + 'ListDatabaseOperationsResponse', + 'ListDatabaseRolesRequest', + 'ListDatabaseRolesResponse', + 'ListDatabasesRequest', + 'ListDatabasesResponse', + 'OptimizeRestoredDatabaseMetadata', + 'RestoreDatabaseEncryptionConfig', + 'RestoreDatabaseMetadata', + 'RestoreDatabaseRequest', + 'RestoreInfo', + 'UpdateDatabaseDdlMetadata', + 'UpdateDatabaseDdlRequest', + 'UpdateDatabaseMetadata', + 'UpdateDatabaseRequest', + 'RestoreSourceType', +) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/gapic_version.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/gapic_version.py new file mode 100644 index 0000000000..405b1cebcf --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +__version__ = "0.1.0" # {x-release-please-version} diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/py.typed b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/py.typed new file mode 100644 index 0000000000..29f334aad6 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-spanner-admin-database package uses inline types. diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/__init__.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/__init__.py new file mode 100644 index 0000000000..4b9db19432 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/__init__.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from google.cloud.spanner_admin_database_v1 import gapic_version as package_version + +__version__ = package_version.__version__ + + +from .services.database_admin import DatabaseAdminClient +from .services.database_admin import DatabaseAdminAsyncClient + +from .types.backup import Backup +from .types.backup import BackupInfo +from .types.backup import CopyBackupEncryptionConfig +from .types.backup import CopyBackupMetadata +from .types.backup import CopyBackupRequest +from .types.backup import CreateBackupEncryptionConfig +from .types.backup import CreateBackupMetadata +from .types.backup import CreateBackupRequest +from .types.backup import DeleteBackupRequest +from .types.backup import GetBackupRequest +from .types.backup import ListBackupOperationsRequest +from .types.backup import ListBackupOperationsResponse +from .types.backup import ListBackupsRequest +from .types.backup import ListBackupsResponse +from .types.backup import UpdateBackupRequest +from .types.common import EncryptionConfig +from .types.common import EncryptionInfo +from .types.common import OperationProgress +from .types.common import DatabaseDialect +from .types.spanner_database_admin import CreateDatabaseMetadata +from .types.spanner_database_admin import CreateDatabaseRequest +from .types.spanner_database_admin import Database +from .types.spanner_database_admin import DatabaseRole +from .types.spanner_database_admin import DropDatabaseRequest +from .types.spanner_database_admin import GetDatabaseDdlRequest +from .types.spanner_database_admin import GetDatabaseDdlResponse +from .types.spanner_database_admin import GetDatabaseRequest +from .types.spanner_database_admin import ListDatabaseOperationsRequest +from .types.spanner_database_admin import ListDatabaseOperationsResponse +from .types.spanner_database_admin import ListDatabaseRolesRequest +from .types.spanner_database_admin import ListDatabaseRolesResponse +from .types.spanner_database_admin import ListDatabasesRequest +from .types.spanner_database_admin import ListDatabasesResponse +from .types.spanner_database_admin import OptimizeRestoredDatabaseMetadata +from .types.spanner_database_admin import RestoreDatabaseEncryptionConfig +from .types.spanner_database_admin import RestoreDatabaseMetadata +from .types.spanner_database_admin import RestoreDatabaseRequest +from .types.spanner_database_admin import RestoreInfo +from .types.spanner_database_admin import UpdateDatabaseDdlMetadata +from .types.spanner_database_admin import UpdateDatabaseDdlRequest +from .types.spanner_database_admin import UpdateDatabaseMetadata +from .types.spanner_database_admin import UpdateDatabaseRequest +from .types.spanner_database_admin import RestoreSourceType + +__all__ = ( + 'DatabaseAdminAsyncClient', +'Backup', +'BackupInfo', +'CopyBackupEncryptionConfig', +'CopyBackupMetadata', +'CopyBackupRequest', +'CreateBackupEncryptionConfig', +'CreateBackupMetadata', +'CreateBackupRequest', +'CreateDatabaseMetadata', +'CreateDatabaseRequest', +'Database', +'DatabaseAdminClient', +'DatabaseDialect', +'DatabaseRole', +'DeleteBackupRequest', +'DropDatabaseRequest', +'EncryptionConfig', +'EncryptionInfo', +'GetBackupRequest', +'GetDatabaseDdlRequest', +'GetDatabaseDdlResponse', +'GetDatabaseRequest', +'ListBackupOperationsRequest', +'ListBackupOperationsResponse', +'ListBackupsRequest', +'ListBackupsResponse', +'ListDatabaseOperationsRequest', +'ListDatabaseOperationsResponse', +'ListDatabaseRolesRequest', +'ListDatabaseRolesResponse', +'ListDatabasesRequest', +'ListDatabasesResponse', +'OperationProgress', +'OptimizeRestoredDatabaseMetadata', +'RestoreDatabaseEncryptionConfig', +'RestoreDatabaseMetadata', +'RestoreDatabaseRequest', +'RestoreInfo', +'RestoreSourceType', +'UpdateBackupRequest', +'UpdateDatabaseDdlMetadata', +'UpdateDatabaseDdlRequest', +'UpdateDatabaseMetadata', +'UpdateDatabaseRequest', +) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_metadata.json b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_metadata.json new file mode 100644 index 0000000000..b0fb4f1384 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_metadata.json @@ -0,0 +1,328 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.spanner_admin_database_v1", + "protoPackage": "google.spanner.admin.database.v1", + "schema": "1.0", + "services": { + "DatabaseAdmin": { + "clients": { + "grpc": { + "libraryClient": "DatabaseAdminClient", + "rpcs": { + "CopyBackup": { + "methods": [ + "copy_backup" + ] + }, + "CreateBackup": { + "methods": [ + "create_backup" + ] + }, + "CreateDatabase": { + "methods": [ + "create_database" + ] + }, + "DeleteBackup": { + "methods": [ + "delete_backup" + ] + }, + "DropDatabase": { + "methods": [ + "drop_database" + ] + }, + "GetBackup": { + "methods": [ + "get_backup" + ] + }, + "GetDatabase": { + "methods": [ + "get_database" + ] + }, + "GetDatabaseDdl": { + "methods": [ + "get_database_ddl" + ] + }, + "GetIamPolicy": { + "methods": [ + "get_iam_policy" + ] + }, + "ListBackupOperations": { + "methods": [ + "list_backup_operations" + ] + }, + "ListBackups": { + "methods": [ + "list_backups" + ] + }, + "ListDatabaseOperations": { + "methods": [ + "list_database_operations" + ] + }, + "ListDatabaseRoles": { + "methods": [ + "list_database_roles" + ] + }, + "ListDatabases": { + "methods": [ + "list_databases" + ] + }, + "RestoreDatabase": { + "methods": [ + "restore_database" + ] + }, + "SetIamPolicy": { + "methods": [ + "set_iam_policy" + ] + }, + "TestIamPermissions": { + "methods": [ + "test_iam_permissions" + ] + }, + "UpdateBackup": { + "methods": [ + "update_backup" + ] + }, + "UpdateDatabase": { + "methods": [ + "update_database" + ] + }, + "UpdateDatabaseDdl": { + "methods": [ + "update_database_ddl" + ] + } + } + }, + "grpc-async": { + "libraryClient": "DatabaseAdminAsyncClient", + "rpcs": { + "CopyBackup": { + "methods": [ + "copy_backup" + ] + }, + "CreateBackup": { + "methods": [ + "create_backup" + ] + }, + "CreateDatabase": { + "methods": [ + "create_database" + ] + }, + "DeleteBackup": { + "methods": [ + "delete_backup" + ] + }, + "DropDatabase": { + "methods": [ + "drop_database" + ] + }, + "GetBackup": { + "methods": [ + "get_backup" + ] + }, + "GetDatabase": { + "methods": [ + "get_database" + ] + }, + "GetDatabaseDdl": { + "methods": [ + "get_database_ddl" + ] + }, + "GetIamPolicy": { + "methods": [ + "get_iam_policy" + ] + }, + "ListBackupOperations": { + "methods": [ + "list_backup_operations" + ] + }, + "ListBackups": { + "methods": [ + "list_backups" + ] + }, + "ListDatabaseOperations": { + "methods": [ + "list_database_operations" + ] + }, + "ListDatabaseRoles": { + "methods": [ + "list_database_roles" + ] + }, + "ListDatabases": { + "methods": [ + "list_databases" + ] + }, + "RestoreDatabase": { + "methods": [ + "restore_database" + ] + }, + "SetIamPolicy": { + "methods": [ + "set_iam_policy" + ] + }, + "TestIamPermissions": { + "methods": [ + "test_iam_permissions" + ] + }, + "UpdateBackup": { + "methods": [ + "update_backup" + ] + }, + "UpdateDatabase": { + "methods": [ + "update_database" + ] + }, + "UpdateDatabaseDdl": { + "methods": [ + "update_database_ddl" + ] + } + } + }, + "rest": { + "libraryClient": "DatabaseAdminClient", + "rpcs": { + "CopyBackup": { + "methods": [ + "copy_backup" + ] + }, + "CreateBackup": { + "methods": [ + "create_backup" + ] + }, + "CreateDatabase": { + "methods": [ + "create_database" + ] + }, + "DeleteBackup": { + "methods": [ + "delete_backup" + ] + }, + "DropDatabase": { + "methods": [ + "drop_database" + ] + }, + "GetBackup": { + "methods": [ + "get_backup" + ] + }, + "GetDatabase": { + "methods": [ + "get_database" + ] + }, + "GetDatabaseDdl": { + "methods": [ + "get_database_ddl" + ] + }, + "GetIamPolicy": { + "methods": [ + "get_iam_policy" + ] + }, + "ListBackupOperations": { + "methods": [ + "list_backup_operations" + ] + }, + "ListBackups": { + "methods": [ + "list_backups" + ] + }, + "ListDatabaseOperations": { + "methods": [ + "list_database_operations" + ] + }, + "ListDatabaseRoles": { + "methods": [ + "list_database_roles" + ] + }, + "ListDatabases": { + "methods": [ + "list_databases" + ] + }, + "RestoreDatabase": { + "methods": [ + "restore_database" + ] + }, + "SetIamPolicy": { + "methods": [ + "set_iam_policy" + ] + }, + "TestIamPermissions": { + "methods": [ + "test_iam_permissions" + ] + }, + "UpdateBackup": { + "methods": [ + "update_backup" + ] + }, + "UpdateDatabase": { + "methods": [ + "update_database" + ] + }, + "UpdateDatabaseDdl": { + "methods": [ + "update_database_ddl" + ] + } + } + } + } + } + } +} diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_version.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_version.py new file mode 100644 index 0000000000..405b1cebcf --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +__version__ = "0.1.0" # {x-release-please-version} diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/py.typed b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/py.typed new file mode 100644 index 0000000000..29f334aad6 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-spanner-admin-database package uses inline types. diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/__init__.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/__init__.py new file mode 100644 index 0000000000..e8e1c3845d --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py new file mode 100644 index 0000000000..f18b3b7d61 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .client import DatabaseAdminClient +from .async_client import DatabaseAdminAsyncClient + +__all__ = ( + 'DatabaseAdminClient', + 'DatabaseAdminAsyncClient', +) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py new file mode 100644 index 0000000000..c0c1cbc083 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py @@ -0,0 +1,3146 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +import functools +import re +from typing import Dict, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union + +from google.cloud.spanner_admin_database_v1 import gapic_version as package_version + +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.spanner_admin_database_v1.services.database_admin import pagers +from google.cloud.spanner_admin_database_v1.types import backup +from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup +from google.cloud.spanner_admin_database_v1.types import common +from google.cloud.spanner_admin_database_v1.types import spanner_database_admin +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import DatabaseAdminTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import DatabaseAdminGrpcAsyncIOTransport +from .client import DatabaseAdminClient + + +class DatabaseAdminAsyncClient: + """Cloud Spanner Database Admin API + + The Cloud Spanner Database Admin API can be used to: + + - create, drop, and list databases + - update the schema of pre-existing databases + - create, delete and list backups for a database + - restore a database from an existing backup + """ + + _client: DatabaseAdminClient + + DEFAULT_ENDPOINT = DatabaseAdminClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = DatabaseAdminClient.DEFAULT_MTLS_ENDPOINT + + backup_path = staticmethod(DatabaseAdminClient.backup_path) + parse_backup_path = staticmethod(DatabaseAdminClient.parse_backup_path) + crypto_key_path = staticmethod(DatabaseAdminClient.crypto_key_path) + parse_crypto_key_path = staticmethod(DatabaseAdminClient.parse_crypto_key_path) + crypto_key_version_path = staticmethod(DatabaseAdminClient.crypto_key_version_path) + parse_crypto_key_version_path = staticmethod(DatabaseAdminClient.parse_crypto_key_version_path) + database_path = staticmethod(DatabaseAdminClient.database_path) + parse_database_path = staticmethod(DatabaseAdminClient.parse_database_path) + database_role_path = staticmethod(DatabaseAdminClient.database_role_path) + parse_database_role_path = staticmethod(DatabaseAdminClient.parse_database_role_path) + instance_path = staticmethod(DatabaseAdminClient.instance_path) + parse_instance_path = staticmethod(DatabaseAdminClient.parse_instance_path) + common_billing_account_path = staticmethod(DatabaseAdminClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(DatabaseAdminClient.parse_common_billing_account_path) + common_folder_path = staticmethod(DatabaseAdminClient.common_folder_path) + parse_common_folder_path = staticmethod(DatabaseAdminClient.parse_common_folder_path) + common_organization_path = staticmethod(DatabaseAdminClient.common_organization_path) + parse_common_organization_path = staticmethod(DatabaseAdminClient.parse_common_organization_path) + common_project_path = staticmethod(DatabaseAdminClient.common_project_path) + parse_common_project_path = staticmethod(DatabaseAdminClient.parse_common_project_path) + common_location_path = staticmethod(DatabaseAdminClient.common_location_path) + parse_common_location_path = staticmethod(DatabaseAdminClient.parse_common_location_path) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DatabaseAdminAsyncClient: The constructed client. + """ + return DatabaseAdminClient.from_service_account_info.__func__(DatabaseAdminAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DatabaseAdminAsyncClient: The constructed client. + """ + return DatabaseAdminClient.from_service_account_file.__func__(DatabaseAdminAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @classmethod + def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[ClientOptions] = None): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variable is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return DatabaseAdminClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> DatabaseAdminTransport: + """Returns the transport used by the client instance. + + Returns: + DatabaseAdminTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial(type(DatabaseAdminClient).get_transport_class, type(DatabaseAdminClient)) + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Union[str, DatabaseAdminTransport] = "grpc_asyncio", + client_options: Optional[ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the database admin client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, ~.DatabaseAdminTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (ClientOptions): Custom options for the client. It + won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + """ + self._client = DatabaseAdminClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + async def list_databases(self, + request: Optional[Union[spanner_database_admin.ListDatabasesRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListDatabasesAsyncPager: + r"""Lists Cloud Spanner databases. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_list_databases(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabasesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_databases(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest, dict]]): + The request object. The request for + [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. + parent (:class:`str`): + Required. The instance whose databases should be listed. + Values are of the form + ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabasesAsyncPager: + The response for + [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_database_admin.ListDatabasesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_databases, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListDatabasesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def create_database(self, + request: Optional[Union[spanner_database_admin.CreateDatabaseRequest, dict]] = None, + *, + parent: Optional[str] = None, + create_statement: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Creates a new Cloud Spanner database and starts to prepare it + for serving. The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and can be + used to track preparation of the database. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateDatabaseMetadata][google.spanner.admin.database.v1.CreateDatabaseMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Database][google.spanner.admin.database.v1.Database], if + successful. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_create_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateDatabaseRequest( + parent="parent_value", + create_statement="create_statement_value", + ) + + # Make the request + operation = client.create_database(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.CreateDatabaseRequest, dict]]): + The request object. The request for + [CreateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase]. + parent (:class:`str`): + Required. The name of the instance that will serve the + new database. Values are of the form + ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + create_statement (:class:`str`): + Required. A ``CREATE DATABASE`` statement, which + specifies the ID of the new database. The database ID + must conform to the regular expression + ``[a-z][a-z0-9_\-]*[a-z0-9]`` and be between 2 and 30 + characters in length. If the database ID is a reserved + word or if it contains a hyphen, the database ID must be + enclosed in backticks (:literal:`\``). + + This corresponds to the ``create_statement`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_database_v1.types.Database` + A Cloud Spanner database. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, create_statement]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_database_admin.CreateDatabaseRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if create_statement is not None: + request.create_statement = create_statement + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.create_database, + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + spanner_database_admin.Database, + metadata_type=spanner_database_admin.CreateDatabaseMetadata, + ) + + # Done; return the response. + return response + + async def get_database(self, + request: Optional[Union[spanner_database_admin.GetDatabaseRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner_database_admin.Database: + r"""Gets the state of a Cloud Spanner database. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_get_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseRequest( + name="name_value", + ) + + # Make the request + response = await client.get_database(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.GetDatabaseRequest, dict]]): + The request object. The request for + [GetDatabase][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase]. + name (:class:`str`): + Required. The name of the requested database. Values are + of the form + ``projects//instances//databases/``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.types.Database: + A Cloud Spanner database. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_database_admin.GetDatabaseRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_database, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def update_database(self, + request: Optional[Union[spanner_database_admin.UpdateDatabaseRequest, dict]] = None, + *, + database: Optional[spanner_database_admin.Database] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Updates a Cloud Spanner database. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the database. If the named database + does not exist, returns ``NOT_FOUND``. + + While the operation is pending: + + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field is set to true. + - Cancelling the operation is best-effort. If the cancellation + succeeds, the operation metadata's + [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] + is set, the updates are reverted, and the operation + terminates with a ``CANCELLED`` status. + - New UpdateDatabase requests will return a + ``FAILED_PRECONDITION`` error until the pending operation is + done (returns successfully or with error). + - Reading the database via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - The new values are in effect and readable via the API. + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format + ``projects//instances//databases//operations/`` + and can be used to track the database modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Database][google.spanner.admin.database.v1.Database], if + successful. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_update_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + database = spanner_admin_database_v1.Database() + database.name = "name_value" + + request = spanner_admin_database_v1.UpdateDatabaseRequest( + database=database, + ) + + # Make the request + operation = client.update_database(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest, dict]]): + The request object. The request for + [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. + database (:class:`google.cloud.spanner_admin_database_v1.types.Database`): + Required. The database to update. The ``name`` field of + the database is of the form + ``projects//instances//databases/``. + + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. The list of fields to update. Currently, only + ``enable_drop_protection`` field can be updated. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_database_v1.types.Database` + A Cloud Spanner database. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database, update_mask]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_database_admin.UpdateDatabaseRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_database, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("database.name", request.database.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + spanner_database_admin.Database, + metadata_type=spanner_database_admin.UpdateDatabaseMetadata, + ) + + # Done; return the response. + return response + + async def update_database_ddl(self, + request: Optional[Union[spanner_database_admin.UpdateDatabaseDdlRequest, dict]] = None, + *, + database: Optional[str] = None, + statements: Optional[MutableSequence[str]] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Updates the schema of a Cloud Spanner database by + creating/altering/dropping tables, columns, indexes, etc. The + returned [long-running operation][google.longrunning.Operation] + will have a name of the format + ``/operations/`` and can be used to + track execution of the schema change(s). The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateDatabaseDdlMetadata][google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata]. + The operation has no response. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_update_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateDatabaseDdlRequest( + database="database_value", + statements=['statements_value1', 'statements_value2'], + ) + + # Make the request + operation = client.update_database_ddl(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseDdlRequest, dict]]): + The request object. Enqueues the given DDL statements to be applied, in + order but not necessarily all at once, to the database + schema at some point (or points) in the future. The + server checks that the statements are executable + (syntactically valid, name tables that exist, etc.) + before enqueueing them, but they may still fail upon + later execution (e.g., if a statement from another batch + of statements is applied first and it conflicts in some + way, or if there is some data-related problem like a + ``NULL`` value in a column to which ``NOT NULL`` would + be added). If a statement fails, all subsequent + statements in the batch are automatically cancelled. + + Each batch of statements is assigned a name which can be + used with the + [Operations][google.longrunning.Operations] API to + monitor progress. See the + [operation_id][google.spanner.admin.database.v1.UpdateDatabaseDdlRequest.operation_id] + field for more details. + database (:class:`str`): + Required. The database to update. + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + statements (:class:`MutableSequence[str]`): + Required. DDL statements to be + applied to the database. + + This corresponds to the ``statements`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + 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 + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database, statements]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_database_admin.UpdateDatabaseDdlRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + if statements: + request.statements.extend(statements) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_database_ddl, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("database", request.database), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=spanner_database_admin.UpdateDatabaseDdlMetadata, + ) + + # Done; return the response. + return response + + async def drop_database(self, + request: Optional[Union[spanner_database_admin.DropDatabaseRequest, dict]] = None, + *, + database: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Drops (aka deletes) a Cloud Spanner database. Completed backups + for the database will be retained according to their + ``expire_time``. Note: Cloud Spanner might continue to accept + requests for a few seconds after the database has been deleted. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_drop_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DropDatabaseRequest( + database="database_value", + ) + + # Make the request + await client.drop_database(request=request) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.DropDatabaseRequest, dict]]): + The request object. The request for + [DropDatabase][google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase]. + database (:class:`str`): + Required. The database to be dropped. + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_database_admin.DropDatabaseRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.drop_database, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("database", request.database), + )), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def get_database_ddl(self, + request: Optional[Union[spanner_database_admin.GetDatabaseDdlRequest, dict]] = None, + *, + database: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner_database_admin.GetDatabaseDdlResponse: + r"""Returns the schema of a Cloud Spanner database as a list of + formatted DDL statements. This method does not show pending + schema updates, those may be queried using the + [Operations][google.longrunning.Operations] API. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_get_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseDdlRequest( + database="database_value", + ) + + # Make the request + response = await client.get_database_ddl(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlRequest, dict]]): + The request object. The request for + [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. + database (:class:`str`): + Required. The database whose schema we wish to get. + Values are of the form + ``projects//instances//databases/`` + + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlResponse: + The response for + [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_database_admin.GetDatabaseDdlRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_database_ddl, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("database", request.database), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def set_iam_policy(self, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, + *, + resource: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the access control policy on a database or backup resource. + Replaces any existing policy. + + Authorization requires ``spanner.databases.setIamPolicy`` + permission on + [resource][google.iam.v1.SetIamPolicyRequest.resource]. For + backups, authorization requires ``spanner.backups.setIamPolicy`` + permission on + [resource][google.iam.v1.SetIamPolicyRequest.resource]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + async def sample_set_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = await client.set_iam_policy(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]]): + The request object. Request message for ``SetIamPolicy`` method. + resource (:class:`str`): + REQUIRED: The resource for which the + policy is being specified. See the + operation documentation for the + appropriate value for this field. + + This corresponds to the ``resource`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.iam.v1.policy_pb2.Policy: + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. + + A Policy is a collection of bindings. A binding binds + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": [ "user:eve@example.com" ], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ], "etag": "BwWWja0YfJA=", "version": 3 + + } + + **YAML example:** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 + + For a description of IAM and its features, see the + [IAM + documentation](\ https://cloud.google.com/iam/docs/). + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([resource]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + elif not request: + request = iam_policy_pb2.SetIamPolicyRequest(resource=resource, ) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy(self, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, + *, + resource: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the access control policy for a database or backup + resource. Returns an empty policy if a database or backup exists + but does not have a policy set. + + Authorization requires ``spanner.databases.getIamPolicy`` + permission on + [resource][google.iam.v1.GetIamPolicyRequest.resource]. For + backups, authorization requires ``spanner.backups.getIamPolicy`` + permission on + [resource][google.iam.v1.GetIamPolicyRequest.resource]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + async def sample_get_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = await client.get_iam_policy(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]]): + The request object. Request message for ``GetIamPolicy`` method. + resource (:class:`str`): + REQUIRED: The resource for which the + policy is being requested. See the + operation documentation for the + appropriate value for this field. + + This corresponds to the ``resource`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.iam.v1.policy_pb2.Policy: + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. + + A Policy is a collection of bindings. A binding binds + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": [ "user:eve@example.com" ], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ], "etag": "BwWWja0YfJA=", "version": 3 + + } + + **YAML example:** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 + + For a description of IAM and its features, see the + [IAM + documentation](\ https://cloud.google.com/iam/docs/). + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([resource]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + elif not request: + request = iam_policy_pb2.GetIamPolicyRequest(resource=resource, ) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_iam_policy, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions(self, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, + *, + resource: Optional[str] = None, + permissions: Optional[MutableSequence[str]] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Returns permissions that the caller has on the specified + database or backup resource. + + Attempting this RPC on a non-existent Cloud Spanner database + will result in a NOT_FOUND error if the user has + ``spanner.databases.list`` permission on the containing Cloud + Spanner instance. Otherwise returns an empty set of permissions. + Calling this method on a backup that does not exist will result + in a NOT_FOUND error if the user has ``spanner.backups.list`` + permission on the containing instance. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + async def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value1', 'permissions_value2'], + ) + + # Make the request + response = await client.test_iam_permissions(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]]): + The request object. Request message for ``TestIamPermissions`` method. + resource (:class:`str`): + REQUIRED: The resource for which the + policy detail is being requested. See + the operation documentation for the + appropriate value for this field. + + This corresponds to the ``resource`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + permissions (:class:`MutableSequence[str]`): + The set of permissions to check for the ``resource``. + Permissions with wildcards (such as '*' or 'storage.*') + are not allowed. For more information see `IAM + Overview `__. + + This corresponds to the ``permissions`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: + Response message for TestIamPermissions method. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([resource, permissions]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + elif not request: + request = iam_policy_pb2.TestIamPermissionsRequest(resource=resource, permissions=permissions, ) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def create_backup(self, + request: Optional[Union[gsad_backup.CreateBackupRequest, dict]] = None, + *, + parent: Optional[str] = None, + backup: Optional[gsad_backup.Backup] = None, + backup_id: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Starts creating a new Cloud Spanner Backup. The returned backup + [long-running operation][google.longrunning.Operation] will have + a name of the format + ``projects//instances//backups//operations/`` + and can be used to track creation of the backup. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Backup][google.spanner.admin.database.v1.Backup], if + successful. Cancelling the returned operation will stop the + creation and delete the backup. There can be only one pending + backup creation per database. Backup creation of different + databases can run concurrently. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_create_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + ) + + # Make the request + operation = client.create_backup(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.CreateBackupRequest, dict]]): + The request object. The request for + [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup]. + parent (:class:`str`): + Required. The name of the instance in which the backup + will be created. This must be the same instance that + contains the database the backup will be created from. + The backup will be stored in the location(s) specified + in the instance configuration of this instance. Values + are of the form + ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + backup (:class:`google.cloud.spanner_admin_database_v1.types.Backup`): + Required. The backup to create. + This corresponds to the ``backup`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + backup_id (:class:`str`): + Required. The id of the backup to be created. The + ``backup_id`` appended to ``parent`` forms the full + backup name of the form + ``projects//instances//backups/``. + + This corresponds to the ``backup_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_database_v1.types.Backup` + A backup of a Cloud Spanner database. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, backup, backup_id]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = gsad_backup.CreateBackupRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if backup is not None: + request.backup = backup + if backup_id is not None: + request.backup_id = backup_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.create_backup, + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gsad_backup.Backup, + metadata_type=gsad_backup.CreateBackupMetadata, + ) + + # Done; return the response. + return response + + async def copy_backup(self, + request: Optional[Union[backup.CopyBackupRequest, dict]] = None, + *, + parent: Optional[str] = None, + backup_id: Optional[str] = None, + source_backup: Optional[str] = None, + expire_time: Optional[timestamp_pb2.Timestamp] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Starts copying a Cloud Spanner Backup. The returned backup + [long-running operation][google.longrunning.Operation] will have + a name of the format + ``projects//instances//backups//operations/`` + and can be used to track copying of the backup. The operation is + associated with the destination backup. The + [metadata][google.longrunning.Operation.metadata] field type is + [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Backup][google.spanner.admin.database.v1.Backup], if + successful. Cancelling the returned operation will stop the + copying and delete the backup. Concurrent CopyBackup requests + can run on the same source backup. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_copy_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CopyBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + source_backup="source_backup_value", + ) + + # Make the request + operation = client.copy_backup(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.CopyBackupRequest, dict]]): + The request object. The request for + [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup]. + parent (:class:`str`): + Required. The name of the destination instance that will + contain the backup copy. Values are of the form: + ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + backup_id (:class:`str`): + Required. The id of the backup copy. The ``backup_id`` + appended to ``parent`` forms the full backup_uri of the + form + ``projects//instances//backups/``. + + This corresponds to the ``backup_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + source_backup (:class:`str`): + Required. The source backup to be copied. The source + backup needs to be in READY state for it to be copied. + Once CopyBackup is in progress, the source backup cannot + be deleted or cleaned up on expiration until CopyBackup + is finished. Values are of the form: + ``projects//instances//backups/``. + + This corresponds to the ``source_backup`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + expire_time (:class:`google.protobuf.timestamp_pb2.Timestamp`): + Required. The expiration time of the backup in + microsecond granularity. The expiration time must be at + least 6 hours and at most 366 days from the + ``create_time`` of the source backup. Once the + ``expire_time`` has passed, the backup is eligible to be + automatically deleted by Cloud Spanner to free the + resources used by the backup. + + This corresponds to the ``expire_time`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_database_v1.types.Backup` + A backup of a Cloud Spanner database. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, backup_id, source_backup, expire_time]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = backup.CopyBackupRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if backup_id is not None: + request.backup_id = backup_id + if source_backup is not None: + request.source_backup = source_backup + if expire_time is not None: + request.expire_time = expire_time + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.copy_backup, + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + backup.Backup, + metadata_type=backup.CopyBackupMetadata, + ) + + # Done; return the response. + return response + + async def get_backup(self, + request: Optional[Union[backup.GetBackupRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> backup.Backup: + r"""Gets metadata on a pending or completed + [Backup][google.spanner.admin.database.v1.Backup]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_get_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetBackupRequest( + name="name_value", + ) + + # Make the request + response = await client.get_backup(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.GetBackupRequest, dict]]): + The request object. The request for + [GetBackup][google.spanner.admin.database.v1.DatabaseAdmin.GetBackup]. + name (:class:`str`): + Required. Name of the backup. Values are of the form + ``projects//instances//backups/``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.types.Backup: + A backup of a Cloud Spanner database. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = backup.GetBackupRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_backup, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def update_backup(self, + request: Optional[Union[gsad_backup.UpdateBackupRequest, dict]] = None, + *, + backup: Optional[gsad_backup.Backup] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gsad_backup.Backup: + r"""Updates a pending or completed + [Backup][google.spanner.admin.database.v1.Backup]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_update_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateBackupRequest( + ) + + # Make the request + response = await client.update_backup(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.UpdateBackupRequest, dict]]): + The request object. The request for + [UpdateBackup][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup]. + backup (:class:`google.cloud.spanner_admin_database_v1.types.Backup`): + Required. The backup to update. ``backup.name``, and the + fields to be updated as specified by ``update_mask`` are + required. Other fields are ignored. Update is only + supported for the following fields: + + - ``backup.expire_time``. + + This corresponds to the ``backup`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. A mask specifying which fields (e.g. + ``expire_time``) in the Backup resource should be + updated. This mask is relative to the Backup resource, + not to the request message. The field mask must always + be specified; this prevents any future fields from being + erased accidentally by clients that do not know about + them. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.types.Backup: + A backup of a Cloud Spanner database. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([backup, update_mask]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = gsad_backup.UpdateBackupRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if backup is not None: + request.backup = backup + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_backup, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("backup.name", request.backup.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_backup(self, + request: Optional[Union[backup.DeleteBackupRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a pending or completed + [Backup][google.spanner.admin.database.v1.Backup]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_delete_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DeleteBackupRequest( + name="name_value", + ) + + # Make the request + await client.delete_backup(request=request) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.DeleteBackupRequest, dict]]): + The request object. The request for + [DeleteBackup][google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup]. + name (:class:`str`): + Required. Name of the backup to delete. Values are of + the form + ``projects//instances//backups/``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = backup.DeleteBackupRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.delete_backup, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def list_backups(self, + request: Optional[Union[backup.ListBackupsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListBackupsAsyncPager: + r"""Lists completed and pending backups. Backups returned are + ordered by ``create_time`` in descending order, starting from + the most recent ``create_time``. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_list_backups(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backups(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.ListBackupsRequest, dict]]): + The request object. The request for + [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. + parent (:class:`str`): + Required. The instance to list backups from. Values are + of the form ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupsAsyncPager: + The response for + [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = backup.ListBackupsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_backups, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListBackupsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def restore_database(self, + request: Optional[Union[spanner_database_admin.RestoreDatabaseRequest, dict]] = None, + *, + parent: Optional[str] = None, + database_id: Optional[str] = None, + backup: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Create a new database by restoring from a completed backup. The + new database must be in the same project and in an instance with + the same instance configuration as the instance containing the + backup. The returned database [long-running + operation][google.longrunning.Operation] has a name of the + format + ``projects//instances//databases//operations/``, + and can be used to track the progress of the operation, and to + cancel it. The [metadata][google.longrunning.Operation.metadata] + field type is + [RestoreDatabaseMetadata][google.spanner.admin.database.v1.RestoreDatabaseMetadata]. + The [response][google.longrunning.Operation.response] type is + [Database][google.spanner.admin.database.v1.Database], if + successful. Cancelling the returned operation will stop the + restore and delete the database. There can be only one database + being restored into an instance at a time. Once the restore + operation completes, a new restore operation can be initiated, + without waiting for the optimize operation associated with the + first restore to complete. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_restore_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.RestoreDatabaseRequest( + backup="backup_value", + parent="parent_value", + database_id="database_id_value", + ) + + # Make the request + operation = client.restore_database(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.RestoreDatabaseRequest, dict]]): + The request object. The request for + [RestoreDatabase][google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase]. + parent (:class:`str`): + Required. The name of the instance in which to create + the restored database. This instance must be in the same + project and have the same instance configuration as the + instance containing the source backup. Values are of the + form ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + database_id (:class:`str`): + Required. The id of the database to create and restore + to. This database must not already exist. The + ``database_id`` appended to ``parent`` forms the full + database name of the form + ``projects//instances//databases/``. + + This corresponds to the ``database_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + backup (:class:`str`): + Name of the backup from which to restore. Values are of + the form + ``projects//instances//backups/``. + + This corresponds to the ``backup`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_database_v1.types.Database` + A Cloud Spanner database. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, database_id, backup]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_database_admin.RestoreDatabaseRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if database_id is not None: + request.database_id = database_id + if backup is not None: + request.backup = backup + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.restore_database, + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + spanner_database_admin.Database, + metadata_type=spanner_database_admin.RestoreDatabaseMetadata, + ) + + # Done; return the response. + return response + + async def list_database_operations(self, + request: Optional[Union[spanner_database_admin.ListDatabaseOperationsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListDatabaseOperationsAsyncPager: + r"""Lists database + [longrunning-operations][google.longrunning.Operation]. A + database operation has a name of the form + ``projects//instances//databases//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_list_database_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabaseOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_database_operations(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest, dict]]): + The request object. The request for + [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. + parent (:class:`str`): + Required. The instance of the database operations. + Values are of the form + ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseOperationsAsyncPager: + The response for + [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_database_admin.ListDatabaseOperationsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_database_operations, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListDatabaseOperationsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_backup_operations(self, + request: Optional[Union[backup.ListBackupOperationsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListBackupOperationsAsyncPager: + r"""Lists the backup [long-running + operations][google.longrunning.Operation] in the given instance. + A backup operation has a name of the form + ``projects//instances//backups//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. Operations returned are ordered by + ``operation.metadata.value.progress.start_time`` in descending + order starting from the most recently started operation. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_list_backup_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backup_operations(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest, dict]]): + The request object. The request for + [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. + parent (:class:`str`): + Required. The instance of the backup operations. Values + are of the form + ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupOperationsAsyncPager: + The response for + [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = backup.ListBackupOperationsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_backup_operations, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListBackupOperationsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_database_roles(self, + request: Optional[Union[spanner_database_admin.ListDatabaseRolesRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListDatabaseRolesAsyncPager: + r"""Lists Cloud Spanner database roles. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_list_database_roles(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabaseRolesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_database_roles(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest, dict]]): + The request object. The request for + [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. + parent (:class:`str`): + Required. The database whose roles should be listed. + Values are of the form + ``projects//instances//databases//databaseRoles``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseRolesAsyncPager: + The response for + [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_database_admin.ListDatabaseRolesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_database_roles, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListDatabaseRolesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: Optional[operations_pb2.ListOperationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def get_operation( + self, + request: Optional[operations_pb2.GetOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("name", request.name),)), + ) + + # Send the request. + response = await rpc( + request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def delete_operation( + self, + request: Optional[operations_pb2.DeleteOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("name", request.name),)), + ) + + # Send the request. + await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + async def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("name", request.name),)), + ) + + # Send the request. + await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + + +__all__ = ( + "DatabaseAdminAsyncClient", +) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/client.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/client.py new file mode 100644 index 0000000000..52705b426e --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/client.py @@ -0,0 +1,3296 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +import os +import re +from typing import Dict, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast + +from google.cloud.spanner_admin_database_v1 import gapic_version as package_version + +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.spanner_admin_database_v1.services.database_admin import pagers +from google.cloud.spanner_admin_database_v1.types import backup +from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup +from google.cloud.spanner_admin_database_v1.types import common +from google.cloud.spanner_admin_database_v1.types import spanner_database_admin +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import DatabaseAdminTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import DatabaseAdminGrpcTransport +from .transports.grpc_asyncio import DatabaseAdminGrpcAsyncIOTransport +from .transports.rest import DatabaseAdminRestTransport + + +class DatabaseAdminClientMeta(type): + """Metaclass for the DatabaseAdmin client. + + This provides class-level methods for building and retrieving + support objects (e.g. transport) without polluting the client instance + objects. + """ + _transport_registry = OrderedDict() # type: Dict[str, Type[DatabaseAdminTransport]] + _transport_registry["grpc"] = DatabaseAdminGrpcTransport + _transport_registry["grpc_asyncio"] = DatabaseAdminGrpcAsyncIOTransport + _transport_registry["rest"] = DatabaseAdminRestTransport + + def get_transport_class(cls, + label: Optional[str] = None, + ) -> Type[DatabaseAdminTransport]: + """Returns an appropriate transport class. + + Args: + label: The name of the desired transport. If none is + provided, then the first transport in the registry is used. + + Returns: + The transport class to use. + """ + # If a specific transport is requested, return that one. + if label: + return cls._transport_registry[label] + + # No transport is requested; return the default (that is, the first one + # in the dictionary). + return next(iter(cls._transport_registry.values())) + + +class DatabaseAdminClient(metaclass=DatabaseAdminClientMeta): + """Cloud Spanner Database Admin API + + The Cloud Spanner Database Admin API can be used to: + + - create, drop, and list databases + - update the schema of pre-existing databases + - create, delete and list backups for a database + - restore a database from an existing backup + """ + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + str: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + DEFAULT_ENDPOINT = "spanner.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DatabaseAdminClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + DatabaseAdminClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file( + filename) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> DatabaseAdminTransport: + """Returns the transport used by the client instance. + + Returns: + DatabaseAdminTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def backup_path(project: str,instance: str,backup: str,) -> str: + """Returns a fully-qualified backup string.""" + return "projects/{project}/instances/{instance}/backups/{backup}".format(project=project, instance=instance, backup=backup, ) + + @staticmethod + def parse_backup_path(path: str) -> Dict[str,str]: + """Parses a backup path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)/backups/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def crypto_key_path(project: str,location: str,key_ring: str,crypto_key: str,) -> str: + """Returns a fully-qualified crypto_key string.""" + return "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}".format(project=project, location=location, key_ring=key_ring, crypto_key=crypto_key, ) + + @staticmethod + def parse_crypto_key_path(path: str) -> Dict[str,str]: + """Parses a crypto_key path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/keyRings/(?P.+?)/cryptoKeys/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def crypto_key_version_path(project: str,location: str,key_ring: str,crypto_key: str,crypto_key_version: str,) -> str: + """Returns a fully-qualified crypto_key_version string.""" + return "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version}".format(project=project, location=location, key_ring=key_ring, crypto_key=crypto_key, crypto_key_version=crypto_key_version, ) + + @staticmethod + def parse_crypto_key_version_path(path: str) -> Dict[str,str]: + """Parses a crypto_key_version path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/keyRings/(?P.+?)/cryptoKeys/(?P.+?)/cryptoKeyVersions/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def database_path(project: str,instance: str,database: str,) -> str: + """Returns a fully-qualified database string.""" + return "projects/{project}/instances/{instance}/databases/{database}".format(project=project, instance=instance, database=database, ) + + @staticmethod + def parse_database_path(path: str) -> Dict[str,str]: + """Parses a database path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)/databases/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def database_role_path(project: str,instance: str,database: str,role: str,) -> str: + """Returns a fully-qualified database_role string.""" + return "projects/{project}/instances/{instance}/databases/{database}/databaseRoles/{role}".format(project=project, instance=instance, database=database, role=role, ) + + @staticmethod + def parse_database_role_path(path: str) -> Dict[str,str]: + """Parses a database_role path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)/databases/(?P.+?)/databaseRoles/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def instance_path(project: str,instance: str,) -> str: + """Returns a fully-qualified instance string.""" + return "projects/{project}/instances/{instance}".format(project=project, instance=instance, ) + + @staticmethod + def parse_instance_path(path: str) -> Dict[str,str]: + """Parses a instance path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path(billing_account: str, ) -> str: + """Returns a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str,str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str, ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder, ) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str,str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str, ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization, ) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str,str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str, ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format(project=project, ) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str,str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str, ) -> str: + """Returns a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format(project=project, location=location, ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str,str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @classmethod + def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_options_lib.ClientOptions] = None): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variable is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[Union[str, DatabaseAdminTransport]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the database admin client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, DatabaseAdminTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the + client. It won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + """ + if isinstance(client_options, dict): + client_options = client_options_lib.from_dict(client_options) + if client_options is None: + client_options = client_options_lib.ClientOptions() + client_options = cast(client_options_lib.ClientOptions, client_options) + + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source(client_options) + + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError("client_options.api_key and credentials are mutually exclusive") + + # Save or instantiate the transport. + # Ordinarily, we provide the transport, but allowing a custom transport + # instance provides an extensibility point for unusual situations. + if isinstance(transport, DatabaseAdminTransport): + # transport is a DatabaseAdminTransport instance. + if credentials or client_options.credentials_file or api_key_value: + raise ValueError("When providing a transport instance, " + "provide its credentials directly.") + if client_options.scopes: + raise ValueError( + "When providing a transport instance, provide its scopes " + "directly." + ) + self._transport = transport + else: + import google.auth._default # type: ignore + + if api_key_value and hasattr(google.auth._default, "get_api_key_credentials"): + credentials = google.auth._default.get_api_key_credentials(api_key_value) + + Transport = type(self).get_transport_class(transport) + self._transport = Transport( + credentials=credentials, + credentials_file=client_options.credentials_file, + host=api_endpoint, + scopes=client_options.scopes, + client_cert_source_for_mtls=client_cert_source_func, + quota_project_id=client_options.quota_project_id, + client_info=client_info, + always_use_jwt_access=True, + api_audience=client_options.api_audience, + ) + + def list_databases(self, + request: Optional[Union[spanner_database_admin.ListDatabasesRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListDatabasesPager: + r"""Lists Cloud Spanner databases. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_list_databases(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabasesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_databases(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest, dict]): + The request object. The request for + [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. + parent (str): + Required. The instance whose databases should be listed. + Values are of the form + ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabasesPager: + The response for + [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_database_admin.ListDatabasesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_database_admin.ListDatabasesRequest): + request = spanner_database_admin.ListDatabasesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_databases] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListDatabasesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def create_database(self, + request: Optional[Union[spanner_database_admin.CreateDatabaseRequest, dict]] = None, + *, + parent: Optional[str] = None, + create_statement: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Creates a new Cloud Spanner database and starts to prepare it + for serving. The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and can be + used to track preparation of the database. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateDatabaseMetadata][google.spanner.admin.database.v1.CreateDatabaseMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Database][google.spanner.admin.database.v1.Database], if + successful. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_create_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateDatabaseRequest( + parent="parent_value", + create_statement="create_statement_value", + ) + + # Make the request + operation = client.create_database(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.CreateDatabaseRequest, dict]): + The request object. The request for + [CreateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase]. + parent (str): + Required. The name of the instance that will serve the + new database. Values are of the form + ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + create_statement (str): + Required. A ``CREATE DATABASE`` statement, which + specifies the ID of the new database. The database ID + must conform to the regular expression + ``[a-z][a-z0-9_\-]*[a-z0-9]`` and be between 2 and 30 + characters in length. If the database ID is a reserved + word or if it contains a hyphen, the database ID must be + enclosed in backticks (:literal:`\``). + + This corresponds to the ``create_statement`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_database_v1.types.Database` + A Cloud Spanner database. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, create_statement]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_database_admin.CreateDatabaseRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_database_admin.CreateDatabaseRequest): + request = spanner_database_admin.CreateDatabaseRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if create_statement is not None: + request.create_statement = create_statement + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_database] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + spanner_database_admin.Database, + metadata_type=spanner_database_admin.CreateDatabaseMetadata, + ) + + # Done; return the response. + return response + + def get_database(self, + request: Optional[Union[spanner_database_admin.GetDatabaseRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner_database_admin.Database: + r"""Gets the state of a Cloud Spanner database. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_get_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseRequest( + name="name_value", + ) + + # Make the request + response = client.get_database(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.GetDatabaseRequest, dict]): + The request object. The request for + [GetDatabase][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase]. + name (str): + Required. The name of the requested database. Values are + of the form + ``projects//instances//databases/``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.types.Database: + A Cloud Spanner database. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_database_admin.GetDatabaseRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_database_admin.GetDatabaseRequest): + request = spanner_database_admin.GetDatabaseRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_database] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def update_database(self, + request: Optional[Union[spanner_database_admin.UpdateDatabaseRequest, dict]] = None, + *, + database: Optional[spanner_database_admin.Database] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Updates a Cloud Spanner database. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the database. If the named database + does not exist, returns ``NOT_FOUND``. + + While the operation is pending: + + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field is set to true. + - Cancelling the operation is best-effort. If the cancellation + succeeds, the operation metadata's + [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] + is set, the updates are reverted, and the operation + terminates with a ``CANCELLED`` status. + - New UpdateDatabase requests will return a + ``FAILED_PRECONDITION`` error until the pending operation is + done (returns successfully or with error). + - Reading the database via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - The new values are in effect and readable via the API. + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format + ``projects//instances//databases//operations/`` + and can be used to track the database modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Database][google.spanner.admin.database.v1.Database], if + successful. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_update_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + database = spanner_admin_database_v1.Database() + database.name = "name_value" + + request = spanner_admin_database_v1.UpdateDatabaseRequest( + database=database, + ) + + # Make the request + operation = client.update_database(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest, dict]): + The request object. The request for + [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. + database (google.cloud.spanner_admin_database_v1.types.Database): + Required. The database to update. The ``name`` field of + the database is of the form + ``projects//instances//databases/``. + + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. The list of fields to update. Currently, only + ``enable_drop_protection`` field can be updated. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_database_v1.types.Database` + A Cloud Spanner database. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database, update_mask]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_database_admin.UpdateDatabaseRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_database_admin.UpdateDatabaseRequest): + request = spanner_database_admin.UpdateDatabaseRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_database] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("database.name", request.database.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + spanner_database_admin.Database, + metadata_type=spanner_database_admin.UpdateDatabaseMetadata, + ) + + # Done; return the response. + return response + + def update_database_ddl(self, + request: Optional[Union[spanner_database_admin.UpdateDatabaseDdlRequest, dict]] = None, + *, + database: Optional[str] = None, + statements: Optional[MutableSequence[str]] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Updates the schema of a Cloud Spanner database by + creating/altering/dropping tables, columns, indexes, etc. The + returned [long-running operation][google.longrunning.Operation] + will have a name of the format + ``/operations/`` and can be used to + track execution of the schema change(s). The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateDatabaseDdlMetadata][google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata]. + The operation has no response. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_update_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateDatabaseDdlRequest( + database="database_value", + statements=['statements_value1', 'statements_value2'], + ) + + # Make the request + operation = client.update_database_ddl(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseDdlRequest, dict]): + The request object. Enqueues the given DDL statements to be applied, in + order but not necessarily all at once, to the database + schema at some point (or points) in the future. The + server checks that the statements are executable + (syntactically valid, name tables that exist, etc.) + before enqueueing them, but they may still fail upon + later execution (e.g., if a statement from another batch + of statements is applied first and it conflicts in some + way, or if there is some data-related problem like a + ``NULL`` value in a column to which ``NOT NULL`` would + be added). If a statement fails, all subsequent + statements in the batch are automatically cancelled. + + Each batch of statements is assigned a name which can be + used with the + [Operations][google.longrunning.Operations] API to + monitor progress. See the + [operation_id][google.spanner.admin.database.v1.UpdateDatabaseDdlRequest.operation_id] + field for more details. + database (str): + Required. The database to update. + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + statements (MutableSequence[str]): + Required. DDL statements to be + applied to the database. + + This corresponds to the ``statements`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + 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 + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database, statements]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_database_admin.UpdateDatabaseDdlRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_database_admin.UpdateDatabaseDdlRequest): + request = spanner_database_admin.UpdateDatabaseDdlRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + if statements is not None: + request.statements = statements + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_database_ddl] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("database", request.database), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=spanner_database_admin.UpdateDatabaseDdlMetadata, + ) + + # Done; return the response. + return response + + def drop_database(self, + request: Optional[Union[spanner_database_admin.DropDatabaseRequest, dict]] = None, + *, + database: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Drops (aka deletes) a Cloud Spanner database. Completed backups + for the database will be retained according to their + ``expire_time``. Note: Cloud Spanner might continue to accept + requests for a few seconds after the database has been deleted. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_drop_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DropDatabaseRequest( + database="database_value", + ) + + # Make the request + client.drop_database(request=request) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.DropDatabaseRequest, dict]): + The request object. The request for + [DropDatabase][google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase]. + database (str): + Required. The database to be dropped. + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_database_admin.DropDatabaseRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_database_admin.DropDatabaseRequest): + request = spanner_database_admin.DropDatabaseRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.drop_database] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("database", request.database), + )), + ) + + # Send the request. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def get_database_ddl(self, + request: Optional[Union[spanner_database_admin.GetDatabaseDdlRequest, dict]] = None, + *, + database: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner_database_admin.GetDatabaseDdlResponse: + r"""Returns the schema of a Cloud Spanner database as a list of + formatted DDL statements. This method does not show pending + schema updates, those may be queried using the + [Operations][google.longrunning.Operations] API. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_get_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseDdlRequest( + database="database_value", + ) + + # Make the request + response = client.get_database_ddl(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlRequest, dict]): + The request object. The request for + [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. + database (str): + Required. The database whose schema we wish to get. + Values are of the form + ``projects//instances//databases/`` + + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlResponse: + The response for + [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_database_admin.GetDatabaseDdlRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_database_admin.GetDatabaseDdlRequest): + request = spanner_database_admin.GetDatabaseDdlRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_database_ddl] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("database", request.database), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy(self, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, + *, + resource: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the access control policy on a database or backup resource. + Replaces any existing policy. + + Authorization requires ``spanner.databases.setIamPolicy`` + permission on + [resource][google.iam.v1.SetIamPolicyRequest.resource]. For + backups, authorization requires ``spanner.backups.setIamPolicy`` + permission on + [resource][google.iam.v1.SetIamPolicyRequest.resource]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_set_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.set_iam_policy(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]): + The request object. Request message for ``SetIamPolicy`` method. + resource (str): + REQUIRED: The resource for which the + policy is being specified. See the + operation documentation for the + appropriate value for this field. + + This corresponds to the ``resource`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.iam.v1.policy_pb2.Policy: + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. + + A Policy is a collection of bindings. A binding binds + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": [ "user:eve@example.com" ], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ], "etag": "BwWWja0YfJA=", "version": 3 + + } + + **YAML example:** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 + + For a description of IAM and its features, see the + [IAM + documentation](\ https://cloud.google.com/iam/docs/). + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([resource]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + request = iam_policy_pb2.SetIamPolicyRequest(**request) + elif not request: + # Null request, just make one. + request = iam_policy_pb2.SetIamPolicyRequest() + if resource is not None: + request.resource = resource + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.set_iam_policy] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy(self, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, + *, + resource: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the access control policy for a database or backup + resource. Returns an empty policy if a database or backup exists + but does not have a policy set. + + Authorization requires ``spanner.databases.getIamPolicy`` + permission on + [resource][google.iam.v1.GetIamPolicyRequest.resource]. For + backups, authorization requires ``spanner.backups.getIamPolicy`` + permission on + [resource][google.iam.v1.GetIamPolicyRequest.resource]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_get_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.get_iam_policy(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]): + The request object. Request message for ``GetIamPolicy`` method. + resource (str): + REQUIRED: The resource for which the + policy is being requested. See the + operation documentation for the + appropriate value for this field. + + This corresponds to the ``resource`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.iam.v1.policy_pb2.Policy: + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. + + A Policy is a collection of bindings. A binding binds + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": [ "user:eve@example.com" ], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ], "etag": "BwWWja0YfJA=", "version": 3 + + } + + **YAML example:** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 + + For a description of IAM and its features, see the + [IAM + documentation](\ https://cloud.google.com/iam/docs/). + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([resource]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + request = iam_policy_pb2.GetIamPolicyRequest(**request) + elif not request: + # Null request, just make one. + request = iam_policy_pb2.GetIamPolicyRequest() + if resource is not None: + request.resource = resource + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_iam_policy] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions(self, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, + *, + resource: Optional[str] = None, + permissions: Optional[MutableSequence[str]] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Returns permissions that the caller has on the specified + database or backup resource. + + Attempting this RPC on a non-existent Cloud Spanner database + will result in a NOT_FOUND error if the user has + ``spanner.databases.list`` permission on the containing Cloud + Spanner instance. Otherwise returns an empty set of permissions. + Calling this method on a backup that does not exist will result + in a NOT_FOUND error if the user has ``spanner.backups.list`` + permission on the containing instance. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value1', 'permissions_value2'], + ) + + # Make the request + response = client.test_iam_permissions(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]): + The request object. Request message for ``TestIamPermissions`` method. + resource (str): + REQUIRED: The resource for which the + policy detail is being requested. See + the operation documentation for the + appropriate value for this field. + + This corresponds to the ``resource`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + permissions (MutableSequence[str]): + The set of permissions to check for the ``resource``. + Permissions with wildcards (such as '*' or 'storage.*') + are not allowed. For more information see `IAM + Overview `__. + + This corresponds to the ``permissions`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: + Response message for TestIamPermissions method. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([resource, permissions]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + elif not request: + # Null request, just make one. + request = iam_policy_pb2.TestIamPermissionsRequest() + if resource is not None: + request.resource = resource + if permissions: + request.permissions.extend(permissions) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def create_backup(self, + request: Optional[Union[gsad_backup.CreateBackupRequest, dict]] = None, + *, + parent: Optional[str] = None, + backup: Optional[gsad_backup.Backup] = None, + backup_id: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Starts creating a new Cloud Spanner Backup. The returned backup + [long-running operation][google.longrunning.Operation] will have + a name of the format + ``projects//instances//backups//operations/`` + and can be used to track creation of the backup. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Backup][google.spanner.admin.database.v1.Backup], if + successful. Cancelling the returned operation will stop the + creation and delete the backup. There can be only one pending + backup creation per database. Backup creation of different + databases can run concurrently. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_create_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + ) + + # Make the request + operation = client.create_backup(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.CreateBackupRequest, dict]): + The request object. The request for + [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup]. + parent (str): + Required. The name of the instance in which the backup + will be created. This must be the same instance that + contains the database the backup will be created from. + The backup will be stored in the location(s) specified + in the instance configuration of this instance. Values + are of the form + ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + backup (google.cloud.spanner_admin_database_v1.types.Backup): + Required. The backup to create. + This corresponds to the ``backup`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + backup_id (str): + Required. The id of the backup to be created. The + ``backup_id`` appended to ``parent`` forms the full + backup name of the form + ``projects//instances//backups/``. + + This corresponds to the ``backup_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_database_v1.types.Backup` + A backup of a Cloud Spanner database. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, backup, backup_id]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a gsad_backup.CreateBackupRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, gsad_backup.CreateBackupRequest): + request = gsad_backup.CreateBackupRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if backup is not None: + request.backup = backup + if backup_id is not None: + request.backup_id = backup_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_backup] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + gsad_backup.Backup, + metadata_type=gsad_backup.CreateBackupMetadata, + ) + + # Done; return the response. + return response + + def copy_backup(self, + request: Optional[Union[backup.CopyBackupRequest, dict]] = None, + *, + parent: Optional[str] = None, + backup_id: Optional[str] = None, + source_backup: Optional[str] = None, + expire_time: Optional[timestamp_pb2.Timestamp] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Starts copying a Cloud Spanner Backup. The returned backup + [long-running operation][google.longrunning.Operation] will have + a name of the format + ``projects//instances//backups//operations/`` + and can be used to track copying of the backup. The operation is + associated with the destination backup. The + [metadata][google.longrunning.Operation.metadata] field type is + [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Backup][google.spanner.admin.database.v1.Backup], if + successful. Cancelling the returned operation will stop the + copying and delete the backup. Concurrent CopyBackup requests + can run on the same source backup. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_copy_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CopyBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + source_backup="source_backup_value", + ) + + # Make the request + operation = client.copy_backup(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.CopyBackupRequest, dict]): + The request object. The request for + [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup]. + parent (str): + Required. The name of the destination instance that will + contain the backup copy. Values are of the form: + ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + backup_id (str): + Required. The id of the backup copy. The ``backup_id`` + appended to ``parent`` forms the full backup_uri of the + form + ``projects//instances//backups/``. + + This corresponds to the ``backup_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + source_backup (str): + Required. The source backup to be copied. The source + backup needs to be in READY state for it to be copied. + Once CopyBackup is in progress, the source backup cannot + be deleted or cleaned up on expiration until CopyBackup + is finished. Values are of the form: + ``projects//instances//backups/``. + + This corresponds to the ``source_backup`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + expire_time (google.protobuf.timestamp_pb2.Timestamp): + Required. The expiration time of the backup in + microsecond granularity. The expiration time must be at + least 6 hours and at most 366 days from the + ``create_time`` of the source backup. Once the + ``expire_time`` has passed, the backup is eligible to be + automatically deleted by Cloud Spanner to free the + resources used by the backup. + + This corresponds to the ``expire_time`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_database_v1.types.Backup` + A backup of a Cloud Spanner database. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, backup_id, source_backup, expire_time]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a backup.CopyBackupRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, backup.CopyBackupRequest): + request = backup.CopyBackupRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if backup_id is not None: + request.backup_id = backup_id + if source_backup is not None: + request.source_backup = source_backup + if expire_time is not None: + request.expire_time = expire_time + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.copy_backup] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + backup.Backup, + metadata_type=backup.CopyBackupMetadata, + ) + + # Done; return the response. + return response + + def get_backup(self, + request: Optional[Union[backup.GetBackupRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> backup.Backup: + r"""Gets metadata on a pending or completed + [Backup][google.spanner.admin.database.v1.Backup]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_get_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetBackupRequest( + name="name_value", + ) + + # Make the request + response = client.get_backup(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.GetBackupRequest, dict]): + The request object. The request for + [GetBackup][google.spanner.admin.database.v1.DatabaseAdmin.GetBackup]. + name (str): + Required. Name of the backup. Values are of the form + ``projects//instances//backups/``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.types.Backup: + A backup of a Cloud Spanner database. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a backup.GetBackupRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, backup.GetBackupRequest): + request = backup.GetBackupRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_backup] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def update_backup(self, + request: Optional[Union[gsad_backup.UpdateBackupRequest, dict]] = None, + *, + backup: Optional[gsad_backup.Backup] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gsad_backup.Backup: + r"""Updates a pending or completed + [Backup][google.spanner.admin.database.v1.Backup]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_update_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateBackupRequest( + ) + + # Make the request + response = client.update_backup(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.UpdateBackupRequest, dict]): + The request object. The request for + [UpdateBackup][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup]. + backup (google.cloud.spanner_admin_database_v1.types.Backup): + Required. The backup to update. ``backup.name``, and the + fields to be updated as specified by ``update_mask`` are + required. Other fields are ignored. Update is only + supported for the following fields: + + - ``backup.expire_time``. + + This corresponds to the ``backup`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. A mask specifying which fields (e.g. + ``expire_time``) in the Backup resource should be + updated. This mask is relative to the Backup resource, + not to the request message. The field mask must always + be specified; this prevents any future fields from being + erased accidentally by clients that do not know about + them. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.types.Backup: + A backup of a Cloud Spanner database. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([backup, update_mask]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a gsad_backup.UpdateBackupRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, gsad_backup.UpdateBackupRequest): + request = gsad_backup.UpdateBackupRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if backup is not None: + request.backup = backup + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_backup] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("backup.name", request.backup.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_backup(self, + request: Optional[Union[backup.DeleteBackupRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a pending or completed + [Backup][google.spanner.admin.database.v1.Backup]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_delete_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DeleteBackupRequest( + name="name_value", + ) + + # Make the request + client.delete_backup(request=request) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.DeleteBackupRequest, dict]): + The request object. The request for + [DeleteBackup][google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup]. + name (str): + Required. Name of the backup to delete. Values are of + the form + ``projects//instances//backups/``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a backup.DeleteBackupRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, backup.DeleteBackupRequest): + request = backup.DeleteBackupRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.delete_backup] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def list_backups(self, + request: Optional[Union[backup.ListBackupsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListBackupsPager: + r"""Lists completed and pending backups. Backups returned are + ordered by ``create_time`` in descending order, starting from + the most recent ``create_time``. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_list_backups(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backups(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.ListBackupsRequest, dict]): + The request object. The request for + [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. + parent (str): + Required. The instance to list backups from. Values are + of the form ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupsPager: + The response for + [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a backup.ListBackupsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, backup.ListBackupsRequest): + request = backup.ListBackupsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_backups] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListBackupsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def restore_database(self, + request: Optional[Union[spanner_database_admin.RestoreDatabaseRequest, dict]] = None, + *, + parent: Optional[str] = None, + database_id: Optional[str] = None, + backup: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Create a new database by restoring from a completed backup. The + new database must be in the same project and in an instance with + the same instance configuration as the instance containing the + backup. The returned database [long-running + operation][google.longrunning.Operation] has a name of the + format + ``projects//instances//databases//operations/``, + and can be used to track the progress of the operation, and to + cancel it. The [metadata][google.longrunning.Operation.metadata] + field type is + [RestoreDatabaseMetadata][google.spanner.admin.database.v1.RestoreDatabaseMetadata]. + The [response][google.longrunning.Operation.response] type is + [Database][google.spanner.admin.database.v1.Database], if + successful. Cancelling the returned operation will stop the + restore and delete the database. There can be only one database + being restored into an instance at a time. Once the restore + operation completes, a new restore operation can be initiated, + without waiting for the optimize operation associated with the + first restore to complete. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_restore_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.RestoreDatabaseRequest( + backup="backup_value", + parent="parent_value", + database_id="database_id_value", + ) + + # Make the request + operation = client.restore_database(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.RestoreDatabaseRequest, dict]): + The request object. The request for + [RestoreDatabase][google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase]. + parent (str): + Required. The name of the instance in which to create + the restored database. This instance must be in the same + project and have the same instance configuration as the + instance containing the source backup. Values are of the + form ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + database_id (str): + Required. The id of the database to create and restore + to. This database must not already exist. The + ``database_id`` appended to ``parent`` forms the full + database name of the form + ``projects//instances//databases/``. + + This corresponds to the ``database_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + backup (str): + Name of the backup from which to restore. Values are of + the form + ``projects//instances//backups/``. + + This corresponds to the ``backup`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_database_v1.types.Database` + A Cloud Spanner database. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, database_id, backup]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_database_admin.RestoreDatabaseRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_database_admin.RestoreDatabaseRequest): + request = spanner_database_admin.RestoreDatabaseRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if database_id is not None: + request.database_id = database_id + if backup is not None: + request.backup = backup + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.restore_database] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + spanner_database_admin.Database, + metadata_type=spanner_database_admin.RestoreDatabaseMetadata, + ) + + # Done; return the response. + return response + + def list_database_operations(self, + request: Optional[Union[spanner_database_admin.ListDatabaseOperationsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListDatabaseOperationsPager: + r"""Lists database + [longrunning-operations][google.longrunning.Operation]. A + database operation has a name of the form + ``projects//instances//databases//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_list_database_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabaseOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_database_operations(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest, dict]): + The request object. The request for + [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. + parent (str): + Required. The instance of the database operations. + Values are of the form + ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseOperationsPager: + The response for + [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_database_admin.ListDatabaseOperationsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_database_admin.ListDatabaseOperationsRequest): + request = spanner_database_admin.ListDatabaseOperationsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_database_operations] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListDatabaseOperationsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_backup_operations(self, + request: Optional[Union[backup.ListBackupOperationsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListBackupOperationsPager: + r"""Lists the backup [long-running + operations][google.longrunning.Operation] in the given instance. + A backup operation has a name of the form + ``projects//instances//backups//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. Operations returned are ordered by + ``operation.metadata.value.progress.start_time`` in descending + order starting from the most recently started operation. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_list_backup_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backup_operations(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest, dict]): + The request object. The request for + [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. + parent (str): + Required. The instance of the backup operations. Values + are of the form + ``projects//instances/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupOperationsPager: + The response for + [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a backup.ListBackupOperationsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, backup.ListBackupOperationsRequest): + request = backup.ListBackupOperationsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_backup_operations] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListBackupOperationsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_database_roles(self, + request: Optional[Union[spanner_database_admin.ListDatabaseRolesRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListDatabaseRolesPager: + r"""Lists Cloud Spanner database roles. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_list_database_roles(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabaseRolesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_database_roles(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest, dict]): + The request object. The request for + [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. + parent (str): + Required. The database whose roles should be listed. + Values are of the form + ``projects//instances//databases//databaseRoles``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseRolesPager: + The response for + [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_database_admin.ListDatabaseRolesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_database_admin.ListDatabaseRolesRequest): + request = spanner_database_admin.ListDatabaseRolesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_database_roles] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListDatabaseRolesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self) -> "DatabaseAdminClient": + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: Optional[operations_pb2.ListOperationsRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def get_operation( + self, + request: Optional[operations_pb2.GetOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("name", request.name),)), + ) + + # Send the request. + response = rpc( + request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def delete_operation( + self, + request: Optional[operations_pb2.DeleteOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("name", request.name),)), + ) + + # Send the request. + rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + def cancel_operation( + self, + request: Optional[operations_pb2.CancelOperationRequest] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + Returns: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("name", request.name),)), + ) + + # Send the request. + rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + + + + + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + + +__all__ = ( + "DatabaseAdminClient", +) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py new file mode 100644 index 0000000000..67c2213658 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py @@ -0,0 +1,625 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from typing import Any, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator + +from google.cloud.spanner_admin_database_v1.types import backup +from google.cloud.spanner_admin_database_v1.types import spanner_database_admin +from google.longrunning import operations_pb2 # type: ignore + + +class ListDatabasesPager: + """A pager for iterating through ``list_databases`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_database_v1.types.ListDatabasesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``databases`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListDatabases`` requests and continue to iterate + through the ``databases`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListDatabasesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., spanner_database_admin.ListDatabasesResponse], + request: spanner_database_admin.ListDatabasesRequest, + response: spanner_database_admin.ListDatabasesResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest): + The initial request object. + response (google.cloud.spanner_admin_database_v1.types.ListDatabasesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner_database_admin.ListDatabasesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[spanner_database_admin.ListDatabasesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[spanner_database_admin.Database]: + for page in self.pages: + yield from page.databases + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListDatabasesAsyncPager: + """A pager for iterating through ``list_databases`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_database_v1.types.ListDatabasesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``databases`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListDatabases`` requests and continue to iterate + through the ``databases`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListDatabasesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., Awaitable[spanner_database_admin.ListDatabasesResponse]], + request: spanner_database_admin.ListDatabasesRequest, + response: spanner_database_admin.ListDatabasesResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest): + The initial request object. + response (google.cloud.spanner_admin_database_v1.types.ListDatabasesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner_database_admin.ListDatabasesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[spanner_database_admin.ListDatabasesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + def __aiter__(self) -> AsyncIterator[spanner_database_admin.Database]: + async def async_generator(): + async for page in self.pages: + for response in page.databases: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListBackupsPager: + """A pager for iterating through ``list_backups`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_database_v1.types.ListBackupsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``backups`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListBackups`` requests and continue to iterate + through the ``backups`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListBackupsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., backup.ListBackupsResponse], + request: backup.ListBackupsRequest, + response: backup.ListBackupsResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_database_v1.types.ListBackupsRequest): + The initial request object. + response (google.cloud.spanner_admin_database_v1.types.ListBackupsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = backup.ListBackupsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[backup.ListBackupsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[backup.Backup]: + for page in self.pages: + yield from page.backups + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListBackupsAsyncPager: + """A pager for iterating through ``list_backups`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_database_v1.types.ListBackupsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``backups`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListBackups`` requests and continue to iterate + through the ``backups`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListBackupsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., Awaitable[backup.ListBackupsResponse]], + request: backup.ListBackupsRequest, + response: backup.ListBackupsResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_database_v1.types.ListBackupsRequest): + The initial request object. + response (google.cloud.spanner_admin_database_v1.types.ListBackupsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = backup.ListBackupsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[backup.ListBackupsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + def __aiter__(self) -> AsyncIterator[backup.Backup]: + async def async_generator(): + async for page in self.pages: + for response in page.backups: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListDatabaseOperationsPager: + """A pager for iterating through ``list_database_operations`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``operations`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListDatabaseOperations`` requests and continue to iterate + through the ``operations`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., spanner_database_admin.ListDatabaseOperationsResponse], + request: spanner_database_admin.ListDatabaseOperationsRequest, + response: spanner_database_admin.ListDatabaseOperationsResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest): + The initial request object. + response (google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner_database_admin.ListDatabaseOperationsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[spanner_database_admin.ListDatabaseOperationsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[operations_pb2.Operation]: + for page in self.pages: + yield from page.operations + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListDatabaseOperationsAsyncPager: + """A pager for iterating through ``list_database_operations`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``operations`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListDatabaseOperations`` requests and continue to iterate + through the ``operations`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., Awaitable[spanner_database_admin.ListDatabaseOperationsResponse]], + request: spanner_database_admin.ListDatabaseOperationsRequest, + response: spanner_database_admin.ListDatabaseOperationsResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest): + The initial request object. + response (google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner_database_admin.ListDatabaseOperationsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[spanner_database_admin.ListDatabaseOperationsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + def __aiter__(self) -> AsyncIterator[operations_pb2.Operation]: + async def async_generator(): + async for page in self.pages: + for response in page.operations: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListBackupOperationsPager: + """A pager for iterating through ``list_backup_operations`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_database_v1.types.ListBackupOperationsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``operations`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListBackupOperations`` requests and continue to iterate + through the ``operations`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListBackupOperationsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., backup.ListBackupOperationsResponse], + request: backup.ListBackupOperationsRequest, + response: backup.ListBackupOperationsResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest): + The initial request object. + response (google.cloud.spanner_admin_database_v1.types.ListBackupOperationsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = backup.ListBackupOperationsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[backup.ListBackupOperationsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[operations_pb2.Operation]: + for page in self.pages: + yield from page.operations + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListBackupOperationsAsyncPager: + """A pager for iterating through ``list_backup_operations`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_database_v1.types.ListBackupOperationsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``operations`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListBackupOperations`` requests and continue to iterate + through the ``operations`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListBackupOperationsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., Awaitable[backup.ListBackupOperationsResponse]], + request: backup.ListBackupOperationsRequest, + response: backup.ListBackupOperationsResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest): + The initial request object. + response (google.cloud.spanner_admin_database_v1.types.ListBackupOperationsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = backup.ListBackupOperationsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[backup.ListBackupOperationsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + def __aiter__(self) -> AsyncIterator[operations_pb2.Operation]: + async def async_generator(): + async for page in self.pages: + for response in page.operations: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListDatabaseRolesPager: + """A pager for iterating through ``list_database_roles`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``database_roles`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListDatabaseRoles`` requests and continue to iterate + through the ``database_roles`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., spanner_database_admin.ListDatabaseRolesResponse], + request: spanner_database_admin.ListDatabaseRolesRequest, + response: spanner_database_admin.ListDatabaseRolesResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest): + The initial request object. + response (google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner_database_admin.ListDatabaseRolesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[spanner_database_admin.ListDatabaseRolesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[spanner_database_admin.DatabaseRole]: + for page in self.pages: + yield from page.database_roles + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListDatabaseRolesAsyncPager: + """A pager for iterating through ``list_database_roles`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``database_roles`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListDatabaseRoles`` requests and continue to iterate + through the ``database_roles`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., Awaitable[spanner_database_admin.ListDatabaseRolesResponse]], + request: spanner_database_admin.ListDatabaseRolesRequest, + response: spanner_database_admin.ListDatabaseRolesResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest): + The initial request object. + response (google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner_database_admin.ListDatabaseRolesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[spanner_database_admin.ListDatabaseRolesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + def __aiter__(self) -> AsyncIterator[spanner_database_admin.DatabaseRole]: + async def async_generator(): + async for page in self.pages: + for response in page.database_roles: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py new file mode 100644 index 0000000000..1a310698cc --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from typing import Dict, Type + +from .base import DatabaseAdminTransport +from .grpc import DatabaseAdminGrpcTransport +from .grpc_asyncio import DatabaseAdminGrpcAsyncIOTransport +from .rest import DatabaseAdminRestTransport +from .rest import DatabaseAdminRestInterceptor + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[DatabaseAdminTransport]] +_transport_registry['grpc'] = DatabaseAdminGrpcTransport +_transport_registry['grpc_asyncio'] = DatabaseAdminGrpcAsyncIOTransport +_transport_registry['rest'] = DatabaseAdminRestTransport + +__all__ = ( + 'DatabaseAdminTransport', + 'DatabaseAdminGrpcTransport', + 'DatabaseAdminGrpcAsyncIOTransport', + 'DatabaseAdminRestTransport', + 'DatabaseAdminRestInterceptor', +) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py new file mode 100644 index 0000000000..591d9a5768 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py @@ -0,0 +1,562 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union + +from google.cloud.spanner_admin_database_v1 import gapic_version as package_version + +import google.auth # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.spanner_admin_database_v1.types import backup +from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup +from google.cloud.spanner_admin_database_v1.types import spanner_database_admin +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + + +class DatabaseAdminTransport(abc.ABC): + """Abstract transport class for DatabaseAdmin.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.admin', + ) + + DEFAULT_HOST: str = 'spanner.googleapis.com' + def __init__( + self, *, + host: str = DEFAULT_HOST, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} + + # Save the scopes. + self._scopes = scopes + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, + **scopes_kwargs, + quota_project_id=quota_project_id + ) + elif credentials is None: + credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) + # Don't apply audience if the credentials file passed from user. + if hasattr(credentials, "with_gdch_audience"): + credentials = credentials.with_gdch_audience(api_audience if api_audience else host) + + # If the credentials are service account credentials, then always try to use self signed JWT. + if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ':' not in host: + host += ':443' + self._host = host + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.list_databases: gapic_v1.method.wrap_method( + self.list_databases, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.create_database: gapic_v1.method.wrap_method( + self.create_database, + default_timeout=3600.0, + client_info=client_info, + ), + self.get_database: gapic_v1.method.wrap_method( + self.get_database, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.update_database: gapic_v1.method.wrap_method( + self.update_database, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.update_database_ddl: gapic_v1.method.wrap_method( + self.update_database_ddl, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.drop_database: gapic_v1.method.wrap_method( + self.drop_database, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.get_database_ddl: gapic_v1.method.wrap_method( + self.get_database_ddl, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.set_iam_policy: gapic_v1.method.wrap_method( + self.set_iam_policy, + default_timeout=30.0, + client_info=client_info, + ), + self.get_iam_policy: gapic_v1.method.wrap_method( + self.get_iam_policy, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=client_info, + ), + self.test_iam_permissions: gapic_v1.method.wrap_method( + self.test_iam_permissions, + default_timeout=30.0, + client_info=client_info, + ), + self.create_backup: gapic_v1.method.wrap_method( + self.create_backup, + default_timeout=3600.0, + client_info=client_info, + ), + self.copy_backup: gapic_v1.method.wrap_method( + self.copy_backup, + default_timeout=3600.0, + client_info=client_info, + ), + self.get_backup: gapic_v1.method.wrap_method( + self.get_backup, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.update_backup: gapic_v1.method.wrap_method( + self.update_backup, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.delete_backup: gapic_v1.method.wrap_method( + self.delete_backup, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.list_backups: gapic_v1.method.wrap_method( + self.list_backups, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.restore_database: gapic_v1.method.wrap_method( + self.restore_database, + default_timeout=3600.0, + client_info=client_info, + ), + self.list_database_operations: gapic_v1.method.wrap_method( + self.list_database_operations, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.list_backup_operations: gapic_v1.method.wrap_method( + self.list_backup_operations, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.list_database_roles: gapic_v1.method.wrap_method( + self.list_database_roles, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self): + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def list_databases(self) -> Callable[ + [spanner_database_admin.ListDatabasesRequest], + Union[ + spanner_database_admin.ListDatabasesResponse, + Awaitable[spanner_database_admin.ListDatabasesResponse] + ]]: + raise NotImplementedError() + + @property + def create_database(self) -> Callable[ + [spanner_database_admin.CreateDatabaseRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def get_database(self) -> Callable[ + [spanner_database_admin.GetDatabaseRequest], + Union[ + spanner_database_admin.Database, + Awaitable[spanner_database_admin.Database] + ]]: + raise NotImplementedError() + + @property + def update_database(self) -> Callable[ + [spanner_database_admin.UpdateDatabaseRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def update_database_ddl(self) -> Callable[ + [spanner_database_admin.UpdateDatabaseDdlRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def drop_database(self) -> Callable[ + [spanner_database_admin.DropDatabaseRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def get_database_ddl(self) -> Callable[ + [spanner_database_admin.GetDatabaseDdlRequest], + Union[ + spanner_database_admin.GetDatabaseDdlResponse, + Awaitable[spanner_database_admin.GetDatabaseDdlResponse] + ]]: + raise NotImplementedError() + + @property + def set_iam_policy(self) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[ + policy_pb2.Policy, + Awaitable[policy_pb2.Policy] + ]]: + raise NotImplementedError() + + @property + def get_iam_policy(self) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[ + policy_pb2.Policy, + Awaitable[policy_pb2.Policy] + ]]: + raise NotImplementedError() + + @property + def test_iam_permissions(self) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse] + ]]: + raise NotImplementedError() + + @property + def create_backup(self) -> Callable[ + [gsad_backup.CreateBackupRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def copy_backup(self) -> Callable[ + [backup.CopyBackupRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def get_backup(self) -> Callable[ + [backup.GetBackupRequest], + Union[ + backup.Backup, + Awaitable[backup.Backup] + ]]: + raise NotImplementedError() + + @property + def update_backup(self) -> Callable[ + [gsad_backup.UpdateBackupRequest], + Union[ + gsad_backup.Backup, + Awaitable[gsad_backup.Backup] + ]]: + raise NotImplementedError() + + @property + def delete_backup(self) -> Callable[ + [backup.DeleteBackupRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def list_backups(self) -> Callable[ + [backup.ListBackupsRequest], + Union[ + backup.ListBackupsResponse, + Awaitable[backup.ListBackupsResponse] + ]]: + raise NotImplementedError() + + @property + def restore_database(self) -> Callable[ + [spanner_database_admin.RestoreDatabaseRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def list_database_operations(self) -> Callable[ + [spanner_database_admin.ListDatabaseOperationsRequest], + Union[ + spanner_database_admin.ListDatabaseOperationsResponse, + Awaitable[spanner_database_admin.ListDatabaseOperationsResponse] + ]]: + raise NotImplementedError() + + @property + def list_backup_operations(self) -> Callable[ + [backup.ListBackupOperationsRequest], + Union[ + backup.ListBackupOperationsResponse, + Awaitable[backup.ListBackupOperationsResponse] + ]]: + raise NotImplementedError() + + @property + def list_database_roles(self) -> Callable[ + [spanner_database_admin.ListDatabaseRolesRequest], + Union[ + spanner_database_admin.ListDatabaseRolesResponse, + Awaitable[spanner_database_admin.ListDatabaseRolesResponse] + ]]: + raise NotImplementedError() + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[operations_pb2.ListOperationsResponse, Awaitable[operations_pb2.ListOperationsResponse]], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[ + [operations_pb2.CancelOperationRequest], + None, + ]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[ + [operations_pb2.DeleteOperationRequest], + None, + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + + +__all__ = ( + 'DatabaseAdminTransport', +) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py new file mode 100644 index 0000000000..002a37a5d3 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py @@ -0,0 +1,1015 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore + +from google.cloud.spanner_admin_database_v1.types import backup +from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup +from google.cloud.spanner_admin_database_v1.types import spanner_database_admin +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from .base import DatabaseAdminTransport, DEFAULT_CLIENT_INFO + + +class DatabaseAdminGrpcTransport(DatabaseAdminTransport): + """gRPC backend transport for DatabaseAdmin. + + Cloud Spanner Database Admin API + + The Cloud Spanner Database Admin API can be used to: + + - create, drop, and list databases + - update the schema of pre-existing databases + - create, delete and list backups for a database + - restore a database from an existing backup + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + _stubs: Dict[str, Callable] + + def __init__(self, *, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[grpc.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel(cls, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service. + """ + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def list_databases(self) -> Callable[ + [spanner_database_admin.ListDatabasesRequest], + spanner_database_admin.ListDatabasesResponse]: + r"""Return a callable for the list databases method over gRPC. + + Lists Cloud Spanner databases. + + Returns: + Callable[[~.ListDatabasesRequest], + ~.ListDatabasesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_databases' not in self._stubs: + self._stubs['list_databases'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/ListDatabases', + request_serializer=spanner_database_admin.ListDatabasesRequest.serialize, + response_deserializer=spanner_database_admin.ListDatabasesResponse.deserialize, + ) + return self._stubs['list_databases'] + + @property + def create_database(self) -> Callable[ + [spanner_database_admin.CreateDatabaseRequest], + operations_pb2.Operation]: + r"""Return a callable for the create database method over gRPC. + + Creates a new Cloud Spanner database and starts to prepare it + for serving. The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and can be + used to track preparation of the database. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateDatabaseMetadata][google.spanner.admin.database.v1.CreateDatabaseMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Database][google.spanner.admin.database.v1.Database], if + successful. + + Returns: + Callable[[~.CreateDatabaseRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'create_database' not in self._stubs: + self._stubs['create_database'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/CreateDatabase', + request_serializer=spanner_database_admin.CreateDatabaseRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['create_database'] + + @property + def get_database(self) -> Callable[ + [spanner_database_admin.GetDatabaseRequest], + spanner_database_admin.Database]: + r"""Return a callable for the get database method over gRPC. + + Gets the state of a Cloud Spanner database. + + Returns: + Callable[[~.GetDatabaseRequest], + ~.Database]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_database' not in self._stubs: + self._stubs['get_database'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/GetDatabase', + request_serializer=spanner_database_admin.GetDatabaseRequest.serialize, + response_deserializer=spanner_database_admin.Database.deserialize, + ) + return self._stubs['get_database'] + + @property + def update_database(self) -> Callable[ + [spanner_database_admin.UpdateDatabaseRequest], + operations_pb2.Operation]: + r"""Return a callable for the update database method over gRPC. + + Updates a Cloud Spanner database. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the database. If the named database + does not exist, returns ``NOT_FOUND``. + + While the operation is pending: + + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field is set to true. + - Cancelling the operation is best-effort. If the cancellation + succeeds, the operation metadata's + [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] + is set, the updates are reverted, and the operation + terminates with a ``CANCELLED`` status. + - New UpdateDatabase requests will return a + ``FAILED_PRECONDITION`` error until the pending operation is + done (returns successfully or with error). + - Reading the database via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - The new values are in effect and readable via the API. + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format + ``projects//instances//databases//operations/`` + and can be used to track the database modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Database][google.spanner.admin.database.v1.Database], if + successful. + + Returns: + Callable[[~.UpdateDatabaseRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'update_database' not in self._stubs: + self._stubs['update_database'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/UpdateDatabase', + request_serializer=spanner_database_admin.UpdateDatabaseRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['update_database'] + + @property + def update_database_ddl(self) -> Callable[ + [spanner_database_admin.UpdateDatabaseDdlRequest], + operations_pb2.Operation]: + r"""Return a callable for the update database ddl method over gRPC. + + Updates the schema of a Cloud Spanner database by + creating/altering/dropping tables, columns, indexes, etc. The + returned [long-running operation][google.longrunning.Operation] + will have a name of the format + ``/operations/`` and can be used to + track execution of the schema change(s). The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateDatabaseDdlMetadata][google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata]. + The operation has no response. + + Returns: + Callable[[~.UpdateDatabaseDdlRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'update_database_ddl' not in self._stubs: + self._stubs['update_database_ddl'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/UpdateDatabaseDdl', + request_serializer=spanner_database_admin.UpdateDatabaseDdlRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['update_database_ddl'] + + @property + def drop_database(self) -> Callable[ + [spanner_database_admin.DropDatabaseRequest], + empty_pb2.Empty]: + r"""Return a callable for the drop database method over gRPC. + + Drops (aka deletes) a Cloud Spanner database. Completed backups + for the database will be retained according to their + ``expire_time``. Note: Cloud Spanner might continue to accept + requests for a few seconds after the database has been deleted. + + Returns: + Callable[[~.DropDatabaseRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'drop_database' not in self._stubs: + self._stubs['drop_database'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/DropDatabase', + request_serializer=spanner_database_admin.DropDatabaseRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['drop_database'] + + @property + def get_database_ddl(self) -> Callable[ + [spanner_database_admin.GetDatabaseDdlRequest], + spanner_database_admin.GetDatabaseDdlResponse]: + r"""Return a callable for the get database ddl method over gRPC. + + Returns the schema of a Cloud Spanner database as a list of + formatted DDL statements. This method does not show pending + schema updates, those may be queried using the + [Operations][google.longrunning.Operations] API. + + Returns: + Callable[[~.GetDatabaseDdlRequest], + ~.GetDatabaseDdlResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_database_ddl' not in self._stubs: + self._stubs['get_database_ddl'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/GetDatabaseDdl', + request_serializer=spanner_database_admin.GetDatabaseDdlRequest.serialize, + response_deserializer=spanner_database_admin.GetDatabaseDdlResponse.deserialize, + ) + return self._stubs['get_database_ddl'] + + @property + def set_iam_policy(self) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + + Sets the access control policy on a database or backup resource. + Replaces any existing policy. + + Authorization requires ``spanner.databases.setIamPolicy`` + permission on + [resource][google.iam.v1.SetIamPolicyRequest.resource]. For + backups, authorization requires ``spanner.backups.setIamPolicy`` + permission on + [resource][google.iam.v1.SetIamPolicyRequest.resource]. + + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'set_iam_policy' not in self._stubs: + self._stubs['set_iam_policy'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/SetIamPolicy', + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs['set_iam_policy'] + + @property + def get_iam_policy(self) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + + Gets the access control policy for a database or backup + resource. Returns an empty policy if a database or backup exists + but does not have a policy set. + + Authorization requires ``spanner.databases.getIamPolicy`` + permission on + [resource][google.iam.v1.GetIamPolicyRequest.resource]. For + backups, authorization requires ``spanner.backups.getIamPolicy`` + permission on + [resource][google.iam.v1.GetIamPolicyRequest.resource]. + + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_iam_policy' not in self._stubs: + self._stubs['get_iam_policy'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/GetIamPolicy', + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs['get_iam_policy'] + + @property + def test_iam_permissions(self) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse]: + r"""Return a callable for the test iam permissions method over gRPC. + + Returns permissions that the caller has on the specified + database or backup resource. + + Attempting this RPC on a non-existent Cloud Spanner database + will result in a NOT_FOUND error if the user has + ``spanner.databases.list`` permission on the containing Cloud + Spanner instance. Otherwise returns an empty set of permissions. + Calling this method on a backup that does not exist will result + in a NOT_FOUND error if the user has ``spanner.backups.list`` + permission on the containing instance. + + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'test_iam_permissions' not in self._stubs: + self._stubs['test_iam_permissions'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/TestIamPermissions', + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs['test_iam_permissions'] + + @property + def create_backup(self) -> Callable[ + [gsad_backup.CreateBackupRequest], + operations_pb2.Operation]: + r"""Return a callable for the create backup method over gRPC. + + Starts creating a new Cloud Spanner Backup. The returned backup + [long-running operation][google.longrunning.Operation] will have + a name of the format + ``projects//instances//backups//operations/`` + and can be used to track creation of the backup. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Backup][google.spanner.admin.database.v1.Backup], if + successful. Cancelling the returned operation will stop the + creation and delete the backup. There can be only one pending + backup creation per database. Backup creation of different + databases can run concurrently. + + Returns: + Callable[[~.CreateBackupRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'create_backup' not in self._stubs: + self._stubs['create_backup'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/CreateBackup', + request_serializer=gsad_backup.CreateBackupRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['create_backup'] + + @property + def copy_backup(self) -> Callable[ + [backup.CopyBackupRequest], + operations_pb2.Operation]: + r"""Return a callable for the copy backup method over gRPC. + + Starts copying a Cloud Spanner Backup. The returned backup + [long-running operation][google.longrunning.Operation] will have + a name of the format + ``projects//instances//backups//operations/`` + and can be used to track copying of the backup. The operation is + associated with the destination backup. The + [metadata][google.longrunning.Operation.metadata] field type is + [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Backup][google.spanner.admin.database.v1.Backup], if + successful. Cancelling the returned operation will stop the + copying and delete the backup. Concurrent CopyBackup requests + can run on the same source backup. + + Returns: + Callable[[~.CopyBackupRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'copy_backup' not in self._stubs: + self._stubs['copy_backup'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/CopyBackup', + request_serializer=backup.CopyBackupRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['copy_backup'] + + @property + def get_backup(self) -> Callable[ + [backup.GetBackupRequest], + backup.Backup]: + r"""Return a callable for the get backup method over gRPC. + + Gets metadata on a pending or completed + [Backup][google.spanner.admin.database.v1.Backup]. + + Returns: + Callable[[~.GetBackupRequest], + ~.Backup]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_backup' not in self._stubs: + self._stubs['get_backup'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/GetBackup', + request_serializer=backup.GetBackupRequest.serialize, + response_deserializer=backup.Backup.deserialize, + ) + return self._stubs['get_backup'] + + @property + def update_backup(self) -> Callable[ + [gsad_backup.UpdateBackupRequest], + gsad_backup.Backup]: + r"""Return a callable for the update backup method over gRPC. + + Updates a pending or completed + [Backup][google.spanner.admin.database.v1.Backup]. + + Returns: + Callable[[~.UpdateBackupRequest], + ~.Backup]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'update_backup' not in self._stubs: + self._stubs['update_backup'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/UpdateBackup', + request_serializer=gsad_backup.UpdateBackupRequest.serialize, + response_deserializer=gsad_backup.Backup.deserialize, + ) + return self._stubs['update_backup'] + + @property + def delete_backup(self) -> Callable[ + [backup.DeleteBackupRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete backup method over gRPC. + + Deletes a pending or completed + [Backup][google.spanner.admin.database.v1.Backup]. + + Returns: + Callable[[~.DeleteBackupRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'delete_backup' not in self._stubs: + self._stubs['delete_backup'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/DeleteBackup', + request_serializer=backup.DeleteBackupRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_backup'] + + @property + def list_backups(self) -> Callable[ + [backup.ListBackupsRequest], + backup.ListBackupsResponse]: + r"""Return a callable for the list backups method over gRPC. + + Lists completed and pending backups. Backups returned are + ordered by ``create_time`` in descending order, starting from + the most recent ``create_time``. + + Returns: + Callable[[~.ListBackupsRequest], + ~.ListBackupsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_backups' not in self._stubs: + self._stubs['list_backups'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/ListBackups', + request_serializer=backup.ListBackupsRequest.serialize, + response_deserializer=backup.ListBackupsResponse.deserialize, + ) + return self._stubs['list_backups'] + + @property + def restore_database(self) -> Callable[ + [spanner_database_admin.RestoreDatabaseRequest], + operations_pb2.Operation]: + r"""Return a callable for the restore database method over gRPC. + + Create a new database by restoring from a completed backup. The + new database must be in the same project and in an instance with + the same instance configuration as the instance containing the + backup. The returned database [long-running + operation][google.longrunning.Operation] has a name of the + format + ``projects//instances//databases//operations/``, + and can be used to track the progress of the operation, and to + cancel it. The [metadata][google.longrunning.Operation.metadata] + field type is + [RestoreDatabaseMetadata][google.spanner.admin.database.v1.RestoreDatabaseMetadata]. + The [response][google.longrunning.Operation.response] type is + [Database][google.spanner.admin.database.v1.Database], if + successful. Cancelling the returned operation will stop the + restore and delete the database. There can be only one database + being restored into an instance at a time. Once the restore + operation completes, a new restore operation can be initiated, + without waiting for the optimize operation associated with the + first restore to complete. + + Returns: + Callable[[~.RestoreDatabaseRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'restore_database' not in self._stubs: + self._stubs['restore_database'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/RestoreDatabase', + request_serializer=spanner_database_admin.RestoreDatabaseRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['restore_database'] + + @property + def list_database_operations(self) -> Callable[ + [spanner_database_admin.ListDatabaseOperationsRequest], + spanner_database_admin.ListDatabaseOperationsResponse]: + r"""Return a callable for the list database operations method over gRPC. + + Lists database + [longrunning-operations][google.longrunning.Operation]. A + database operation has a name of the form + ``projects//instances//databases//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. + + Returns: + Callable[[~.ListDatabaseOperationsRequest], + ~.ListDatabaseOperationsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_database_operations' not in self._stubs: + self._stubs['list_database_operations'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/ListDatabaseOperations', + request_serializer=spanner_database_admin.ListDatabaseOperationsRequest.serialize, + response_deserializer=spanner_database_admin.ListDatabaseOperationsResponse.deserialize, + ) + return self._stubs['list_database_operations'] + + @property + def list_backup_operations(self) -> Callable[ + [backup.ListBackupOperationsRequest], + backup.ListBackupOperationsResponse]: + r"""Return a callable for the list backup operations method over gRPC. + + Lists the backup [long-running + operations][google.longrunning.Operation] in the given instance. + A backup operation has a name of the form + ``projects//instances//backups//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. Operations returned are ordered by + ``operation.metadata.value.progress.start_time`` in descending + order starting from the most recently started operation. + + Returns: + Callable[[~.ListBackupOperationsRequest], + ~.ListBackupOperationsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_backup_operations' not in self._stubs: + self._stubs['list_backup_operations'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/ListBackupOperations', + request_serializer=backup.ListBackupOperationsRequest.serialize, + response_deserializer=backup.ListBackupOperationsResponse.deserialize, + ) + return self._stubs['list_backup_operations'] + + @property + def list_database_roles(self) -> Callable[ + [spanner_database_admin.ListDatabaseRolesRequest], + spanner_database_admin.ListDatabaseRolesResponse]: + r"""Return a callable for the list database roles method over gRPC. + + Lists Cloud Spanner database roles. + + Returns: + Callable[[~.ListDatabaseRolesRequest], + ~.ListDatabaseRolesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_database_roles' not in self._stubs: + self._stubs['list_database_roles'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/ListDatabaseRoles', + request_serializer=spanner_database_admin.ListDatabaseRolesRequest.serialize, + response_deserializer=spanner_database_admin.ListDatabaseRolesResponse.deserialize, + ) + return self._stubs['list_database_roles'] + + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[[operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse]: + r"""Return a callable for the list_operations method over gRPC. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def kind(self) -> str: + return "grpc" + + +__all__ = ( + 'DatabaseAdminGrpcTransport', +) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py new file mode 100644 index 0000000000..6942dd3a30 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py @@ -0,0 +1,1014 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.spanner_admin_database_v1.types import backup +from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup +from google.cloud.spanner_admin_database_v1.types import spanner_database_admin +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from .base import DatabaseAdminTransport, DEFAULT_CLIENT_INFO +from .grpc import DatabaseAdminGrpcTransport + + +class DatabaseAdminGrpcAsyncIOTransport(DatabaseAdminTransport): + """gRPC AsyncIO backend transport for DatabaseAdmin. + + Cloud Spanner Database Admin API + + The Cloud Spanner Database Admin API can be used to: + + - create, drop, and list databases + - update the schema of pre-existing databases + - create, delete and list backups for a database + - restore a database from an existing backup + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel(cls, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + def __init__(self, *, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[aio.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsAsyncClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def list_databases(self) -> Callable[ + [spanner_database_admin.ListDatabasesRequest], + Awaitable[spanner_database_admin.ListDatabasesResponse]]: + r"""Return a callable for the list databases method over gRPC. + + Lists Cloud Spanner databases. + + Returns: + Callable[[~.ListDatabasesRequest], + Awaitable[~.ListDatabasesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_databases' not in self._stubs: + self._stubs['list_databases'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/ListDatabases', + request_serializer=spanner_database_admin.ListDatabasesRequest.serialize, + response_deserializer=spanner_database_admin.ListDatabasesResponse.deserialize, + ) + return self._stubs['list_databases'] + + @property + def create_database(self) -> Callable[ + [spanner_database_admin.CreateDatabaseRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the create database method over gRPC. + + Creates a new Cloud Spanner database and starts to prepare it + for serving. The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and can be + used to track preparation of the database. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateDatabaseMetadata][google.spanner.admin.database.v1.CreateDatabaseMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Database][google.spanner.admin.database.v1.Database], if + successful. + + Returns: + Callable[[~.CreateDatabaseRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'create_database' not in self._stubs: + self._stubs['create_database'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/CreateDatabase', + request_serializer=spanner_database_admin.CreateDatabaseRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['create_database'] + + @property + def get_database(self) -> Callable[ + [spanner_database_admin.GetDatabaseRequest], + Awaitable[spanner_database_admin.Database]]: + r"""Return a callable for the get database method over gRPC. + + Gets the state of a Cloud Spanner database. + + Returns: + Callable[[~.GetDatabaseRequest], + Awaitable[~.Database]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_database' not in self._stubs: + self._stubs['get_database'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/GetDatabase', + request_serializer=spanner_database_admin.GetDatabaseRequest.serialize, + response_deserializer=spanner_database_admin.Database.deserialize, + ) + return self._stubs['get_database'] + + @property + def update_database(self) -> Callable[ + [spanner_database_admin.UpdateDatabaseRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the update database method over gRPC. + + Updates a Cloud Spanner database. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the database. If the named database + does not exist, returns ``NOT_FOUND``. + + While the operation is pending: + + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field is set to true. + - Cancelling the operation is best-effort. If the cancellation + succeeds, the operation metadata's + [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] + is set, the updates are reverted, and the operation + terminates with a ``CANCELLED`` status. + - New UpdateDatabase requests will return a + ``FAILED_PRECONDITION`` error until the pending operation is + done (returns successfully or with error). + - Reading the database via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - The new values are in effect and readable via the API. + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format + ``projects//instances//databases//operations/`` + and can be used to track the database modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Database][google.spanner.admin.database.v1.Database], if + successful. + + Returns: + Callable[[~.UpdateDatabaseRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'update_database' not in self._stubs: + self._stubs['update_database'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/UpdateDatabase', + request_serializer=spanner_database_admin.UpdateDatabaseRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['update_database'] + + @property + def update_database_ddl(self) -> Callable[ + [spanner_database_admin.UpdateDatabaseDdlRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the update database ddl method over gRPC. + + Updates the schema of a Cloud Spanner database by + creating/altering/dropping tables, columns, indexes, etc. The + returned [long-running operation][google.longrunning.Operation] + will have a name of the format + ``/operations/`` and can be used to + track execution of the schema change(s). The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateDatabaseDdlMetadata][google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata]. + The operation has no response. + + Returns: + Callable[[~.UpdateDatabaseDdlRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'update_database_ddl' not in self._stubs: + self._stubs['update_database_ddl'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/UpdateDatabaseDdl', + request_serializer=spanner_database_admin.UpdateDatabaseDdlRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['update_database_ddl'] + + @property + def drop_database(self) -> Callable[ + [spanner_database_admin.DropDatabaseRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the drop database method over gRPC. + + Drops (aka deletes) a Cloud Spanner database. Completed backups + for the database will be retained according to their + ``expire_time``. Note: Cloud Spanner might continue to accept + requests for a few seconds after the database has been deleted. + + Returns: + Callable[[~.DropDatabaseRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'drop_database' not in self._stubs: + self._stubs['drop_database'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/DropDatabase', + request_serializer=spanner_database_admin.DropDatabaseRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['drop_database'] + + @property + def get_database_ddl(self) -> Callable[ + [spanner_database_admin.GetDatabaseDdlRequest], + Awaitable[spanner_database_admin.GetDatabaseDdlResponse]]: + r"""Return a callable for the get database ddl method over gRPC. + + Returns the schema of a Cloud Spanner database as a list of + formatted DDL statements. This method does not show pending + schema updates, those may be queried using the + [Operations][google.longrunning.Operations] API. + + Returns: + Callable[[~.GetDatabaseDdlRequest], + Awaitable[~.GetDatabaseDdlResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_database_ddl' not in self._stubs: + self._stubs['get_database_ddl'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/GetDatabaseDdl', + request_serializer=spanner_database_admin.GetDatabaseDdlRequest.serialize, + response_deserializer=spanner_database_admin.GetDatabaseDdlResponse.deserialize, + ) + return self._stubs['get_database_ddl'] + + @property + def set_iam_policy(self) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Awaitable[policy_pb2.Policy]]: + r"""Return a callable for the set iam policy method over gRPC. + + Sets the access control policy on a database or backup resource. + Replaces any existing policy. + + Authorization requires ``spanner.databases.setIamPolicy`` + permission on + [resource][google.iam.v1.SetIamPolicyRequest.resource]. For + backups, authorization requires ``spanner.backups.setIamPolicy`` + permission on + [resource][google.iam.v1.SetIamPolicyRequest.resource]. + + Returns: + Callable[[~.SetIamPolicyRequest], + Awaitable[~.Policy]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'set_iam_policy' not in self._stubs: + self._stubs['set_iam_policy'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/SetIamPolicy', + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs['set_iam_policy'] + + @property + def get_iam_policy(self) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Awaitable[policy_pb2.Policy]]: + r"""Return a callable for the get iam policy method over gRPC. + + Gets the access control policy for a database or backup + resource. Returns an empty policy if a database or backup exists + but does not have a policy set. + + Authorization requires ``spanner.databases.getIamPolicy`` + permission on + [resource][google.iam.v1.GetIamPolicyRequest.resource]. For + backups, authorization requires ``spanner.backups.getIamPolicy`` + permission on + [resource][google.iam.v1.GetIamPolicyRequest.resource]. + + Returns: + Callable[[~.GetIamPolicyRequest], + Awaitable[~.Policy]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_iam_policy' not in self._stubs: + self._stubs['get_iam_policy'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/GetIamPolicy', + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs['get_iam_policy'] + + @property + def test_iam_permissions(self) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Awaitable[iam_policy_pb2.TestIamPermissionsResponse]]: + r"""Return a callable for the test iam permissions method over gRPC. + + Returns permissions that the caller has on the specified + database or backup resource. + + Attempting this RPC on a non-existent Cloud Spanner database + will result in a NOT_FOUND error if the user has + ``spanner.databases.list`` permission on the containing Cloud + Spanner instance. Otherwise returns an empty set of permissions. + Calling this method on a backup that does not exist will result + in a NOT_FOUND error if the user has ``spanner.backups.list`` + permission on the containing instance. + + Returns: + Callable[[~.TestIamPermissionsRequest], + Awaitable[~.TestIamPermissionsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'test_iam_permissions' not in self._stubs: + self._stubs['test_iam_permissions'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/TestIamPermissions', + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs['test_iam_permissions'] + + @property + def create_backup(self) -> Callable[ + [gsad_backup.CreateBackupRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the create backup method over gRPC. + + Starts creating a new Cloud Spanner Backup. The returned backup + [long-running operation][google.longrunning.Operation] will have + a name of the format + ``projects//instances//backups//operations/`` + and can be used to track creation of the backup. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Backup][google.spanner.admin.database.v1.Backup], if + successful. Cancelling the returned operation will stop the + creation and delete the backup. There can be only one pending + backup creation per database. Backup creation of different + databases can run concurrently. + + Returns: + Callable[[~.CreateBackupRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'create_backup' not in self._stubs: + self._stubs['create_backup'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/CreateBackup', + request_serializer=gsad_backup.CreateBackupRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['create_backup'] + + @property + def copy_backup(self) -> Callable[ + [backup.CopyBackupRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the copy backup method over gRPC. + + Starts copying a Cloud Spanner Backup. The returned backup + [long-running operation][google.longrunning.Operation] will have + a name of the format + ``projects//instances//backups//operations/`` + and can be used to track copying of the backup. The operation is + associated with the destination backup. The + [metadata][google.longrunning.Operation.metadata] field type is + [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Backup][google.spanner.admin.database.v1.Backup], if + successful. Cancelling the returned operation will stop the + copying and delete the backup. Concurrent CopyBackup requests + can run on the same source backup. + + Returns: + Callable[[~.CopyBackupRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'copy_backup' not in self._stubs: + self._stubs['copy_backup'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/CopyBackup', + request_serializer=backup.CopyBackupRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['copy_backup'] + + @property + def get_backup(self) -> Callable[ + [backup.GetBackupRequest], + Awaitable[backup.Backup]]: + r"""Return a callable for the get backup method over gRPC. + + Gets metadata on a pending or completed + [Backup][google.spanner.admin.database.v1.Backup]. + + Returns: + Callable[[~.GetBackupRequest], + Awaitable[~.Backup]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_backup' not in self._stubs: + self._stubs['get_backup'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/GetBackup', + request_serializer=backup.GetBackupRequest.serialize, + response_deserializer=backup.Backup.deserialize, + ) + return self._stubs['get_backup'] + + @property + def update_backup(self) -> Callable[ + [gsad_backup.UpdateBackupRequest], + Awaitable[gsad_backup.Backup]]: + r"""Return a callable for the update backup method over gRPC. + + Updates a pending or completed + [Backup][google.spanner.admin.database.v1.Backup]. + + Returns: + Callable[[~.UpdateBackupRequest], + Awaitable[~.Backup]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'update_backup' not in self._stubs: + self._stubs['update_backup'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/UpdateBackup', + request_serializer=gsad_backup.UpdateBackupRequest.serialize, + response_deserializer=gsad_backup.Backup.deserialize, + ) + return self._stubs['update_backup'] + + @property + def delete_backup(self) -> Callable[ + [backup.DeleteBackupRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete backup method over gRPC. + + Deletes a pending or completed + [Backup][google.spanner.admin.database.v1.Backup]. + + Returns: + Callable[[~.DeleteBackupRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'delete_backup' not in self._stubs: + self._stubs['delete_backup'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/DeleteBackup', + request_serializer=backup.DeleteBackupRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_backup'] + + @property + def list_backups(self) -> Callable[ + [backup.ListBackupsRequest], + Awaitable[backup.ListBackupsResponse]]: + r"""Return a callable for the list backups method over gRPC. + + Lists completed and pending backups. Backups returned are + ordered by ``create_time`` in descending order, starting from + the most recent ``create_time``. + + Returns: + Callable[[~.ListBackupsRequest], + Awaitable[~.ListBackupsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_backups' not in self._stubs: + self._stubs['list_backups'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/ListBackups', + request_serializer=backup.ListBackupsRequest.serialize, + response_deserializer=backup.ListBackupsResponse.deserialize, + ) + return self._stubs['list_backups'] + + @property + def restore_database(self) -> Callable[ + [spanner_database_admin.RestoreDatabaseRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the restore database method over gRPC. + + Create a new database by restoring from a completed backup. The + new database must be in the same project and in an instance with + the same instance configuration as the instance containing the + backup. The returned database [long-running + operation][google.longrunning.Operation] has a name of the + format + ``projects//instances//databases//operations/``, + and can be used to track the progress of the operation, and to + cancel it. The [metadata][google.longrunning.Operation.metadata] + field type is + [RestoreDatabaseMetadata][google.spanner.admin.database.v1.RestoreDatabaseMetadata]. + The [response][google.longrunning.Operation.response] type is + [Database][google.spanner.admin.database.v1.Database], if + successful. Cancelling the returned operation will stop the + restore and delete the database. There can be only one database + being restored into an instance at a time. Once the restore + operation completes, a new restore operation can be initiated, + without waiting for the optimize operation associated with the + first restore to complete. + + Returns: + Callable[[~.RestoreDatabaseRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'restore_database' not in self._stubs: + self._stubs['restore_database'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/RestoreDatabase', + request_serializer=spanner_database_admin.RestoreDatabaseRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['restore_database'] + + @property + def list_database_operations(self) -> Callable[ + [spanner_database_admin.ListDatabaseOperationsRequest], + Awaitable[spanner_database_admin.ListDatabaseOperationsResponse]]: + r"""Return a callable for the list database operations method over gRPC. + + Lists database + [longrunning-operations][google.longrunning.Operation]. A + database operation has a name of the form + ``projects//instances//databases//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. + + Returns: + Callable[[~.ListDatabaseOperationsRequest], + Awaitable[~.ListDatabaseOperationsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_database_operations' not in self._stubs: + self._stubs['list_database_operations'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/ListDatabaseOperations', + request_serializer=spanner_database_admin.ListDatabaseOperationsRequest.serialize, + response_deserializer=spanner_database_admin.ListDatabaseOperationsResponse.deserialize, + ) + return self._stubs['list_database_operations'] + + @property + def list_backup_operations(self) -> Callable[ + [backup.ListBackupOperationsRequest], + Awaitable[backup.ListBackupOperationsResponse]]: + r"""Return a callable for the list backup operations method over gRPC. + + Lists the backup [long-running + operations][google.longrunning.Operation] in the given instance. + A backup operation has a name of the form + ``projects//instances//backups//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. Operations returned are ordered by + ``operation.metadata.value.progress.start_time`` in descending + order starting from the most recently started operation. + + Returns: + Callable[[~.ListBackupOperationsRequest], + Awaitable[~.ListBackupOperationsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_backup_operations' not in self._stubs: + self._stubs['list_backup_operations'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/ListBackupOperations', + request_serializer=backup.ListBackupOperationsRequest.serialize, + response_deserializer=backup.ListBackupOperationsResponse.deserialize, + ) + return self._stubs['list_backup_operations'] + + @property + def list_database_roles(self) -> Callable[ + [spanner_database_admin.ListDatabaseRolesRequest], + Awaitable[spanner_database_admin.ListDatabaseRolesResponse]]: + r"""Return a callable for the list database roles method over gRPC. + + Lists Cloud Spanner database roles. + + Returns: + Callable[[~.ListDatabaseRolesRequest], + Awaitable[~.ListDatabaseRolesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_database_roles' not in self._stubs: + self._stubs['list_database_roles'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.database.v1.DatabaseAdmin/ListDatabaseRoles', + request_serializer=spanner_database_admin.ListDatabaseRolesRequest.serialize, + response_deserializer=spanner_database_admin.ListDatabaseRolesResponse.deserialize, + ) + return self._stubs['list_database_roles'] + + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[[operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse]: + r"""Return a callable for the list_operations method over gRPC. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + +__all__ = ( + 'DatabaseAdminGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py new file mode 100644 index 0000000000..ad9d98696f --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py @@ -0,0 +1,3132 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from google.auth.transport.requests import AuthorizedSession # type: ignore +import json # type: ignore +import grpc # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.api_core import exceptions as core_exceptions +from google.api_core import retry as retries +from google.api_core import rest_helpers +from google.api_core import rest_streaming +from google.api_core import path_template +from google.api_core import gapic_v1 + +from google.protobuf import json_format +from google.api_core import operations_v1 +from google.longrunning import operations_pb2 +from requests import __version__ as requests_version +import dataclasses +import re +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +import warnings + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + + +from google.cloud.spanner_admin_database_v1.types import backup +from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup +from google.cloud.spanner_admin_database_v1.types import spanner_database_admin +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore + +from .base import DatabaseAdminTransport, DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, + grpc_version=None, + rest_version=requests_version, +) + + +class DatabaseAdminRestInterceptor: + """Interceptor for DatabaseAdmin. + + Interceptors are used to manipulate requests, request metadata, and responses + in arbitrary ways. + Example use cases include: + * Logging + * Verifying requests according to service or custom semantics + * Stripping extraneous information from responses + + These use cases and more can be enabled by injecting an + instance of a custom subclass when constructing the DatabaseAdminRestTransport. + + .. code-block:: python + class MyCustomDatabaseAdminInterceptor(DatabaseAdminRestInterceptor): + def pre_copy_backup(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_copy_backup(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_create_backup(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_create_backup(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_create_database(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_create_database(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_delete_backup(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def pre_drop_database(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def pre_get_backup(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_backup(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_get_database(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_database(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_get_database_ddl(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_database_ddl(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_get_iam_policy(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_iam_policy(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_list_backup_operations(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_backup_operations(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_list_backups(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_backups(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_list_database_operations(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_database_operations(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_list_database_roles(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_database_roles(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_list_databases(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_databases(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_restore_database(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_restore_database(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_set_iam_policy(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_set_iam_policy(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_test_iam_permissions(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_test_iam_permissions(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_update_backup(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_update_backup(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_update_database(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_update_database(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_update_database_ddl(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_update_database_ddl(self, response): + logging.log(f"Received response: {response}") + return response + + transport = DatabaseAdminRestTransport(interceptor=MyCustomDatabaseAdminInterceptor()) + client = DatabaseAdminClient(transport=transport) + + + """ + def pre_copy_backup(self, request: backup.CopyBackupRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[backup.CopyBackupRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for copy_backup + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_copy_backup(self, response: operations_pb2.Operation) -> operations_pb2.Operation: + """Post-rpc interceptor for copy_backup + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_create_backup(self, request: gsad_backup.CreateBackupRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[gsad_backup.CreateBackupRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for create_backup + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_create_backup(self, response: operations_pb2.Operation) -> operations_pb2.Operation: + """Post-rpc interceptor for create_backup + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_create_database(self, request: spanner_database_admin.CreateDatabaseRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.CreateDatabaseRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for create_database + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_create_database(self, response: operations_pb2.Operation) -> operations_pb2.Operation: + """Post-rpc interceptor for create_database + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_delete_backup(self, request: backup.DeleteBackupRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[backup.DeleteBackupRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for delete_backup + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def pre_drop_database(self, request: spanner_database_admin.DropDatabaseRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.DropDatabaseRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for drop_database + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def pre_get_backup(self, request: backup.GetBackupRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[backup.GetBackupRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for get_backup + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_get_backup(self, response: backup.Backup) -> backup.Backup: + """Post-rpc interceptor for get_backup + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_get_database(self, request: spanner_database_admin.GetDatabaseRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.GetDatabaseRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for get_database + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_get_database(self, response: spanner_database_admin.Database) -> spanner_database_admin.Database: + """Post-rpc interceptor for get_database + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_get_database_ddl(self, request: spanner_database_admin.GetDatabaseDdlRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.GetDatabaseDdlRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for get_database_ddl + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_get_database_ddl(self, response: spanner_database_admin.GetDatabaseDdlResponse) -> spanner_database_admin.GetDatabaseDdlResponse: + """Post-rpc interceptor for get_database_ddl + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_get_iam_policy(self, request: iam_policy_pb2.GetIamPolicyRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for get_iam_policy + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_get_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: + """Post-rpc interceptor for get_iam_policy + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_list_backup_operations(self, request: backup.ListBackupOperationsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[backup.ListBackupOperationsRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for list_backup_operations + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_list_backup_operations(self, response: backup.ListBackupOperationsResponse) -> backup.ListBackupOperationsResponse: + """Post-rpc interceptor for list_backup_operations + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_list_backups(self, request: backup.ListBackupsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[backup.ListBackupsRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for list_backups + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_list_backups(self, response: backup.ListBackupsResponse) -> backup.ListBackupsResponse: + """Post-rpc interceptor for list_backups + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_list_database_operations(self, request: spanner_database_admin.ListDatabaseOperationsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.ListDatabaseOperationsRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for list_database_operations + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_list_database_operations(self, response: spanner_database_admin.ListDatabaseOperationsResponse) -> spanner_database_admin.ListDatabaseOperationsResponse: + """Post-rpc interceptor for list_database_operations + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_list_database_roles(self, request: spanner_database_admin.ListDatabaseRolesRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.ListDatabaseRolesRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for list_database_roles + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_list_database_roles(self, response: spanner_database_admin.ListDatabaseRolesResponse) -> spanner_database_admin.ListDatabaseRolesResponse: + """Post-rpc interceptor for list_database_roles + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_list_databases(self, request: spanner_database_admin.ListDatabasesRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.ListDatabasesRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for list_databases + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_list_databases(self, response: spanner_database_admin.ListDatabasesResponse) -> spanner_database_admin.ListDatabasesResponse: + """Post-rpc interceptor for list_databases + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_restore_database(self, request: spanner_database_admin.RestoreDatabaseRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.RestoreDatabaseRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for restore_database + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_restore_database(self, response: operations_pb2.Operation) -> operations_pb2.Operation: + """Post-rpc interceptor for restore_database + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_set_iam_policy(self, request: iam_policy_pb2.SetIamPolicyRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for set_iam_policy + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_set_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: + """Post-rpc interceptor for set_iam_policy + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_test_iam_permissions(self, request: iam_policy_pb2.TestIamPermissionsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[iam_policy_pb2.TestIamPermissionsRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for test_iam_permissions + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_test_iam_permissions(self, response: iam_policy_pb2.TestIamPermissionsResponse) -> iam_policy_pb2.TestIamPermissionsResponse: + """Post-rpc interceptor for test_iam_permissions + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_update_backup(self, request: gsad_backup.UpdateBackupRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[gsad_backup.UpdateBackupRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for update_backup + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_update_backup(self, response: gsad_backup.Backup) -> gsad_backup.Backup: + """Post-rpc interceptor for update_backup + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_update_database(self, request: spanner_database_admin.UpdateDatabaseRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.UpdateDatabaseRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for update_database + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_update_database(self, response: operations_pb2.Operation) -> operations_pb2.Operation: + """Post-rpc interceptor for update_database + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_update_database_ddl(self, request: spanner_database_admin.UpdateDatabaseDdlRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.UpdateDatabaseDdlRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for update_database_ddl + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_update_database_ddl(self, response: operations_pb2.Operation) -> operations_pb2.Operation: + """Post-rpc interceptor for update_database_ddl + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + + def pre_cancel_operation( + self, request: operations_pb2.CancelOperationRequest, metadata: Sequence[Tuple[str, str]] + ) -> Tuple[operations_pb2.CancelOperationRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_cancel_operation( + self, response: None + ) -> None: + """Post-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_delete_operation( + self, request: operations_pb2.DeleteOperationRequest, metadata: Sequence[Tuple[str, str]] + ) -> Tuple[operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for delete_operation + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_delete_operation( + self, response: None + ) -> None: + """Post-rpc interceptor for delete_operation + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_get_operation( + self, request: operations_pb2.GetOperationRequest, metadata: Sequence[Tuple[str, str]] + ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for get_operation + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_get_operation( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for get_operation + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_list_operations( + self, request: operations_pb2.ListOperationsRequest, metadata: Sequence[Tuple[str, str]] + ) -> Tuple[operations_pb2.ListOperationsRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for list_operations + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_list_operations( + self, response: operations_pb2.ListOperationsResponse + ) -> operations_pb2.ListOperationsResponse: + """Post-rpc interceptor for list_operations + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + + +@dataclasses.dataclass +class DatabaseAdminRestStub: + _session: AuthorizedSession + _host: str + _interceptor: DatabaseAdminRestInterceptor + + +class DatabaseAdminRestTransport(DatabaseAdminTransport): + """REST backend transport for DatabaseAdmin. + + Cloud Spanner Database Admin API + + The Cloud Spanner Database Admin API can be used to: + + - create, drop, and list databases + - update the schema of pre-existing databases + - create, delete and list backups for a database + - restore a database from an existing backup + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends JSON representations of protocol buffers over HTTP/1.1 + + """ + + def __init__(self, *, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + client_cert_source_for_mtls: Optional[Callable[[ + ], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = 'https', + interceptor: Optional[DatabaseAdminRestInterceptor] = None, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client + certificate to configure mutual TLS HTTP channel. It is ignored + if ``channel`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you are developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + url_scheme: the protocol scheme for the API endpoint. Normally + "https", but for testing or local servers, + "http" can be specified. + """ + # Run the base constructor + # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. + # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the + # credentials object + maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) + if maybe_url_match is None: + raise ValueError(f"Unexpected hostname structure: {host}") # pragma: NO COVER + + url_match_items = maybe_url_match.groupdict() + + host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host + + super().__init__( + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience + ) + self._session = AuthorizedSession( + self._credentials, default_host=self.DEFAULT_HOST) + self._operations_client: Optional[operations_v1.AbstractOperationsClient] = None + if client_cert_source_for_mtls: + self._session.configure_mtls_channel(client_cert_source_for_mtls) + self._interceptor = interceptor or DatabaseAdminRestInterceptor() + self._prep_wrapped_messages(client_info) + + @property + def operations_client(self) -> operations_v1.AbstractOperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Only create a new client if we do not already have one. + if self._operations_client is None: + http_options: Dict[str, List[Dict[str, str]]] = { + 'google.longrunning.Operations.CancelOperation': [ + { + 'method': 'post', + 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}:cancel', + }, + { + 'method': 'post', + 'uri': '/v1/{name=projects/*/instances/*/operations/*}:cancel', + }, + { + 'method': 'post', + 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations/*}:cancel', + }, + { + 'method': 'post', + 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations/*}:cancel', + }, + ], + 'google.longrunning.Operations.DeleteOperation': [ + { + 'method': 'delete', + 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}', + }, + { + 'method': 'delete', + 'uri': '/v1/{name=projects/*/instances/*/operations/*}', + }, + { + 'method': 'delete', + 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations/*}', + }, + { + 'method': 'delete', + 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations/*}', + }, + ], + 'google.longrunning.Operations.GetOperation': [ + { + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}', + }, + { + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/operations/*}', + }, + { + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations/*}', + }, + { + 'method': 'get', + 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations/*}', + }, + ], + 'google.longrunning.Operations.ListOperations': [ + { + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations}', + }, + { + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/operations}', + }, + { + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations}', + }, + { + 'method': 'get', + 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations}', + }, + ], + } + + rest_transport = operations_v1.OperationsRestTransport( + host=self._host, + # use the credentials which are saved + credentials=self._credentials, + scopes=self._scopes, + http_options=http_options, + path_prefix="v1") + + self._operations_client = operations_v1.AbstractOperationsClient(transport=rest_transport) + + # Return the client from cache. + return self._operations_client + + class _CopyBackup(DatabaseAdminRestStub): + def __hash__(self): + return hash("CopyBackup") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: backup.CopyBackupRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> operations_pb2.Operation: + r"""Call the copy backup method over HTTP. + + Args: + request (~.backup.CopyBackupRequest): + The request object. The request for + [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{parent=projects/*/instances/*}/backups:copy', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_copy_backup(request, metadata) + pb_request = backup.CopyBackupRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_copy_backup(resp) + return resp + + class _CreateBackup(DatabaseAdminRestStub): + def __hash__(self): + return hash("CreateBackup") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "backupId" : "", } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: gsad_backup.CreateBackupRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> operations_pb2.Operation: + r"""Call the create backup method over HTTP. + + Args: + request (~.gsad_backup.CreateBackupRequest): + The request object. The request for + [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{parent=projects/*/instances/*}/backups', + 'body': 'backup', + }, + ] + request, metadata = self._interceptor.pre_create_backup(request, metadata) + pb_request = gsad_backup.CreateBackupRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_backup(resp) + return resp + + class _CreateDatabase(DatabaseAdminRestStub): + def __hash__(self): + return hash("CreateDatabase") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_database_admin.CreateDatabaseRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> operations_pb2.Operation: + r"""Call the create database method over HTTP. + + Args: + request (~.spanner_database_admin.CreateDatabaseRequest): + The request object. The request for + [CreateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{parent=projects/*/instances/*}/databases', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_create_database(request, metadata) + pb_request = spanner_database_admin.CreateDatabaseRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_database(resp) + return resp + + class _DeleteBackup(DatabaseAdminRestStub): + def __hash__(self): + return hash("DeleteBackup") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: backup.DeleteBackupRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ): + r"""Call the delete backup method over HTTP. + + Args: + request (~.backup.DeleteBackupRequest): + The request object. The request for + [DeleteBackup][google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'delete', + 'uri': '/v1/{name=projects/*/instances/*/backups/*}', + }, + ] + request, metadata = self._interceptor.pre_delete_backup(request, metadata) + pb_request = backup.DeleteBackupRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + class _DropDatabase(DatabaseAdminRestStub): + def __hash__(self): + return hash("DropDatabase") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_database_admin.DropDatabaseRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ): + r"""Call the drop database method over HTTP. + + Args: + request (~.spanner_database_admin.DropDatabaseRequest): + The request object. The request for + [DropDatabase][google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'delete', + 'uri': '/v1/{database=projects/*/instances/*/databases/*}', + }, + ] + request, metadata = self._interceptor.pre_drop_database(request, metadata) + pb_request = spanner_database_admin.DropDatabaseRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + class _GetBackup(DatabaseAdminRestStub): + def __hash__(self): + return hash("GetBackup") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: backup.GetBackupRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> backup.Backup: + r"""Call the get backup method over HTTP. + + Args: + request (~.backup.GetBackupRequest): + The request object. The request for + [GetBackup][google.spanner.admin.database.v1.DatabaseAdmin.GetBackup]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.backup.Backup: + A backup of a Cloud Spanner database. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/backups/*}', + }, + ] + request, metadata = self._interceptor.pre_get_backup(request, metadata) + pb_request = backup.GetBackupRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = backup.Backup() + pb_resp = backup.Backup.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_backup(resp) + return resp + + class _GetDatabase(DatabaseAdminRestStub): + def __hash__(self): + return hash("GetDatabase") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_database_admin.GetDatabaseRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner_database_admin.Database: + r"""Call the get database method over HTTP. + + Args: + request (~.spanner_database_admin.GetDatabaseRequest): + The request object. The request for + [GetDatabase][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner_database_admin.Database: + A Cloud Spanner database. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/databases/*}', + }, + ] + request, metadata = self._interceptor.pre_get_database(request, metadata) + pb_request = spanner_database_admin.GetDatabaseRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner_database_admin.Database() + pb_resp = spanner_database_admin.Database.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_database(resp) + return resp + + class _GetDatabaseDdl(DatabaseAdminRestStub): + def __hash__(self): + return hash("GetDatabaseDdl") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_database_admin.GetDatabaseDdlRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner_database_admin.GetDatabaseDdlResponse: + r"""Call the get database ddl method over HTTP. + + Args: + request (~.spanner_database_admin.GetDatabaseDdlRequest): + The request object. The request for + [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner_database_admin.GetDatabaseDdlResponse: + The response for + [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{database=projects/*/instances/*/databases/*}/ddl', + }, + ] + request, metadata = self._interceptor.pre_get_database_ddl(request, metadata) + pb_request = spanner_database_admin.GetDatabaseDdlRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner_database_admin.GetDatabaseDdlResponse() + pb_resp = spanner_database_admin.GetDatabaseDdlResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_database_ddl(resp) + return resp + + class _GetIamPolicy(DatabaseAdminRestStub): + def __hash__(self): + return hash("GetIamPolicy") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: iam_policy_pb2.GetIamPolicyRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> policy_pb2.Policy: + r"""Call the get iam policy method over HTTP. + + Args: + request (~.iam_policy_pb2.GetIamPolicyRequest): + The request object. Request message for ``GetIamPolicy`` method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.policy_pb2.Policy: + An Identity and Access Management (IAM) policy, which + specifies access controls for Google Cloud resources. + + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members``, or + principals, to a single ``role``. Principals can be user + accounts, service accounts, Google groups, and domains + (such as G Suite). A ``role`` is a named list of + permissions; each ``role`` can be an IAM predefined role + or a user-created custom role. + + For some types of Google Cloud resources, a ``binding`` + can also specify a ``condition``, which is a logical + expression that allows access to a resource only if the + expression evaluates to ``true``. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the `IAM + documentation `__. + + **JSON example:** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": [ + "user:eve@example.com" + ], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ], + "etag": "BwWWja0YfJA=", + "version": 3 + } + + **YAML example:** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + etag: BwWWja0YfJA= + version: 3 + + For a description of IAM and its features, see the `IAM + documentation `__. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{resource=projects/*/instances/*/databases/*}:getIamPolicy', + 'body': '*', + }, +{ + 'method': 'post', + 'uri': '/v1/{resource=projects/*/instances/*/backups/*}:getIamPolicy', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_get_iam_policy(request, metadata) + pb_request = request + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = policy_pb2.Policy() + pb_resp = resp + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_iam_policy(resp) + return resp + + class _ListBackupOperations(DatabaseAdminRestStub): + def __hash__(self): + return hash("ListBackupOperations") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: backup.ListBackupOperationsRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> backup.ListBackupOperationsResponse: + r"""Call the list backup operations method over HTTP. + + Args: + request (~.backup.ListBackupOperationsRequest): + The request object. The request for + [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.backup.ListBackupOperationsResponse: + The response for + [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{parent=projects/*/instances/*}/backupOperations', + }, + ] + request, metadata = self._interceptor.pre_list_backup_operations(request, metadata) + pb_request = backup.ListBackupOperationsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = backup.ListBackupOperationsResponse() + pb_resp = backup.ListBackupOperationsResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_backup_operations(resp) + return resp + + class _ListBackups(DatabaseAdminRestStub): + def __hash__(self): + return hash("ListBackups") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: backup.ListBackupsRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> backup.ListBackupsResponse: + r"""Call the list backups method over HTTP. + + Args: + request (~.backup.ListBackupsRequest): + The request object. The request for + [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.backup.ListBackupsResponse: + The response for + [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{parent=projects/*/instances/*}/backups', + }, + ] + request, metadata = self._interceptor.pre_list_backups(request, metadata) + pb_request = backup.ListBackupsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = backup.ListBackupsResponse() + pb_resp = backup.ListBackupsResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_backups(resp) + return resp + + class _ListDatabaseOperations(DatabaseAdminRestStub): + def __hash__(self): + return hash("ListDatabaseOperations") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_database_admin.ListDatabaseOperationsRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner_database_admin.ListDatabaseOperationsResponse: + r"""Call the list database operations method over HTTP. + + Args: + request (~.spanner_database_admin.ListDatabaseOperationsRequest): + The request object. The request for + [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner_database_admin.ListDatabaseOperationsResponse: + The response for + [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{parent=projects/*/instances/*}/databaseOperations', + }, + ] + request, metadata = self._interceptor.pre_list_database_operations(request, metadata) + pb_request = spanner_database_admin.ListDatabaseOperationsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner_database_admin.ListDatabaseOperationsResponse() + pb_resp = spanner_database_admin.ListDatabaseOperationsResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_database_operations(resp) + return resp + + class _ListDatabaseRoles(DatabaseAdminRestStub): + def __hash__(self): + return hash("ListDatabaseRoles") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_database_admin.ListDatabaseRolesRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner_database_admin.ListDatabaseRolesResponse: + r"""Call the list database roles method over HTTP. + + Args: + request (~.spanner_database_admin.ListDatabaseRolesRequest): + The request object. The request for + [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner_database_admin.ListDatabaseRolesResponse: + The response for + [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{parent=projects/*/instances/*/databases/*}/databaseRoles', + }, + ] + request, metadata = self._interceptor.pre_list_database_roles(request, metadata) + pb_request = spanner_database_admin.ListDatabaseRolesRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner_database_admin.ListDatabaseRolesResponse() + pb_resp = spanner_database_admin.ListDatabaseRolesResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_database_roles(resp) + return resp + + class _ListDatabases(DatabaseAdminRestStub): + def __hash__(self): + return hash("ListDatabases") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_database_admin.ListDatabasesRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner_database_admin.ListDatabasesResponse: + r"""Call the list databases method over HTTP. + + Args: + request (~.spanner_database_admin.ListDatabasesRequest): + The request object. The request for + [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner_database_admin.ListDatabasesResponse: + The response for + [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{parent=projects/*/instances/*}/databases', + }, + ] + request, metadata = self._interceptor.pre_list_databases(request, metadata) + pb_request = spanner_database_admin.ListDatabasesRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner_database_admin.ListDatabasesResponse() + pb_resp = spanner_database_admin.ListDatabasesResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_databases(resp) + return resp + + class _RestoreDatabase(DatabaseAdminRestStub): + def __hash__(self): + return hash("RestoreDatabase") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_database_admin.RestoreDatabaseRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> operations_pb2.Operation: + r"""Call the restore database method over HTTP. + + Args: + request (~.spanner_database_admin.RestoreDatabaseRequest): + The request object. The request for + [RestoreDatabase][google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{parent=projects/*/instances/*}/databases:restore', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_restore_database(request, metadata) + pb_request = spanner_database_admin.RestoreDatabaseRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_restore_database(resp) + return resp + + class _SetIamPolicy(DatabaseAdminRestStub): + def __hash__(self): + return hash("SetIamPolicy") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: iam_policy_pb2.SetIamPolicyRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> policy_pb2.Policy: + r"""Call the set iam policy method over HTTP. + + Args: + request (~.iam_policy_pb2.SetIamPolicyRequest): + The request object. Request message for ``SetIamPolicy`` method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.policy_pb2.Policy: + An Identity and Access Management (IAM) policy, which + specifies access controls for Google Cloud resources. + + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members``, or + principals, to a single ``role``. Principals can be user + accounts, service accounts, Google groups, and domains + (such as G Suite). A ``role`` is a named list of + permissions; each ``role`` can be an IAM predefined role + or a user-created custom role. + + For some types of Google Cloud resources, a ``binding`` + can also specify a ``condition``, which is a logical + expression that allows access to a resource only if the + expression evaluates to ``true``. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the `IAM + documentation `__. + + **JSON example:** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": [ + "user:eve@example.com" + ], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ], + "etag": "BwWWja0YfJA=", + "version": 3 + } + + **YAML example:** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + etag: BwWWja0YfJA= + version: 3 + + For a description of IAM and its features, see the `IAM + documentation `__. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{resource=projects/*/instances/*/databases/*}:setIamPolicy', + 'body': '*', + }, +{ + 'method': 'post', + 'uri': '/v1/{resource=projects/*/instances/*/backups/*}:setIamPolicy', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_set_iam_policy(request, metadata) + pb_request = request + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = policy_pb2.Policy() + pb_resp = resp + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_set_iam_policy(resp) + return resp + + class _TestIamPermissions(DatabaseAdminRestStub): + def __hash__(self): + return hash("TestIamPermissions") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: iam_policy_pb2.TestIamPermissionsRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Call the test iam permissions method over HTTP. + + Args: + request (~.iam_policy_pb2.TestIamPermissionsRequest): + The request object. Request message for ``TestIamPermissions`` method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{resource=projects/*/instances/*/databases/*}:testIamPermissions', + 'body': '*', + }, +{ + 'method': 'post', + 'uri': '/v1/{resource=projects/*/instances/*/backups/*}:testIamPermissions', + 'body': '*', + }, +{ + 'method': 'post', + 'uri': '/v1/{resource=projects/*/instances/*/databases/*/databaseRoles/*}:testIamPermissions', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_test_iam_permissions(request, metadata) + pb_request = request + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = iam_policy_pb2.TestIamPermissionsResponse() + pb_resp = resp + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_test_iam_permissions(resp) + return resp + + class _UpdateBackup(DatabaseAdminRestStub): + def __hash__(self): + return hash("UpdateBackup") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "updateMask" : {}, } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: gsad_backup.UpdateBackupRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> gsad_backup.Backup: + r"""Call the update backup method over HTTP. + + Args: + request (~.gsad_backup.UpdateBackupRequest): + The request object. The request for + [UpdateBackup][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.gsad_backup.Backup: + A backup of a Cloud Spanner database. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'patch', + 'uri': '/v1/{backup.name=projects/*/instances/*/backups/*}', + 'body': 'backup', + }, + ] + request, metadata = self._interceptor.pre_update_backup(request, metadata) + pb_request = gsad_backup.UpdateBackupRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = gsad_backup.Backup() + pb_resp = gsad_backup.Backup.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_backup(resp) + return resp + + class _UpdateDatabase(DatabaseAdminRestStub): + def __hash__(self): + return hash("UpdateDatabase") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "updateMask" : {}, } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_database_admin.UpdateDatabaseRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> operations_pb2.Operation: + r"""Call the update database method over HTTP. + + Args: + request (~.spanner_database_admin.UpdateDatabaseRequest): + The request object. The request for + [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'patch', + 'uri': '/v1/{database.name=projects/*/instances/*/databases/*}', + 'body': 'database', + }, + ] + request, metadata = self._interceptor.pre_update_database(request, metadata) + pb_request = spanner_database_admin.UpdateDatabaseRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_database(resp) + return resp + + class _UpdateDatabaseDdl(DatabaseAdminRestStub): + def __hash__(self): + return hash("UpdateDatabaseDdl") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_database_admin.UpdateDatabaseDdlRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> operations_pb2.Operation: + r"""Call the update database ddl method over HTTP. + + Args: + request (~.spanner_database_admin.UpdateDatabaseDdlRequest): + The request object. Enqueues the given DDL statements to be applied, in + order but not necessarily all at once, to the database + schema at some point (or points) in the future. The + server checks that the statements are executable + (syntactically valid, name tables that exist, etc.) + before enqueueing them, but they may still fail upon + later execution (e.g., if a statement from another batch + of statements is applied first and it conflicts in some + way, or if there is some data-related problem like a + ``NULL`` value in a column to which ``NOT NULL`` would + be added). If a statement fails, all subsequent + statements in the batch are automatically cancelled. + + Each batch of statements is assigned a name which can be + used with the + [Operations][google.longrunning.Operations] API to + monitor progress. See the + [operation_id][google.spanner.admin.database.v1.UpdateDatabaseDdlRequest.operation_id] + field for more details. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'patch', + 'uri': '/v1/{database=projects/*/instances/*/databases/*}/ddl', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_update_database_ddl(request, metadata) + pb_request = spanner_database_admin.UpdateDatabaseDdlRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_database_ddl(resp) + return resp + + @property + def copy_backup(self) -> Callable[ + [backup.CopyBackupRequest], + operations_pb2.Operation]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._CopyBackup(self._session, self._host, self._interceptor) # type: ignore + + @property + def create_backup(self) -> Callable[ + [gsad_backup.CreateBackupRequest], + operations_pb2.Operation]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._CreateBackup(self._session, self._host, self._interceptor) # type: ignore + + @property + def create_database(self) -> Callable[ + [spanner_database_admin.CreateDatabaseRequest], + operations_pb2.Operation]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._CreateDatabase(self._session, self._host, self._interceptor) # type: ignore + + @property + def delete_backup(self) -> Callable[ + [backup.DeleteBackupRequest], + empty_pb2.Empty]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._DeleteBackup(self._session, self._host, self._interceptor) # type: ignore + + @property + def drop_database(self) -> Callable[ + [spanner_database_admin.DropDatabaseRequest], + empty_pb2.Empty]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._DropDatabase(self._session, self._host, self._interceptor) # type: ignore + + @property + def get_backup(self) -> Callable[ + [backup.GetBackupRequest], + backup.Backup]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetBackup(self._session, self._host, self._interceptor) # type: ignore + + @property + def get_database(self) -> Callable[ + [spanner_database_admin.GetDatabaseRequest], + spanner_database_admin.Database]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetDatabase(self._session, self._host, self._interceptor) # type: ignore + + @property + def get_database_ddl(self) -> Callable[ + [spanner_database_admin.GetDatabaseDdlRequest], + spanner_database_admin.GetDatabaseDdlResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetDatabaseDdl(self._session, self._host, self._interceptor) # type: ignore + + @property + def get_iam_policy(self) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + policy_pb2.Policy]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetIamPolicy(self._session, self._host, self._interceptor) # type: ignore + + @property + def list_backup_operations(self) -> Callable[ + [backup.ListBackupOperationsRequest], + backup.ListBackupOperationsResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListBackupOperations(self._session, self._host, self._interceptor) # type: ignore + + @property + def list_backups(self) -> Callable[ + [backup.ListBackupsRequest], + backup.ListBackupsResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListBackups(self._session, self._host, self._interceptor) # type: ignore + + @property + def list_database_operations(self) -> Callable[ + [spanner_database_admin.ListDatabaseOperationsRequest], + spanner_database_admin.ListDatabaseOperationsResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListDatabaseOperations(self._session, self._host, self._interceptor) # type: ignore + + @property + def list_database_roles(self) -> Callable[ + [spanner_database_admin.ListDatabaseRolesRequest], + spanner_database_admin.ListDatabaseRolesResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListDatabaseRoles(self._session, self._host, self._interceptor) # type: ignore + + @property + def list_databases(self) -> Callable[ + [spanner_database_admin.ListDatabasesRequest], + spanner_database_admin.ListDatabasesResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListDatabases(self._session, self._host, self._interceptor) # type: ignore + + @property + def restore_database(self) -> Callable[ + [spanner_database_admin.RestoreDatabaseRequest], + operations_pb2.Operation]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._RestoreDatabase(self._session, self._host, self._interceptor) # type: ignore + + @property + def set_iam_policy(self) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + policy_pb2.Policy]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._SetIamPolicy(self._session, self._host, self._interceptor) # type: ignore + + @property + def test_iam_permissions(self) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._TestIamPermissions(self._session, self._host, self._interceptor) # type: ignore + + @property + def update_backup(self) -> Callable[ + [gsad_backup.UpdateBackupRequest], + gsad_backup.Backup]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._UpdateBackup(self._session, self._host, self._interceptor) # type: ignore + + @property + def update_database(self) -> Callable[ + [spanner_database_admin.UpdateDatabaseRequest], + operations_pb2.Operation]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._UpdateDatabase(self._session, self._host, self._interceptor) # type: ignore + + @property + def update_database_ddl(self) -> Callable[ + [spanner_database_admin.UpdateDatabaseDdlRequest], + operations_pb2.Operation]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._UpdateDatabaseDdl(self._session, self._host, self._interceptor) # type: ignore + + @property + def cancel_operation(self): + return self._CancelOperation(self._session, self._host, self._interceptor) # type: ignore + + class _CancelOperation(DatabaseAdminRestStub): + def __call__(self, + request: operations_pb2.CancelOperationRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> None: + + r"""Call the cancel operation method over HTTP. + + Args: + request (operations_pb2.CancelOperationRequest): + The request object for CancelOperation method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}:cancel', + }, +{ + 'method': 'post', + 'uri': '/v1/{name=projects/*/instances/*/operations/*}:cancel', + }, +{ + 'method': 'post', + 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations/*}:cancel', + }, +{ + 'method': 'post', + 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations/*}:cancel', + }, + ] + + request, metadata = self._interceptor.pre_cancel_operation(request, metadata) + request_kwargs = json_format.MessageToDict(request) + transcoded_request = path_template.transcode( + http_options, **request_kwargs) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json.dumps(transcoded_request['query_params'])) + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + return self._interceptor.post_cancel_operation(None) + + @property + def delete_operation(self): + return self._DeleteOperation(self._session, self._host, self._interceptor) # type: ignore + + class _DeleteOperation(DatabaseAdminRestStub): + def __call__(self, + request: operations_pb2.DeleteOperationRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> None: + + r"""Call the delete operation method over HTTP. + + Args: + request (operations_pb2.DeleteOperationRequest): + The request object for DeleteOperation method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'delete', + 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}', + }, +{ + 'method': 'delete', + 'uri': '/v1/{name=projects/*/instances/*/operations/*}', + }, +{ + 'method': 'delete', + 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations/*}', + }, +{ + 'method': 'delete', + 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations/*}', + }, + ] + + request, metadata = self._interceptor.pre_delete_operation(request, metadata) + request_kwargs = json_format.MessageToDict(request) + transcoded_request = path_template.transcode( + http_options, **request_kwargs) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json.dumps(transcoded_request['query_params'])) + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + return self._interceptor.post_delete_operation(None) + + @property + def get_operation(self): + return self._GetOperation(self._session, self._host, self._interceptor) # type: ignore + + class _GetOperation(DatabaseAdminRestStub): + def __call__(self, + request: operations_pb2.GetOperationRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> operations_pb2.Operation: + + r"""Call the get operation method over HTTP. + + Args: + request (operations_pb2.GetOperationRequest): + The request object for GetOperation method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + operations_pb2.Operation: Response from GetOperation method. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}', + }, +{ + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/operations/*}', + }, +{ + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations/*}', + }, +{ + 'method': 'get', + 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations/*}', + }, + ] + + request, metadata = self._interceptor.pre_get_operation(request, metadata) + request_kwargs = json_format.MessageToDict(request) + transcoded_request = path_template.transcode( + http_options, **request_kwargs) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json.dumps(transcoded_request['query_params'])) + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + resp = operations_pb2.Operation() + resp = json_format.Parse(response.content.decode("utf-8"), resp) + resp = self._interceptor.post_get_operation(resp) + return resp + + @property + def list_operations(self): + return self._ListOperations(self._session, self._host, self._interceptor) # type: ignore + + class _ListOperations(DatabaseAdminRestStub): + def __call__(self, + request: operations_pb2.ListOperationsRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> operations_pb2.ListOperationsResponse: + + r"""Call the list operations method over HTTP. + + Args: + request (operations_pb2.ListOperationsRequest): + The request object for ListOperations method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + operations_pb2.ListOperationsResponse: Response from ListOperations method. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations}', + }, +{ + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/operations}', + }, +{ + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations}', + }, +{ + 'method': 'get', + 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations}', + }, + ] + + request, metadata = self._interceptor.pre_list_operations(request, metadata) + request_kwargs = json_format.MessageToDict(request) + transcoded_request = path_template.transcode( + http_options, **request_kwargs) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json.dumps(transcoded_request['query_params'])) + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + resp = operations_pb2.ListOperationsResponse() + resp = json_format.Parse(response.content.decode("utf-8"), resp) + resp = self._interceptor.post_list_operations(resp) + return resp + + @property + def kind(self) -> str: + return "rest" + + def close(self): + self._session.close() + + +__all__=( + 'DatabaseAdminRestTransport', +) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/__init__.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/__init__.py new file mode 100644 index 0000000000..c9fb52da51 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/__init__.py @@ -0,0 +1,110 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .backup import ( + Backup, + BackupInfo, + CopyBackupEncryptionConfig, + CopyBackupMetadata, + CopyBackupRequest, + CreateBackupEncryptionConfig, + CreateBackupMetadata, + CreateBackupRequest, + DeleteBackupRequest, + GetBackupRequest, + ListBackupOperationsRequest, + ListBackupOperationsResponse, + ListBackupsRequest, + ListBackupsResponse, + UpdateBackupRequest, +) +from .common import ( + EncryptionConfig, + EncryptionInfo, + OperationProgress, + DatabaseDialect, +) +from .spanner_database_admin import ( + CreateDatabaseMetadata, + CreateDatabaseRequest, + Database, + DatabaseRole, + DropDatabaseRequest, + GetDatabaseDdlRequest, + GetDatabaseDdlResponse, + GetDatabaseRequest, + ListDatabaseOperationsRequest, + ListDatabaseOperationsResponse, + ListDatabaseRolesRequest, + ListDatabaseRolesResponse, + ListDatabasesRequest, + ListDatabasesResponse, + OptimizeRestoredDatabaseMetadata, + RestoreDatabaseEncryptionConfig, + RestoreDatabaseMetadata, + RestoreDatabaseRequest, + RestoreInfo, + UpdateDatabaseDdlMetadata, + UpdateDatabaseDdlRequest, + UpdateDatabaseMetadata, + UpdateDatabaseRequest, + RestoreSourceType, +) + +__all__ = ( + 'Backup', + 'BackupInfo', + 'CopyBackupEncryptionConfig', + 'CopyBackupMetadata', + 'CopyBackupRequest', + 'CreateBackupEncryptionConfig', + 'CreateBackupMetadata', + 'CreateBackupRequest', + 'DeleteBackupRequest', + 'GetBackupRequest', + 'ListBackupOperationsRequest', + 'ListBackupOperationsResponse', + 'ListBackupsRequest', + 'ListBackupsResponse', + 'UpdateBackupRequest', + 'EncryptionConfig', + 'EncryptionInfo', + 'OperationProgress', + 'DatabaseDialect', + 'CreateDatabaseMetadata', + 'CreateDatabaseRequest', + 'Database', + 'DatabaseRole', + 'DropDatabaseRequest', + 'GetDatabaseDdlRequest', + 'GetDatabaseDdlResponse', + 'GetDatabaseRequest', + 'ListDatabaseOperationsRequest', + 'ListDatabaseOperationsResponse', + 'ListDatabaseRolesRequest', + 'ListDatabaseRolesResponse', + 'ListDatabasesRequest', + 'ListDatabasesResponse', + 'OptimizeRestoredDatabaseMetadata', + 'RestoreDatabaseEncryptionConfig', + 'RestoreDatabaseMetadata', + 'RestoreDatabaseRequest', + 'RestoreInfo', + 'UpdateDatabaseDdlMetadata', + 'UpdateDatabaseDdlRequest', + 'UpdateDatabaseMetadata', + 'UpdateDatabaseRequest', + 'RestoreSourceType', +) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/backup.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/backup.py new file mode 100644 index 0000000000..667938e242 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/backup.py @@ -0,0 +1,906 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.cloud.spanner_admin_database_v1.types import common +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.spanner.admin.database.v1', + manifest={ + 'Backup', + 'CreateBackupRequest', + 'CreateBackupMetadata', + 'CopyBackupRequest', + 'CopyBackupMetadata', + 'UpdateBackupRequest', + 'GetBackupRequest', + 'DeleteBackupRequest', + 'ListBackupsRequest', + 'ListBackupsResponse', + 'ListBackupOperationsRequest', + 'ListBackupOperationsResponse', + 'BackupInfo', + 'CreateBackupEncryptionConfig', + 'CopyBackupEncryptionConfig', + }, +) + + +class Backup(proto.Message): + r"""A backup of a Cloud Spanner database. + + Attributes: + database (str): + Required for the + [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup] + operation. Name of the database from which this backup was + created. This needs to be in the same instance as the + backup. Values are of the form + ``projects//instances//databases/``. + version_time (google.protobuf.timestamp_pb2.Timestamp): + The backup will contain an externally consistent copy of the + database at the timestamp specified by ``version_time``. If + ``version_time`` is not specified, the system will set + ``version_time`` to the ``create_time`` of the backup. + expire_time (google.protobuf.timestamp_pb2.Timestamp): + Required for the + [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup] + operation. The expiration time of the backup, with + microseconds granularity that must be at least 6 hours and + at most 366 days from the time the CreateBackup request is + processed. Once the ``expire_time`` has passed, the backup + is eligible to be automatically deleted by Cloud Spanner to + free the resources used by the backup. + name (str): + Output only for the + [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup] + operation. Required for the + [UpdateBackup][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup] + operation. + + A globally unique identifier for the backup which cannot be + changed. Values are of the form + ``projects//instances//backups/[a-z][a-z0-9_\-]*[a-z0-9]`` + The final segment of the name must be between 2 and 60 + characters in length. + + The backup is stored in the location(s) specified in the + instance configuration of the instance containing the + backup, identified by the prefix of the backup name of the + form ``projects//instances/``. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time the + [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup] + request is received. If the request does not specify + ``version_time``, the ``version_time`` of the backup will be + equivalent to the ``create_time``. + size_bytes (int): + Output only. Size of the backup in bytes. + state (google.cloud.spanner_admin_database_v1.types.Backup.State): + Output only. The current state of the backup. + referencing_databases (MutableSequence[str]): + Output only. The names of the restored databases that + reference the backup. The database names are of the form + ``projects//instances//databases/``. + Referencing databases may exist in different instances. The + existence of any referencing database prevents the backup + from being deleted. When a restored database from the backup + enters the ``READY`` state, the reference to the backup is + removed. + encryption_info (google.cloud.spanner_admin_database_v1.types.EncryptionInfo): + Output only. The encryption information for + the backup. + database_dialect (google.cloud.spanner_admin_database_v1.types.DatabaseDialect): + Output only. The database dialect information + for the backup. + referencing_backups (MutableSequence[str]): + Output only. The names of the destination backups being + created by copying this source backup. The backup names are + of the form + ``projects//instances//backups/``. + Referencing backups may exist in different instances. The + existence of any referencing backup prevents the backup from + being deleted. When the copy operation is done (either + successfully completed or cancelled or the destination + backup is deleted), the reference to the backup is removed. + max_expire_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The max allowed expiration time of the backup, + with microseconds granularity. A backup's expiration time + can be configured in multiple APIs: CreateBackup, + UpdateBackup, CopyBackup. When updating or copying an + existing backup, the expiration time specified must be less + than ``Backup.max_expire_time``. + """ + class State(proto.Enum): + r"""Indicates the current state of the backup. + + Values: + STATE_UNSPECIFIED (0): + Not specified. + CREATING (1): + The pending backup is still being created. Operations on the + backup may fail with ``FAILED_PRECONDITION`` in this state. + READY (2): + The backup is complete and ready for use. + """ + STATE_UNSPECIFIED = 0 + CREATING = 1 + READY = 2 + + database: str = proto.Field( + proto.STRING, + number=2, + ) + version_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=9, + message=timestamp_pb2.Timestamp, + ) + expire_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + name: str = proto.Field( + proto.STRING, + number=1, + ) + create_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + size_bytes: int = proto.Field( + proto.INT64, + number=5, + ) + state: State = proto.Field( + proto.ENUM, + number=6, + enum=State, + ) + referencing_databases: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=7, + ) + encryption_info: common.EncryptionInfo = proto.Field( + proto.MESSAGE, + number=8, + message=common.EncryptionInfo, + ) + database_dialect: common.DatabaseDialect = proto.Field( + proto.ENUM, + number=10, + enum=common.DatabaseDialect, + ) + referencing_backups: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=11, + ) + max_expire_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=12, + message=timestamp_pb2.Timestamp, + ) + + +class CreateBackupRequest(proto.Message): + r"""The request for + [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup]. + + Attributes: + parent (str): + Required. The name of the instance in which the backup will + be created. This must be the same instance that contains the + database the backup will be created from. The backup will be + stored in the location(s) specified in the instance + configuration of this instance. Values are of the form + ``projects//instances/``. + backup_id (str): + Required. The id of the backup to be created. The + ``backup_id`` appended to ``parent`` forms the full backup + name of the form + ``projects//instances//backups/``. + backup (google.cloud.spanner_admin_database_v1.types.Backup): + Required. The backup to create. + encryption_config (google.cloud.spanner_admin_database_v1.types.CreateBackupEncryptionConfig): + Optional. The encryption configuration used to encrypt the + backup. If this field is not specified, the backup will use + the same encryption configuration as the database by + default, namely + [encryption_type][google.spanner.admin.database.v1.CreateBackupEncryptionConfig.encryption_type] + = ``USE_DATABASE_ENCRYPTION``. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + backup_id: str = proto.Field( + proto.STRING, + number=2, + ) + backup: 'Backup' = proto.Field( + proto.MESSAGE, + number=3, + message='Backup', + ) + encryption_config: 'CreateBackupEncryptionConfig' = proto.Field( + proto.MESSAGE, + number=4, + message='CreateBackupEncryptionConfig', + ) + + +class CreateBackupMetadata(proto.Message): + r"""Metadata type for the operation returned by + [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup]. + + Attributes: + name (str): + The name of the backup being created. + database (str): + The name of the database the backup is + created from. + progress (google.cloud.spanner_admin_database_v1.types.OperationProgress): + The progress of the + [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup] + operation. + cancel_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which cancellation of this operation was + received. + [Operations.CancelOperation][google.longrunning.Operations.CancelOperation] + starts asynchronous cancellation on a long-running + operation. The server makes a best effort to cancel the + operation, but success is not guaranteed. Clients can use + [Operations.GetOperation][google.longrunning.Operations.GetOperation] + or other methods to check whether the cancellation succeeded + or whether the operation completed despite cancellation. On + successful cancellation, the operation is not deleted; + instead, it becomes an operation with an + [Operation.error][google.longrunning.Operation.error] value + with a [google.rpc.Status.code][google.rpc.Status.code] of + 1, corresponding to ``Code.CANCELLED``. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + database: str = proto.Field( + proto.STRING, + number=2, + ) + progress: common.OperationProgress = proto.Field( + proto.MESSAGE, + number=3, + message=common.OperationProgress, + ) + cancel_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + + +class CopyBackupRequest(proto.Message): + r"""The request for + [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup]. + + Attributes: + parent (str): + Required. The name of the destination instance that will + contain the backup copy. Values are of the form: + ``projects//instances/``. + backup_id (str): + Required. The id of the backup copy. The ``backup_id`` + appended to ``parent`` forms the full backup_uri of the form + ``projects//instances//backups/``. + source_backup (str): + Required. The source backup to be copied. The source backup + needs to be in READY state for it to be copied. Once + CopyBackup is in progress, the source backup cannot be + deleted or cleaned up on expiration until CopyBackup is + finished. Values are of the form: + ``projects//instances//backups/``. + expire_time (google.protobuf.timestamp_pb2.Timestamp): + Required. The expiration time of the backup in microsecond + granularity. The expiration time must be at least 6 hours + and at most 366 days from the ``create_time`` of the source + backup. Once the ``expire_time`` has passed, the backup is + eligible to be automatically deleted by Cloud Spanner to + free the resources used by the backup. + encryption_config (google.cloud.spanner_admin_database_v1.types.CopyBackupEncryptionConfig): + Optional. The encryption configuration used to encrypt the + backup. If this field is not specified, the backup will use + the same encryption configuration as the source backup by + default, namely + [encryption_type][google.spanner.admin.database.v1.CopyBackupEncryptionConfig.encryption_type] + = ``USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION``. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + backup_id: str = proto.Field( + proto.STRING, + number=2, + ) + source_backup: str = proto.Field( + proto.STRING, + number=3, + ) + expire_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + encryption_config: 'CopyBackupEncryptionConfig' = proto.Field( + proto.MESSAGE, + number=5, + message='CopyBackupEncryptionConfig', + ) + + +class CopyBackupMetadata(proto.Message): + r"""Metadata type for the google.longrunning.Operation returned by + [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup]. + + Attributes: + name (str): + The name of the backup being created through the copy + operation. Values are of the form + ``projects//instances//backups/``. + source_backup (str): + The name of the source backup that is being copied. Values + are of the form + ``projects//instances//backups/``. + progress (google.cloud.spanner_admin_database_v1.types.OperationProgress): + The progress of the + [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup] + operation. + cancel_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which cancellation of CopyBackup operation was + received. + [Operations.CancelOperation][google.longrunning.Operations.CancelOperation] + starts asynchronous cancellation on a long-running + operation. The server makes a best effort to cancel the + operation, but success is not guaranteed. Clients can use + [Operations.GetOperation][google.longrunning.Operations.GetOperation] + or other methods to check whether the cancellation succeeded + or whether the operation completed despite cancellation. On + successful cancellation, the operation is not deleted; + instead, it becomes an operation with an + [Operation.error][google.longrunning.Operation.error] value + with a [google.rpc.Status.code][google.rpc.Status.code] of + 1, corresponding to ``Code.CANCELLED``. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + source_backup: str = proto.Field( + proto.STRING, + number=2, + ) + progress: common.OperationProgress = proto.Field( + proto.MESSAGE, + number=3, + message=common.OperationProgress, + ) + cancel_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + + +class UpdateBackupRequest(proto.Message): + r"""The request for + [UpdateBackup][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup]. + + Attributes: + backup (google.cloud.spanner_admin_database_v1.types.Backup): + Required. The backup to update. ``backup.name``, and the + fields to be updated as specified by ``update_mask`` are + required. Other fields are ignored. Update is only supported + for the following fields: + + - ``backup.expire_time``. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. A mask specifying which fields (e.g. + ``expire_time``) in the Backup resource should be updated. + This mask is relative to the Backup resource, not to the + request message. The field mask must always be specified; + this prevents any future fields from being erased + accidentally by clients that do not know about them. + """ + + backup: 'Backup' = proto.Field( + proto.MESSAGE, + number=1, + message='Backup', + ) + update_mask: field_mask_pb2.FieldMask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class GetBackupRequest(proto.Message): + r"""The request for + [GetBackup][google.spanner.admin.database.v1.DatabaseAdmin.GetBackup]. + + Attributes: + name (str): + Required. Name of the backup. Values are of the form + ``projects//instances//backups/``. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class DeleteBackupRequest(proto.Message): + r"""The request for + [DeleteBackup][google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup]. + + Attributes: + name (str): + Required. Name of the backup to delete. Values are of the + form + ``projects//instances//backups/``. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class ListBackupsRequest(proto.Message): + r"""The request for + [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. + + Attributes: + parent (str): + Required. The instance to list backups from. Values are of + the form ``projects//instances/``. + filter (str): + An expression that filters the list of returned backups. + + A filter expression consists of a field name, a comparison + operator, and a value for filtering. The value must be a + string, a number, or a boolean. The comparison operator must + be one of: ``<``, ``>``, ``<=``, ``>=``, ``!=``, ``=``, or + ``:``. Colon ``:`` is the contains operator. Filter rules + are not case sensitive. + + The following fields in the + [Backup][google.spanner.admin.database.v1.Backup] are + eligible for filtering: + + - ``name`` + - ``database`` + - ``state`` + - ``create_time`` (and values are of the format + YYYY-MM-DDTHH:MM:SSZ) + - ``expire_time`` (and values are of the format + YYYY-MM-DDTHH:MM:SSZ) + - ``version_time`` (and values are of the format + YYYY-MM-DDTHH:MM:SSZ) + - ``size_bytes`` + + You can combine multiple expressions by enclosing each + expression in parentheses. By default, expressions are + combined with AND logic, but you can specify AND, OR, and + NOT logic explicitly. + + Here are a few examples: + + - ``name:Howl`` - The backup's name contains the string + "howl". + - ``database:prod`` - The database's name contains the + string "prod". + - ``state:CREATING`` - The backup is pending creation. + - ``state:READY`` - The backup is fully created and ready + for use. + - ``(name:howl) AND (create_time < \"2018-03-28T14:50:00Z\")`` + - The backup name contains the string "howl" and + ``create_time`` of the backup is before + 2018-03-28T14:50:00Z. + - ``expire_time < \"2018-03-28T14:50:00Z\"`` - The backup + ``expire_time`` is before 2018-03-28T14:50:00Z. + - ``size_bytes > 10000000000`` - The backup's size is + greater than 10GB + page_size (int): + Number of backups to be returned in the + response. If 0 or less, defaults to the server's + maximum allowed page size. + page_token (str): + If non-empty, ``page_token`` should contain a + [next_page_token][google.spanner.admin.database.v1.ListBackupsResponse.next_page_token] + from a previous + [ListBackupsResponse][google.spanner.admin.database.v1.ListBackupsResponse] + to the same ``parent`` and with the same ``filter``. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + filter: str = proto.Field( + proto.STRING, + number=2, + ) + page_size: int = proto.Field( + proto.INT32, + number=3, + ) + page_token: str = proto.Field( + proto.STRING, + number=4, + ) + + +class ListBackupsResponse(proto.Message): + r"""The response for + [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. + + Attributes: + backups (MutableSequence[google.cloud.spanner_admin_database_v1.types.Backup]): + The list of matching backups. Backups returned are ordered + by ``create_time`` in descending order, starting from the + most recent ``create_time``. + next_page_token (str): + ``next_page_token`` can be sent in a subsequent + [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups] + call to fetch more of the matching backups. + """ + + @property + def raw_page(self): + return self + + backups: MutableSequence['Backup'] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Backup', + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + +class ListBackupOperationsRequest(proto.Message): + r"""The request for + [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. + + Attributes: + parent (str): + Required. The instance of the backup operations. Values are + of the form ``projects//instances/``. + filter (str): + An expression that filters the list of returned backup + operations. + + A filter expression consists of a field name, a comparison + operator, and a value for filtering. The value must be a + string, a number, or a boolean. The comparison operator must + be one of: ``<``, ``>``, ``<=``, ``>=``, ``!=``, ``=``, or + ``:``. Colon ``:`` is the contains operator. Filter rules + are not case sensitive. + + The following fields in the + [operation][google.longrunning.Operation] are eligible for + filtering: + + - ``name`` - The name of the long-running operation + - ``done`` - False if the operation is in progress, else + true. + - ``metadata.@type`` - the type of metadata. For example, + the type string for + [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata] + is + ``type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata``. + - ``metadata.`` - any field in metadata.value. + ``metadata.@type`` must be specified first if filtering + on metadata fields. + - ``error`` - Error associated with the long-running + operation. + - ``response.@type`` - the type of response. + - ``response.`` - any field in response.value. + + You can combine multiple expressions by enclosing each + expression in parentheses. By default, expressions are + combined with AND logic, but you can specify AND, OR, and + NOT logic explicitly. + + Here are a few examples: + + - ``done:true`` - The operation is complete. + - ``(metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata) AND`` + ``metadata.database:prod`` - Returns operations where: + + - The operation's metadata type is + [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata]. + - The database the backup was taken from has a name + containing the string "prod". + + - ``(metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata) AND`` + ``(metadata.name:howl) AND`` + ``(metadata.progress.start_time < \"2018-03-28T14:50:00Z\") AND`` + ``(error:*)`` - Returns operations where: + + - The operation's metadata type is + [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata]. + - The backup name contains the string "howl". + - The operation started before 2018-03-28T14:50:00Z. + - The operation resulted in an error. + + - ``(metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CopyBackupMetadata) AND`` + ``(metadata.source_backup:test) AND`` + ``(metadata.progress.start_time < \"2022-01-18T14:50:00Z\") AND`` + ``(error:*)`` - Returns operations where: + + - The operation's metadata type is + [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. + - The source backup of the copied backup name contains + the string "test". + - The operation started before 2022-01-18T14:50:00Z. + - The operation resulted in an error. + + - ``((metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata) AND`` + ``(metadata.database:test_db)) OR`` + ``((metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CopyBackupMetadata) AND`` + ``(metadata.source_backup:test_bkp)) AND`` + ``(error:*)`` - Returns operations where: + + - The operation's metadata matches either of criteria: + + - The operation's metadata type is + [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata] + AND the database the backup was taken from has name + containing string "test_db" + - The operation's metadata type is + [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata] + AND the backup the backup was copied from has name + containing string "test_bkp" + + - The operation resulted in an error. + page_size (int): + Number of operations to be returned in the + response. If 0 or less, defaults to the server's + maximum allowed page size. + page_token (str): + If non-empty, ``page_token`` should contain a + [next_page_token][google.spanner.admin.database.v1.ListBackupOperationsResponse.next_page_token] + from a previous + [ListBackupOperationsResponse][google.spanner.admin.database.v1.ListBackupOperationsResponse] + to the same ``parent`` and with the same ``filter``. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + filter: str = proto.Field( + proto.STRING, + number=2, + ) + page_size: int = proto.Field( + proto.INT32, + number=3, + ) + page_token: str = proto.Field( + proto.STRING, + number=4, + ) + + +class ListBackupOperationsResponse(proto.Message): + r"""The response for + [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. + + Attributes: + operations (MutableSequence[google.longrunning.operations_pb2.Operation]): + The list of matching backup [long-running + operations][google.longrunning.Operation]. Each operation's + name will be prefixed by the backup's name. The operation's + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that are pending or have + completed/failed/canceled within the last 7 days. Operations + returned are ordered by + ``operation.metadata.value.progress.start_time`` in + descending order starting from the most recently started + operation. + next_page_token (str): + ``next_page_token`` can be sent in a subsequent + [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations] + call to fetch more of the matching metadata. + """ + + @property + def raw_page(self): + return self + + operations: MutableSequence[operations_pb2.Operation] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=operations_pb2.Operation, + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + +class BackupInfo(proto.Message): + r"""Information about a backup. + + Attributes: + backup (str): + Name of the backup. + version_time (google.protobuf.timestamp_pb2.Timestamp): + The backup contains an externally consistent copy of + ``source_database`` at the timestamp specified by + ``version_time``. If the + [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup] + request did not specify ``version_time``, the + ``version_time`` of the backup is equivalent to the + ``create_time``. + create_time (google.protobuf.timestamp_pb2.Timestamp): + The time the + [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup] + request was received. + source_database (str): + Name of the database the backup was created + from. + """ + + backup: str = proto.Field( + proto.STRING, + number=1, + ) + version_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + create_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + source_database: str = proto.Field( + proto.STRING, + number=3, + ) + + +class CreateBackupEncryptionConfig(proto.Message): + r"""Encryption configuration for the backup to create. + + Attributes: + encryption_type (google.cloud.spanner_admin_database_v1.types.CreateBackupEncryptionConfig.EncryptionType): + Required. The encryption type of the backup. + kms_key_name (str): + Optional. The Cloud KMS key that will be used to protect the + backup. This field should be set only when + [encryption_type][google.spanner.admin.database.v1.CreateBackupEncryptionConfig.encryption_type] + is ``CUSTOMER_MANAGED_ENCRYPTION``. Values are of the form + ``projects//locations//keyRings//cryptoKeys/``. + """ + class EncryptionType(proto.Enum): + r"""Encryption types for the backup. + + Values: + ENCRYPTION_TYPE_UNSPECIFIED (0): + Unspecified. Do not use. + USE_DATABASE_ENCRYPTION (1): + Use the same encryption configuration as the database. This + is the default option when + [encryption_config][google.spanner.admin.database.v1.CreateBackupEncryptionConfig] + is empty. For example, if the database is using + ``Customer_Managed_Encryption``, the backup will be using + the same Cloud KMS key as the database. + GOOGLE_DEFAULT_ENCRYPTION (2): + Use Google default encryption. + CUSTOMER_MANAGED_ENCRYPTION (3): + Use customer managed encryption. If specified, + ``kms_key_name`` must contain a valid Cloud KMS key. + """ + ENCRYPTION_TYPE_UNSPECIFIED = 0 + USE_DATABASE_ENCRYPTION = 1 + GOOGLE_DEFAULT_ENCRYPTION = 2 + CUSTOMER_MANAGED_ENCRYPTION = 3 + + encryption_type: EncryptionType = proto.Field( + proto.ENUM, + number=1, + enum=EncryptionType, + ) + kms_key_name: str = proto.Field( + proto.STRING, + number=2, + ) + + +class CopyBackupEncryptionConfig(proto.Message): + r"""Encryption configuration for the copied backup. + + Attributes: + encryption_type (google.cloud.spanner_admin_database_v1.types.CopyBackupEncryptionConfig.EncryptionType): + Required. The encryption type of the backup. + kms_key_name (str): + Optional. The Cloud KMS key that will be used to protect the + backup. This field should be set only when + [encryption_type][google.spanner.admin.database.v1.CopyBackupEncryptionConfig.encryption_type] + is ``CUSTOMER_MANAGED_ENCRYPTION``. Values are of the form + ``projects//locations//keyRings//cryptoKeys/``. + """ + class EncryptionType(proto.Enum): + r"""Encryption types for the backup. + + Values: + ENCRYPTION_TYPE_UNSPECIFIED (0): + Unspecified. Do not use. + USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION (1): + This is the default option for + [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup] + when + [encryption_config][google.spanner.admin.database.v1.CopyBackupEncryptionConfig] + is not specified. For example, if the source backup is using + ``Customer_Managed_Encryption``, the backup will be using + the same Cloud KMS key as the source backup. + GOOGLE_DEFAULT_ENCRYPTION (2): + Use Google default encryption. + CUSTOMER_MANAGED_ENCRYPTION (3): + Use customer managed encryption. If specified, + ``kms_key_name`` must contain a valid Cloud KMS key. + """ + ENCRYPTION_TYPE_UNSPECIFIED = 0 + USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION = 1 + GOOGLE_DEFAULT_ENCRYPTION = 2 + CUSTOMER_MANAGED_ENCRYPTION = 3 + + encryption_type: EncryptionType = proto.Field( + proto.ENUM, + number=1, + enum=EncryptionType, + ) + kms_key_name: str = proto.Field( + proto.STRING, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/common.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/common.py new file mode 100644 index 0000000000..6a676425b2 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/common.py @@ -0,0 +1,155 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.spanner.admin.database.v1', + manifest={ + 'DatabaseDialect', + 'OperationProgress', + 'EncryptionConfig', + 'EncryptionInfo', + }, +) + + +class DatabaseDialect(proto.Enum): + r"""Indicates the dialect type of a database. + + Values: + DATABASE_DIALECT_UNSPECIFIED (0): + Default value. This value will create a database with the + GOOGLE_STANDARD_SQL dialect. + GOOGLE_STANDARD_SQL (1): + Google standard SQL. + POSTGRESQL (2): + PostgreSQL supported SQL. + """ + DATABASE_DIALECT_UNSPECIFIED = 0 + GOOGLE_STANDARD_SQL = 1 + POSTGRESQL = 2 + + +class OperationProgress(proto.Message): + r"""Encapsulates progress related information for a Cloud Spanner + long running operation. + + Attributes: + progress_percent (int): + Percent completion of the operation. + Values are between 0 and 100 inclusive. + start_time (google.protobuf.timestamp_pb2.Timestamp): + Time the request was received. + end_time (google.protobuf.timestamp_pb2.Timestamp): + If set, the time at which this operation + failed or was completed successfully. + """ + + progress_percent: int = proto.Field( + proto.INT32, + number=1, + ) + start_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + end_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + + +class EncryptionConfig(proto.Message): + r"""Encryption configuration for a Cloud Spanner database. + + Attributes: + kms_key_name (str): + The Cloud KMS key to be used for encrypting and decrypting + the database. Values are of the form + ``projects//locations//keyRings//cryptoKeys/``. + """ + + kms_key_name: str = proto.Field( + proto.STRING, + number=2, + ) + + +class EncryptionInfo(proto.Message): + r"""Encryption information for a Cloud Spanner database or + backup. + + Attributes: + encryption_type (google.cloud.spanner_admin_database_v1.types.EncryptionInfo.Type): + Output only. The type of encryption. + encryption_status (google.rpc.status_pb2.Status): + Output only. If present, the status of a + recent encrypt/decrypt call on underlying data + for this database or backup. Regardless of + status, data is always encrypted at rest. + kms_key_version (str): + Output only. A Cloud KMS key version that is + being used to protect the database or backup. + """ + class Type(proto.Enum): + r"""Possible encryption types. + + Values: + TYPE_UNSPECIFIED (0): + Encryption type was not specified, though + data at rest remains encrypted. + GOOGLE_DEFAULT_ENCRYPTION (1): + The data is encrypted at rest with a key that + is fully managed by Google. No key version or + status will be populated. This is the default + state. + CUSTOMER_MANAGED_ENCRYPTION (2): + The data is encrypted at rest with a key that is managed by + the customer. The active version of the key. + ``kms_key_version`` will be populated, and + ``encryption_status`` may be populated. + """ + TYPE_UNSPECIFIED = 0 + GOOGLE_DEFAULT_ENCRYPTION = 1 + CUSTOMER_MANAGED_ENCRYPTION = 2 + + encryption_type: Type = proto.Field( + proto.ENUM, + number=3, + enum=Type, + ) + encryption_status: status_pb2.Status = proto.Field( + proto.MESSAGE, + number=4, + message=status_pb2.Status, + ) + kms_key_version: str = proto.Field( + proto.STRING, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py new file mode 100644 index 0000000000..4a37be71af --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py @@ -0,0 +1,1059 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup +from google.cloud.spanner_admin_database_v1.types import common +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.spanner.admin.database.v1', + manifest={ + 'RestoreSourceType', + 'RestoreInfo', + 'Database', + 'ListDatabasesRequest', + 'ListDatabasesResponse', + 'CreateDatabaseRequest', + 'CreateDatabaseMetadata', + 'GetDatabaseRequest', + 'UpdateDatabaseRequest', + 'UpdateDatabaseMetadata', + 'UpdateDatabaseDdlRequest', + 'UpdateDatabaseDdlMetadata', + 'DropDatabaseRequest', + 'GetDatabaseDdlRequest', + 'GetDatabaseDdlResponse', + 'ListDatabaseOperationsRequest', + 'ListDatabaseOperationsResponse', + 'RestoreDatabaseRequest', + 'RestoreDatabaseEncryptionConfig', + 'RestoreDatabaseMetadata', + 'OptimizeRestoredDatabaseMetadata', + 'DatabaseRole', + 'ListDatabaseRolesRequest', + 'ListDatabaseRolesResponse', + }, +) + + +class RestoreSourceType(proto.Enum): + r"""Indicates the type of the restore source. + + Values: + TYPE_UNSPECIFIED (0): + No restore associated. + BACKUP (1): + A backup was used as the source of the + restore. + """ + TYPE_UNSPECIFIED = 0 + BACKUP = 1 + + +class RestoreInfo(proto.Message): + r"""Information about the database restore. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + source_type (google.cloud.spanner_admin_database_v1.types.RestoreSourceType): + The type of the restore source. + backup_info (google.cloud.spanner_admin_database_v1.types.BackupInfo): + Information about the backup used to restore + the database. The backup may no longer exist. + + This field is a member of `oneof`_ ``source_info``. + """ + + source_type: 'RestoreSourceType' = proto.Field( + proto.ENUM, + number=1, + enum='RestoreSourceType', + ) + backup_info: gsad_backup.BackupInfo = proto.Field( + proto.MESSAGE, + number=2, + oneof='source_info', + message=gsad_backup.BackupInfo, + ) + + +class Database(proto.Message): + r"""A Cloud Spanner database. + + Attributes: + name (str): + Required. The name of the database. Values are of the form + ``projects//instances//databases/``, + where ```` is as specified in the + ``CREATE DATABASE`` statement. This name can be passed to + other API methods to identify the database. + state (google.cloud.spanner_admin_database_v1.types.Database.State): + Output only. The current database state. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. If exists, the time at which the + database creation started. + restore_info (google.cloud.spanner_admin_database_v1.types.RestoreInfo): + Output only. Applicable only for restored + databases. Contains information about the + restore source. + encryption_config (google.cloud.spanner_admin_database_v1.types.EncryptionConfig): + Output only. For databases that are using + customer managed encryption, this field contains + the encryption configuration for the database. + For databases that are using Google default or + other types of encryption, this field is empty. + encryption_info (MutableSequence[google.cloud.spanner_admin_database_v1.types.EncryptionInfo]): + Output only. For databases that are using + customer managed encryption, this field contains + the encryption information for the database, + such as encryption state and the Cloud KMS key + versions that are in use. + For databases that are using Google default or + other types of encryption, this field is empty. + + This field is propagated lazily from the + backend. There might be a delay from when a key + version is being used and when it appears in + this field. + version_retention_period (str): + Output only. The period in which Cloud Spanner retains all + versions of data for the database. This is the same as the + value of version_retention_period database option set using + [UpdateDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl]. + Defaults to 1 hour, if not set. + earliest_version_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Earliest timestamp at which + older versions of the data can be read. This + value is continuously updated by Cloud Spanner + and becomes stale the moment it is queried. If + you are using this value to recover data, make + sure to account for the time from the moment + when the value is queried to the moment when you + initiate the recovery. + default_leader (str): + Output only. The read-write region which contains the + database's leader replicas. + + This is the same as the value of default_leader database + option set using DatabaseAdmin.CreateDatabase or + DatabaseAdmin.UpdateDatabaseDdl. If not explicitly set, this + is empty. + database_dialect (google.cloud.spanner_admin_database_v1.types.DatabaseDialect): + Output only. The dialect of the Cloud Spanner + Database. + enable_drop_protection (bool): + Whether drop protection is enabled for this + database. Defaults to false, if not set. + reconciling (bool): + Output only. If true, the database is being + updated. If false, there are no ongoing update + operations for the database. + """ + class State(proto.Enum): + r"""Indicates the current state of the database. + + Values: + STATE_UNSPECIFIED (0): + Not specified. + CREATING (1): + The database is still being created. Operations on the + database may fail with ``FAILED_PRECONDITION`` in this + state. + READY (2): + The database is fully created and ready for + use. + READY_OPTIMIZING (3): + The database is fully created and ready for use, but is + still being optimized for performance and cannot handle full + load. + + In this state, the database still references the backup it + was restore from, preventing the backup from being deleted. + When optimizations are complete, the full performance of the + database will be restored, and the database will transition + to ``READY`` state. + """ + STATE_UNSPECIFIED = 0 + CREATING = 1 + READY = 2 + READY_OPTIMIZING = 3 + + name: str = proto.Field( + proto.STRING, + number=1, + ) + state: State = proto.Field( + proto.ENUM, + number=2, + enum=State, + ) + create_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + restore_info: 'RestoreInfo' = proto.Field( + proto.MESSAGE, + number=4, + message='RestoreInfo', + ) + encryption_config: common.EncryptionConfig = proto.Field( + proto.MESSAGE, + number=5, + message=common.EncryptionConfig, + ) + encryption_info: MutableSequence[common.EncryptionInfo] = proto.RepeatedField( + proto.MESSAGE, + number=8, + message=common.EncryptionInfo, + ) + version_retention_period: str = proto.Field( + proto.STRING, + number=6, + ) + earliest_version_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + default_leader: str = proto.Field( + proto.STRING, + number=9, + ) + database_dialect: common.DatabaseDialect = proto.Field( + proto.ENUM, + number=10, + enum=common.DatabaseDialect, + ) + enable_drop_protection: bool = proto.Field( + proto.BOOL, + number=11, + ) + reconciling: bool = proto.Field( + proto.BOOL, + number=12, + ) + + +class ListDatabasesRequest(proto.Message): + r"""The request for + [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. + + Attributes: + parent (str): + Required. The instance whose databases should be listed. + Values are of the form + ``projects//instances/``. + page_size (int): + Number of databases to be returned in the + response. If 0 or less, defaults to the server's + maximum allowed page size. + page_token (str): + If non-empty, ``page_token`` should contain a + [next_page_token][google.spanner.admin.database.v1.ListDatabasesResponse.next_page_token] + from a previous + [ListDatabasesResponse][google.spanner.admin.database.v1.ListDatabasesResponse]. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + page_size: int = proto.Field( + proto.INT32, + number=3, + ) + page_token: str = proto.Field( + proto.STRING, + number=4, + ) + + +class ListDatabasesResponse(proto.Message): + r"""The response for + [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. + + Attributes: + databases (MutableSequence[google.cloud.spanner_admin_database_v1.types.Database]): + Databases that matched the request. + next_page_token (str): + ``next_page_token`` can be sent in a subsequent + [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases] + call to fetch more of the matching databases. + """ + + @property + def raw_page(self): + return self + + databases: MutableSequence['Database'] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Database', + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + +class CreateDatabaseRequest(proto.Message): + r"""The request for + [CreateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase]. + + Attributes: + parent (str): + Required. The name of the instance that will serve the new + database. Values are of the form + ``projects//instances/``. + create_statement (str): + Required. A ``CREATE DATABASE`` statement, which specifies + the ID of the new database. The database ID must conform to + the regular expression ``[a-z][a-z0-9_\-]*[a-z0-9]`` and be + between 2 and 30 characters in length. If the database ID is + a reserved word or if it contains a hyphen, the database ID + must be enclosed in backticks (:literal:`\``). + extra_statements (MutableSequence[str]): + Optional. A list of DDL statements to run + inside the newly created database. Statements + can create tables, indexes, etc. These + statements execute atomically with the creation + of the database: if there is an error in any + statement, the database is not created. + encryption_config (google.cloud.spanner_admin_database_v1.types.EncryptionConfig): + Optional. The encryption configuration for + the database. If this field is not specified, + Cloud Spanner will encrypt/decrypt all data at + rest using Google default encryption. + database_dialect (google.cloud.spanner_admin_database_v1.types.DatabaseDialect): + Optional. The dialect of the Cloud Spanner + Database. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + create_statement: str = proto.Field( + proto.STRING, + number=2, + ) + extra_statements: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=3, + ) + encryption_config: common.EncryptionConfig = proto.Field( + proto.MESSAGE, + number=4, + message=common.EncryptionConfig, + ) + database_dialect: common.DatabaseDialect = proto.Field( + proto.ENUM, + number=5, + enum=common.DatabaseDialect, + ) + + +class CreateDatabaseMetadata(proto.Message): + r"""Metadata type for the operation returned by + [CreateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase]. + + Attributes: + database (str): + The database being created. + """ + + database: str = proto.Field( + proto.STRING, + number=1, + ) + + +class GetDatabaseRequest(proto.Message): + r"""The request for + [GetDatabase][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase]. + + Attributes: + name (str): + Required. The name of the requested database. Values are of + the form + ``projects//instances//databases/``. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class UpdateDatabaseRequest(proto.Message): + r"""The request for + [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. + + Attributes: + database (google.cloud.spanner_admin_database_v1.types.Database): + Required. The database to update. The ``name`` field of the + database is of the form + ``projects//instances//databases/``. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. The list of fields to update. Currently, only + ``enable_drop_protection`` field can be updated. + """ + + database: 'Database' = proto.Field( + proto.MESSAGE, + number=1, + message='Database', + ) + update_mask: field_mask_pb2.FieldMask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class UpdateDatabaseMetadata(proto.Message): + r"""Metadata type for the operation returned by + [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. + + Attributes: + request (google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest): + The request for + [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. + progress (google.cloud.spanner_admin_database_v1.types.OperationProgress): + The progress of the + [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase] + operation. + cancel_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which this operation was + cancelled. If set, this operation is in the + process of undoing itself (which is + best-effort). + """ + + request: 'UpdateDatabaseRequest' = proto.Field( + proto.MESSAGE, + number=1, + message='UpdateDatabaseRequest', + ) + progress: common.OperationProgress = proto.Field( + proto.MESSAGE, + number=2, + message=common.OperationProgress, + ) + cancel_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + + +class UpdateDatabaseDdlRequest(proto.Message): + r"""Enqueues the given DDL statements to be applied, in order but not + necessarily all at once, to the database schema at some point (or + points) in the future. The server checks that the statements are + executable (syntactically valid, name tables that exist, etc.) + before enqueueing them, but they may still fail upon later execution + (e.g., if a statement from another batch of statements is applied + first and it conflicts in some way, or if there is some data-related + problem like a ``NULL`` value in a column to which ``NOT NULL`` + would be added). If a statement fails, all subsequent statements in + the batch are automatically cancelled. + + Each batch of statements is assigned a name which can be used with + the [Operations][google.longrunning.Operations] API to monitor + progress. See the + [operation_id][google.spanner.admin.database.v1.UpdateDatabaseDdlRequest.operation_id] + field for more details. + + Attributes: + database (str): + Required. The database to update. + statements (MutableSequence[str]): + Required. DDL statements to be applied to the + database. + operation_id (str): + If empty, the new update request is assigned an + automatically-generated operation ID. Otherwise, + ``operation_id`` is used to construct the name of the + resulting [Operation][google.longrunning.Operation]. + + Specifying an explicit operation ID simplifies determining + whether the statements were executed in the event that the + [UpdateDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl] + call is replayed, or the return value is otherwise lost: the + [database][google.spanner.admin.database.v1.UpdateDatabaseDdlRequest.database] + and ``operation_id`` fields can be combined to form the + [name][google.longrunning.Operation.name] of the resulting + [longrunning.Operation][google.longrunning.Operation]: + ``/operations/``. + + ``operation_id`` should be unique within the database, and + must be a valid identifier: ``[a-z][a-z0-9_]*``. Note that + automatically-generated operation IDs always begin with an + underscore. If the named operation already exists, + [UpdateDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl] + returns ``ALREADY_EXISTS``. + """ + + database: str = proto.Field( + proto.STRING, + number=1, + ) + statements: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=2, + ) + operation_id: str = proto.Field( + proto.STRING, + number=3, + ) + + +class UpdateDatabaseDdlMetadata(proto.Message): + r"""Metadata type for the operation returned by + [UpdateDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl]. + + Attributes: + database (str): + The database being modified. + statements (MutableSequence[str]): + For an update this list contains all the + statements. For an individual statement, this + list contains only that statement. + commit_timestamps (MutableSequence[google.protobuf.timestamp_pb2.Timestamp]): + Reports the commit timestamps of all statements that have + succeeded so far, where ``commit_timestamps[i]`` is the + commit timestamp for the statement ``statements[i]``. + throttled (bool): + Output only. When true, indicates that the + operation is throttled e.g due to resource + constraints. When resources become available the + operation will resume and this field will be + false again. + progress (MutableSequence[google.cloud.spanner_admin_database_v1.types.OperationProgress]): + The progress of the + [UpdateDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl] + operations. Currently, only index creation statements will + have a continuously updating progress. For non-index + creation statements, ``progress[i]`` will have start time + and end time populated with commit timestamp of operation, + as well as a progress of 100% once the operation has + completed. ``progress[i]`` is the operation progress for + ``statements[i]``. + """ + + database: str = proto.Field( + proto.STRING, + number=1, + ) + statements: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=2, + ) + commit_timestamps: MutableSequence[timestamp_pb2.Timestamp] = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + throttled: bool = proto.Field( + proto.BOOL, + number=4, + ) + progress: MutableSequence[common.OperationProgress] = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=common.OperationProgress, + ) + + +class DropDatabaseRequest(proto.Message): + r"""The request for + [DropDatabase][google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase]. + + Attributes: + database (str): + Required. The database to be dropped. + """ + + database: str = proto.Field( + proto.STRING, + number=1, + ) + + +class GetDatabaseDdlRequest(proto.Message): + r"""The request for + [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. + + Attributes: + database (str): + Required. The database whose schema we wish to get. Values + are of the form + ``projects//instances//databases/`` + """ + + database: str = proto.Field( + proto.STRING, + number=1, + ) + + +class GetDatabaseDdlResponse(proto.Message): + r"""The response for + [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. + + Attributes: + statements (MutableSequence[str]): + A list of formatted DDL statements defining + the schema of the database specified in the + request. + """ + + statements: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=1, + ) + + +class ListDatabaseOperationsRequest(proto.Message): + r"""The request for + [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. + + Attributes: + parent (str): + Required. The instance of the database operations. Values + are of the form ``projects//instances/``. + filter (str): + An expression that filters the list of returned operations. + + A filter expression consists of a field name, a comparison + operator, and a value for filtering. The value must be a + string, a number, or a boolean. The comparison operator must + be one of: ``<``, ``>``, ``<=``, ``>=``, ``!=``, ``=``, or + ``:``. Colon ``:`` is the contains operator. Filter rules + are not case sensitive. + + The following fields in the + [Operation][google.longrunning.Operation] are eligible for + filtering: + + - ``name`` - The name of the long-running operation + - ``done`` - False if the operation is in progress, else + true. + - ``metadata.@type`` - the type of metadata. For example, + the type string for + [RestoreDatabaseMetadata][google.spanner.admin.database.v1.RestoreDatabaseMetadata] + is + ``type.googleapis.com/google.spanner.admin.database.v1.RestoreDatabaseMetadata``. + - ``metadata.`` - any field in metadata.value. + ``metadata.@type`` must be specified first, if filtering + on metadata fields. + - ``error`` - Error associated with the long-running + operation. + - ``response.@type`` - the type of response. + - ``response.`` - any field in response.value. + + You can combine multiple expressions by enclosing each + expression in parentheses. By default, expressions are + combined with AND logic. However, you can specify AND, OR, + and NOT logic explicitly. + + Here are a few examples: + + - ``done:true`` - The operation is complete. + - ``(metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.RestoreDatabaseMetadata) AND`` + ``(metadata.source_type:BACKUP) AND`` + ``(metadata.backup_info.backup:backup_howl) AND`` + ``(metadata.name:restored_howl) AND`` + ``(metadata.progress.start_time < \"2018-03-28T14:50:00Z\") AND`` + ``(error:*)`` - Return operations where: + + - The operation's metadata type is + [RestoreDatabaseMetadata][google.spanner.admin.database.v1.RestoreDatabaseMetadata]. + - The database is restored from a backup. + - The backup name contains "backup_howl". + - The restored database's name contains "restored_howl". + - The operation started before 2018-03-28T14:50:00Z. + - The operation resulted in an error. + page_size (int): + Number of operations to be returned in the + response. If 0 or less, defaults to the server's + maximum allowed page size. + page_token (str): + If non-empty, ``page_token`` should contain a + [next_page_token][google.spanner.admin.database.v1.ListDatabaseOperationsResponse.next_page_token] + from a previous + [ListDatabaseOperationsResponse][google.spanner.admin.database.v1.ListDatabaseOperationsResponse] + to the same ``parent`` and with the same ``filter``. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + filter: str = proto.Field( + proto.STRING, + number=2, + ) + page_size: int = proto.Field( + proto.INT32, + number=3, + ) + page_token: str = proto.Field( + proto.STRING, + number=4, + ) + + +class ListDatabaseOperationsResponse(proto.Message): + r"""The response for + [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. + + Attributes: + operations (MutableSequence[google.longrunning.operations_pb2.Operation]): + The list of matching database [long-running + operations][google.longrunning.Operation]. Each operation's + name will be prefixed by the database's name. The + operation's + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + next_page_token (str): + ``next_page_token`` can be sent in a subsequent + [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations] + call to fetch more of the matching metadata. + """ + + @property + def raw_page(self): + return self + + operations: MutableSequence[operations_pb2.Operation] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=operations_pb2.Operation, + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + +class RestoreDatabaseRequest(proto.Message): + r"""The request for + [RestoreDatabase][google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase]. + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + parent (str): + Required. The name of the instance in which to create the + restored database. This instance must be in the same project + and have the same instance configuration as the instance + containing the source backup. Values are of the form + ``projects//instances/``. + database_id (str): + Required. The id of the database to create and restore to. + This database must not already exist. The ``database_id`` + appended to ``parent`` forms the full database name of the + form + ``projects//instances//databases/``. + backup (str): + Name of the backup from which to restore. Values are of the + form + ``projects//instances//backups/``. + + This field is a member of `oneof`_ ``source``. + encryption_config (google.cloud.spanner_admin_database_v1.types.RestoreDatabaseEncryptionConfig): + Optional. An encryption configuration describing the + encryption type and key resources in Cloud KMS used to + encrypt/decrypt the database to restore to. If this field is + not specified, the restored database will use the same + encryption configuration as the backup by default, namely + [encryption_type][google.spanner.admin.database.v1.RestoreDatabaseEncryptionConfig.encryption_type] + = ``USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION``. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + database_id: str = proto.Field( + proto.STRING, + number=2, + ) + backup: str = proto.Field( + proto.STRING, + number=3, + oneof='source', + ) + encryption_config: 'RestoreDatabaseEncryptionConfig' = proto.Field( + proto.MESSAGE, + number=4, + message='RestoreDatabaseEncryptionConfig', + ) + + +class RestoreDatabaseEncryptionConfig(proto.Message): + r"""Encryption configuration for the restored database. + + Attributes: + encryption_type (google.cloud.spanner_admin_database_v1.types.RestoreDatabaseEncryptionConfig.EncryptionType): + Required. The encryption type of the restored + database. + kms_key_name (str): + Optional. The Cloud KMS key that will be used to + encrypt/decrypt the restored database. This field should be + set only when + [encryption_type][google.spanner.admin.database.v1.RestoreDatabaseEncryptionConfig.encryption_type] + is ``CUSTOMER_MANAGED_ENCRYPTION``. Values are of the form + ``projects//locations//keyRings//cryptoKeys/``. + """ + class EncryptionType(proto.Enum): + r"""Encryption types for the database to be restored. + + Values: + ENCRYPTION_TYPE_UNSPECIFIED (0): + Unspecified. Do not use. + USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION (1): + This is the default option when + [encryption_config][google.spanner.admin.database.v1.RestoreDatabaseEncryptionConfig] + is not specified. + GOOGLE_DEFAULT_ENCRYPTION (2): + Use Google default encryption. + CUSTOMER_MANAGED_ENCRYPTION (3): + Use customer managed encryption. If specified, + ``kms_key_name`` must must contain a valid Cloud KMS key. + """ + ENCRYPTION_TYPE_UNSPECIFIED = 0 + USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION = 1 + GOOGLE_DEFAULT_ENCRYPTION = 2 + CUSTOMER_MANAGED_ENCRYPTION = 3 + + encryption_type: EncryptionType = proto.Field( + proto.ENUM, + number=1, + enum=EncryptionType, + ) + kms_key_name: str = proto.Field( + proto.STRING, + number=2, + ) + + +class RestoreDatabaseMetadata(proto.Message): + r"""Metadata type for the long-running operation returned by + [RestoreDatabase][google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase]. + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + name (str): + Name of the database being created and + restored to. + source_type (google.cloud.spanner_admin_database_v1.types.RestoreSourceType): + The type of the restore source. + backup_info (google.cloud.spanner_admin_database_v1.types.BackupInfo): + Information about the backup used to restore + the database. + + This field is a member of `oneof`_ ``source_info``. + progress (google.cloud.spanner_admin_database_v1.types.OperationProgress): + The progress of the + [RestoreDatabase][google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase] + operation. + cancel_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which cancellation of this operation was + received. + [Operations.CancelOperation][google.longrunning.Operations.CancelOperation] + starts asynchronous cancellation on a long-running + operation. The server makes a best effort to cancel the + operation, but success is not guaranteed. Clients can use + [Operations.GetOperation][google.longrunning.Operations.GetOperation] + or other methods to check whether the cancellation succeeded + or whether the operation completed despite cancellation. On + successful cancellation, the operation is not deleted; + instead, it becomes an operation with an + [Operation.error][google.longrunning.Operation.error] value + with a [google.rpc.Status.code][google.rpc.Status.code] of + 1, corresponding to ``Code.CANCELLED``. + optimize_database_operation_name (str): + If exists, the name of the long-running operation that will + be used to track the post-restore optimization process to + optimize the performance of the restored database, and + remove the dependency on the restore source. The name is of + the form + ``projects//instances//databases//operations/`` + where the is the name of database being created and restored + to. The metadata type of the long-running operation is + [OptimizeRestoredDatabaseMetadata][google.spanner.admin.database.v1.OptimizeRestoredDatabaseMetadata]. + This long-running operation will be automatically created by + the system after the RestoreDatabase long-running operation + completes successfully. This operation will not be created + if the restore was not successful. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + source_type: 'RestoreSourceType' = proto.Field( + proto.ENUM, + number=2, + enum='RestoreSourceType', + ) + backup_info: gsad_backup.BackupInfo = proto.Field( + proto.MESSAGE, + number=3, + oneof='source_info', + message=gsad_backup.BackupInfo, + ) + progress: common.OperationProgress = proto.Field( + proto.MESSAGE, + number=4, + message=common.OperationProgress, + ) + cancel_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + optimize_database_operation_name: str = proto.Field( + proto.STRING, + number=6, + ) + + +class OptimizeRestoredDatabaseMetadata(proto.Message): + r"""Metadata type for the long-running operation used to track + the progress of optimizations performed on a newly restored + database. This long-running operation is automatically created + by the system after the successful completion of a database + restore, and cannot be cancelled. + + Attributes: + name (str): + Name of the restored database being + optimized. + progress (google.cloud.spanner_admin_database_v1.types.OperationProgress): + The progress of the post-restore + optimizations. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + progress: common.OperationProgress = proto.Field( + proto.MESSAGE, + number=2, + message=common.OperationProgress, + ) + + +class DatabaseRole(proto.Message): + r"""A Cloud Spanner database role. + + Attributes: + name (str): + Required. The name of the database role. Values are of the + form + ``projects//instances//databases//databaseRoles/ {role}``, + where ```` is as specified in the ``CREATE ROLE`` DDL + statement. This name can be passed to Get/Set IAMPolicy + methods to identify the database role. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class ListDatabaseRolesRequest(proto.Message): + r"""The request for + [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. + + Attributes: + parent (str): + Required. The database whose roles should be listed. Values + are of the form + ``projects//instances//databases//databaseRoles``. + page_size (int): + Number of database roles to be returned in + the response. If 0 or less, defaults to the + server's maximum allowed page size. + page_token (str): + If non-empty, ``page_token`` should contain a + [next_page_token][google.spanner.admin.database.v1.ListDatabaseRolesResponse.next_page_token] + from a previous + [ListDatabaseRolesResponse][google.spanner.admin.database.v1.ListDatabaseRolesResponse]. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + page_size: int = proto.Field( + proto.INT32, + number=2, + ) + page_token: str = proto.Field( + proto.STRING, + number=3, + ) + + +class ListDatabaseRolesResponse(proto.Message): + r"""The response for + [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. + + Attributes: + database_roles (MutableSequence[google.cloud.spanner_admin_database_v1.types.DatabaseRole]): + Database roles that matched the request. + next_page_token (str): + ``next_page_token`` can be sent in a subsequent + [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles] + call to fetch more of the matching roles. + """ + + @property + def raw_page(self): + return self + + database_roles: MutableSequence['DatabaseRole'] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='DatabaseRole', + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner_admin_database/v1/mypy.ini b/owl-bot-staging/spanner_admin_database/v1/mypy.ini new file mode 100644 index 0000000000..574c5aed39 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.7 +namespace_packages = True diff --git a/owl-bot-staging/spanner_admin_database/v1/noxfile.py b/owl-bot-staging/spanner_admin_database/v1/noxfile.py new file mode 100644 index 0000000000..d00593d952 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/noxfile.py @@ -0,0 +1,184 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import pathlib +import shutil +import subprocess +import sys + + +import nox # type: ignore + +ALL_PYTHON = [ + "3.7", + "3.8", + "3.9", + "3.10", + "3.11", +] + +CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() + +LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" +PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8") + +BLACK_VERSION = "black==22.3.0" +BLACK_PATHS = ["docs", "google", "tests", "samples", "noxfile.py", "setup.py"] +DEFAULT_PYTHON_VERSION = "3.11" + +nox.sessions = [ + "unit", + "cover", + "mypy", + "check_lower_bounds" + # exclude update_lower_bounds from default + "docs", + "blacken", + "lint", + "lint_setup_py", +] + +@nox.session(python=ALL_PYTHON) +def unit(session): + """Run the unit test suite.""" + + session.install('coverage', 'pytest', 'pytest-cov', 'pytest-asyncio', 'asyncmock; python_version < "3.8"') + session.install('-e', '.') + + session.run( + 'py.test', + '--quiet', + '--cov=google/cloud/spanner_admin_database_v1/', + '--cov=tests/', + '--cov-config=.coveragerc', + '--cov-report=term', + '--cov-report=html', + os.path.join('tests', 'unit', ''.join(session.posargs)) + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def cover(session): + """Run the final coverage report. + This outputs the coverage report aggregating coverage from the unit + test runs (not system test runs), and then erases coverage data. + """ + session.install("coverage", "pytest-cov") + session.run("coverage", "report", "--show-missing", "--fail-under=100") + + session.run("coverage", "erase") + + +@nox.session(python=ALL_PYTHON) +def mypy(session): + """Run the type checker.""" + session.install( + 'mypy', + 'types-requests', + 'types-protobuf' + ) + session.install('.') + session.run( + 'mypy', + '--explicit-package-bases', + 'google', + ) + + +@nox.session +def update_lower_bounds(session): + """Update lower bounds in constraints.txt to match setup.py""" + session.install('google-cloud-testutils') + session.install('.') + + session.run( + 'lower-bound-checker', + 'update', + '--package-name', + PACKAGE_NAME, + '--constraints-file', + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + + +@nox.session +def check_lower_bounds(session): + """Check lower bounds in setup.py are reflected in constraints file""" + session.install('google-cloud-testutils') + session.install('.') + + session.run( + 'lower-bound-checker', + 'check', + '--package-name', + PACKAGE_NAME, + '--constraints-file', + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def docs(session): + """Build the docs for this library.""" + + session.install("-e", ".") + session.install("sphinx==4.0.1", "alabaster", "recommonmark") + + shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) + session.run( + "sphinx-build", + "-W", # warnings as errors + "-T", # show full traceback on exception + "-N", # no colors + "-b", + "html", + "-d", + os.path.join("docs", "_build", "doctrees", ""), + os.path.join("docs", ""), + os.path.join("docs", "_build", "html", ""), + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def lint(session): + """Run linters. + + Returns a failure if the linters find linting errors or sufficiently + serious code quality issues. + """ + session.install("flake8", BLACK_VERSION) + session.run( + "black", + "--check", + *BLACK_PATHS, + ) + session.run("flake8", "google", "tests", "samples") + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def blacken(session): + """Run black. Format code to uniform standard.""" + session.install(BLACK_VERSION) + session.run( + "black", + *BLACK_PATHS, + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def lint_setup_py(session): + """Verify that setup.py is valid (including RST check).""" + session.install("docutils", "pygments") + session.run("python", "setup.py", "check", "--restructuredtext", "--strict") diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.database.v1.json b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.database.v1.json new file mode 100644 index 0000000000..11932ae5e8 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.database.v1.json @@ -0,0 +1,3319 @@ +{ + "clientLibrary": { + "apis": [ + { + "id": "google.spanner.admin.database.v1", + "version": "v1" + } + ], + "language": "PYTHON", + "name": "google-cloud-spanner-admin-database", + "version": "0.1.0" + }, + "snippets": [ + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.copy_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "CopyBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.CopyBackupRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "backup_id", + "type": "str" + }, + { + "name": "source_backup", + "type": "str" + }, + { + "name": "expire_time", + "type": "google.protobuf.timestamp_pb2.Timestamp" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "copy_backup" + }, + "description": "Sample for CopyBackup", + "file": "spanner_v1_generated_database_admin_copy_backup_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_CopyBackup_async", + "segments": [ + { + "end": 57, + "start": 27, + "type": "FULL" + }, + { + "end": 57, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 54, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 58, + "start": 55, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_copy_backup_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.copy_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "CopyBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.CopyBackupRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "backup_id", + "type": "str" + }, + { + "name": "source_backup", + "type": "str" + }, + { + "name": "expire_time", + "type": "google.protobuf.timestamp_pb2.Timestamp" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "copy_backup" + }, + "description": "Sample for CopyBackup", + "file": "spanner_v1_generated_database_admin_copy_backup_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_CopyBackup_sync", + "segments": [ + { + "end": 57, + "start": 27, + "type": "FULL" + }, + { + "end": 57, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 54, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 58, + "start": 55, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_copy_backup_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.create_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "CreateBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.CreateBackupRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "backup", + "type": "google.cloud.spanner_admin_database_v1.types.Backup" + }, + { + "name": "backup_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_backup" + }, + "description": "Sample for CreateBackup", + "file": "spanner_v1_generated_database_admin_create_backup_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_CreateBackup_async", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_create_backup_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.create_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "CreateBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.CreateBackupRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "backup", + "type": "google.cloud.spanner_admin_database_v1.types.Backup" + }, + { + "name": "backup_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_backup" + }, + "description": "Sample for CreateBackup", + "file": "spanner_v1_generated_database_admin_create_backup_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_CreateBackup_sync", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_create_backup_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.create_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "CreateDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.CreateDatabaseRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "create_statement", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_database" + }, + "description": "Sample for CreateDatabase", + "file": "spanner_v1_generated_database_admin_create_database_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_CreateDatabase_async", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_create_database_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.create_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "CreateDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.CreateDatabaseRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "create_statement", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_database" + }, + "description": "Sample for CreateDatabase", + "file": "spanner_v1_generated_database_admin_create_database_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_CreateDatabase_sync", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_create_database_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.delete_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "DeleteBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.DeleteBackupRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_backup" + }, + "description": "Sample for DeleteBackup", + "file": "spanner_v1_generated_database_admin_delete_backup_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_DeleteBackup_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_delete_backup_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.delete_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "DeleteBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.DeleteBackupRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_backup" + }, + "description": "Sample for DeleteBackup", + "file": "spanner_v1_generated_database_admin_delete_backup_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_DeleteBackup_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_delete_backup_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.drop_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "DropDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.DropDatabaseRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "drop_database" + }, + "description": "Sample for DropDatabase", + "file": "spanner_v1_generated_database_admin_drop_database_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_DropDatabase_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_drop_database_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.drop_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "DropDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.DropDatabaseRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "drop_database" + }, + "description": "Sample for DropDatabase", + "file": "spanner_v1_generated_database_admin_drop_database_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_DropDatabase_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_drop_database_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.get_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.GetBackupRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.Backup", + "shortName": "get_backup" + }, + "description": "Sample for GetBackup", + "file": "spanner_v1_generated_database_admin_get_backup_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetBackup_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_backup_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.get_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.GetBackupRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.Backup", + "shortName": "get_backup" + }, + "description": "Sample for GetBackup", + "file": "spanner_v1_generated_database_admin_get_backup_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetBackup_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_backup_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.get_database_ddl", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetDatabaseDdl" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlResponse", + "shortName": "get_database_ddl" + }, + "description": "Sample for GetDatabaseDdl", + "file": "spanner_v1_generated_database_admin_get_database_ddl_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_database_ddl_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.get_database_ddl", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetDatabaseDdl" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlResponse", + "shortName": "get_database_ddl" + }, + "description": "Sample for GetDatabaseDdl", + "file": "spanner_v1_generated_database_admin_get_database_ddl_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_database_ddl_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.get_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.GetDatabaseRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.Database", + "shortName": "get_database" + }, + "description": "Sample for GetDatabase", + "file": "spanner_v1_generated_database_admin_get_database_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetDatabase_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_database_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.get_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.GetDatabaseRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.Database", + "shortName": "get_database" + }, + "description": "Sample for GetDatabase", + "file": "spanner_v1_generated_database_admin_get_database_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetDatabase_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_database_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.get_iam_policy", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetIamPolicy", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "get_iam_policy" + }, + "description": "Sample for GetIamPolicy", + "file": "spanner_v1_generated_database_admin_get_iam_policy_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetIamPolicy_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 41, + "start": 39, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 42, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_iam_policy_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.get_iam_policy", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetIamPolicy", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "GetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "get_iam_policy" + }, + "description": "Sample for GetIamPolicy", + "file": "spanner_v1_generated_database_admin_get_iam_policy_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_GetIamPolicy_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 41, + "start": 39, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 42, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_get_iam_policy_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.list_backup_operations", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListBackupOperations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupOperationsAsyncPager", + "shortName": "list_backup_operations" + }, + "description": "Sample for ListBackupOperations", + "file": "spanner_v1_generated_database_admin_list_backup_operations_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListBackupOperations_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_backup_operations_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.list_backup_operations", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListBackupOperations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupOperationsPager", + "shortName": "list_backup_operations" + }, + "description": "Sample for ListBackupOperations", + "file": "spanner_v1_generated_database_admin_list_backup_operations_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListBackupOperations_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_backup_operations_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.list_backups", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListBackups", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListBackups" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListBackupsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupsAsyncPager", + "shortName": "list_backups" + }, + "description": "Sample for ListBackups", + "file": "spanner_v1_generated_database_admin_list_backups_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListBackups_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_backups_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.list_backups", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListBackups", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListBackups" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListBackupsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupsPager", + "shortName": "list_backups" + }, + "description": "Sample for ListBackups", + "file": "spanner_v1_generated_database_admin_list_backups_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListBackups_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_backups_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.list_database_operations", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListDatabaseOperations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseOperationsAsyncPager", + "shortName": "list_database_operations" + }, + "description": "Sample for ListDatabaseOperations", + "file": "spanner_v1_generated_database_admin_list_database_operations_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_database_operations_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.list_database_operations", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListDatabaseOperations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseOperationsPager", + "shortName": "list_database_operations" + }, + "description": "Sample for ListDatabaseOperations", + "file": "spanner_v1_generated_database_admin_list_database_operations_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_database_operations_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.list_database_roles", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListDatabaseRoles" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseRolesAsyncPager", + "shortName": "list_database_roles" + }, + "description": "Sample for ListDatabaseRoles", + "file": "spanner_v1_generated_database_admin_list_database_roles_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabaseRoles_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_database_roles_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.list_database_roles", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListDatabaseRoles" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseRolesPager", + "shortName": "list_database_roles" + }, + "description": "Sample for ListDatabaseRoles", + "file": "spanner_v1_generated_database_admin_list_database_roles_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabaseRoles_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_database_roles_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.list_databases", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListDatabases" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabasesAsyncPager", + "shortName": "list_databases" + }, + "description": "Sample for ListDatabases", + "file": "spanner_v1_generated_database_admin_list_databases_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabases_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_databases_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.list_databases", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "ListDatabases" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabasesPager", + "shortName": "list_databases" + }, + "description": "Sample for ListDatabases", + "file": "spanner_v1_generated_database_admin_list_databases_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabases_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_list_databases_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.restore_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "RestoreDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.RestoreDatabaseRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "database_id", + "type": "str" + }, + { + "name": "backup", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "restore_database" + }, + "description": "Sample for RestoreDatabase", + "file": "spanner_v1_generated_database_admin_restore_database_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_RestoreDatabase_async", + "segments": [ + { + "end": 57, + "start": 27, + "type": "FULL" + }, + { + "end": 57, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 54, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 58, + "start": 55, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_restore_database_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.restore_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "RestoreDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.RestoreDatabaseRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "database_id", + "type": "str" + }, + { + "name": "backup", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "restore_database" + }, + "description": "Sample for RestoreDatabase", + "file": "spanner_v1_generated_database_admin_restore_database_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_RestoreDatabase_sync", + "segments": [ + { + "end": 57, + "start": 27, + "type": "FULL" + }, + { + "end": 57, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 54, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 58, + "start": 55, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_restore_database_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.set_iam_policy", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.SetIamPolicy", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "SetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.SetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "set_iam_policy" + }, + "description": "Sample for SetIamPolicy", + "file": "spanner_v1_generated_database_admin_set_iam_policy_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_SetIamPolicy_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 41, + "start": 39, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 42, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_set_iam_policy_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.set_iam_policy", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.SetIamPolicy", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "SetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.SetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "set_iam_policy" + }, + "description": "Sample for SetIamPolicy", + "file": "spanner_v1_generated_database_admin_set_iam_policy_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_SetIamPolicy_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 41, + "start": 39, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 42, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_set_iam_policy_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.test_iam_permissions", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.TestIamPermissions", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "TestIamPermissions" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "permissions", + "type": "MutableSequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", + "shortName": "test_iam_permissions" + }, + "description": "Sample for TestIamPermissions", + "file": "spanner_v1_generated_database_admin_test_iam_permissions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_TestIamPermissions_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 41, + "start": 39, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 42, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_test_iam_permissions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.test_iam_permissions", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.TestIamPermissions", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "TestIamPermissions" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "permissions", + "type": "MutableSequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", + "shortName": "test_iam_permissions" + }, + "description": "Sample for TestIamPermissions", + "file": "spanner_v1_generated_database_admin_test_iam_permissions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_TestIamPermissions_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 41, + "start": 39, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 42, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_test_iam_permissions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.update_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "UpdateBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.UpdateBackupRequest" + }, + { + "name": "backup", + "type": "google.cloud.spanner_admin_database_v1.types.Backup" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.Backup", + "shortName": "update_backup" + }, + "description": "Sample for UpdateBackup", + "file": "spanner_v1_generated_database_admin_update_backup_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateBackup_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_update_backup_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.update_backup", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "UpdateBackup" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.UpdateBackupRequest" + }, + { + "name": "backup", + "type": "google.cloud.spanner_admin_database_v1.types.Backup" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_database_v1.types.Backup", + "shortName": "update_backup" + }, + "description": "Sample for UpdateBackup", + "file": "spanner_v1_generated_database_admin_update_backup_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateBackup_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_update_backup_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.update_database_ddl", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "UpdateDatabaseDdl" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.UpdateDatabaseDdlRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "statements", + "type": "MutableSequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_database_ddl" + }, + "description": "Sample for UpdateDatabaseDdl", + "file": "spanner_v1_generated_database_admin_update_database_ddl_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_async", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_update_database_ddl_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.update_database_ddl", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "UpdateDatabaseDdl" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.UpdateDatabaseDdlRequest" + }, + { + "name": "database", + "type": "str" + }, + { + "name": "statements", + "type": "MutableSequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_database_ddl" + }, + "description": "Sample for UpdateDatabaseDdl", + "file": "spanner_v1_generated_database_admin_update_database_ddl_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_sync", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_update_database_ddl_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.update_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "UpdateDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest" + }, + { + "name": "database", + "type": "google.cloud.spanner_admin_database_v1.types.Database" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_database" + }, + "description": "Sample for UpdateDatabase", + "file": "spanner_v1_generated_database_admin_update_database_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateDatabase_async", + "segments": [ + { + "end": 58, + "start": 27, + "type": "FULL" + }, + { + "end": 58, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 48, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 55, + "start": 49, + "type": "REQUEST_EXECUTION" + }, + { + "end": 59, + "start": 56, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_update_database_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.update_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "UpdateDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest" + }, + { + "name": "database", + "type": "google.cloud.spanner_admin_database_v1.types.Database" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_database" + }, + "description": "Sample for UpdateDatabase", + "file": "spanner_v1_generated_database_admin_update_database_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateDatabase_sync", + "segments": [ + { + "end": 58, + "start": 27, + "type": "FULL" + }, + { + "end": 58, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 48, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 55, + "start": 49, + "type": "REQUEST_EXECUTION" + }, + { + "end": 59, + "start": 56, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_update_database_sync.py" + } + ] +} diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_async.py new file mode 100644 index 0000000000..63dd1a1230 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_async.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CopyBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_CopyBackup_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_copy_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CopyBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + source_backup="source_backup_value", + ) + + # Make the request + operation = client.copy_backup(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_CopyBackup_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_sync.py new file mode 100644 index 0000000000..30d1efc423 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_sync.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CopyBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_CopyBackup_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_copy_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CopyBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + source_backup="source_backup_value", + ) + + # Make the request + operation = client.copy_backup(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_CopyBackup_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_async.py new file mode 100644 index 0000000000..530f39e816 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_async.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_CreateBackup_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_create_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + ) + + # Make the request + operation = client.create_backup(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_CreateBackup_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_sync.py new file mode 100644 index 0000000000..9af8c6943a --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_sync.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_CreateBackup_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_create_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateBackupRequest( + parent="parent_value", + backup_id="backup_id_value", + ) + + # Make the request + operation = client.create_backup(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_CreateBackup_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_async.py new file mode 100644 index 0000000000..e9525c02ec --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_async.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_CreateDatabase_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_create_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateDatabaseRequest( + parent="parent_value", + create_statement="create_statement_value", + ) + + # Make the request + operation = client.create_database(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_CreateDatabase_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_sync.py new file mode 100644 index 0000000000..95d549e82f --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_sync.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_CreateDatabase_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_create_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.CreateDatabaseRequest( + parent="parent_value", + create_statement="create_statement_value", + ) + + # Make the request + operation = client.create_database(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_CreateDatabase_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_async.py new file mode 100644 index 0000000000..630c8b34dd --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_DeleteBackup_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_delete_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DeleteBackupRequest( + name="name_value", + ) + + # Make the request + await client.delete_backup(request=request) + + +# [END spanner_v1_generated_DatabaseAdmin_DeleteBackup_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_sync.py new file mode 100644 index 0000000000..b1ea092308 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_DeleteBackup_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_delete_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DeleteBackupRequest( + name="name_value", + ) + + # Make the request + client.delete_backup(request=request) + + +# [END spanner_v1_generated_DatabaseAdmin_DeleteBackup_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_async.py new file mode 100644 index 0000000000..4683f47e99 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DropDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_DropDatabase_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_drop_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DropDatabaseRequest( + database="database_value", + ) + + # Make the request + await client.drop_database(request=request) + + +# [END spanner_v1_generated_DatabaseAdmin_DropDatabase_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_sync.py new file mode 100644 index 0000000000..62c322279a --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DropDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_DropDatabase_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_drop_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.DropDatabaseRequest( + database="database_value", + ) + + # Make the request + client.drop_database(request=request) + + +# [END spanner_v1_generated_DatabaseAdmin_DropDatabase_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_async.py new file mode 100644 index 0000000000..e41b762328 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetBackup_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_get_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetBackupRequest( + name="name_value", + ) + + # Make the request + response = await client.get_backup(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetBackup_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_sync.py new file mode 100644 index 0000000000..9d65904d9f --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetBackup_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_get_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetBackupRequest( + name="name_value", + ) + + # Make the request + response = client.get_backup(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetBackup_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_async.py new file mode 100644 index 0000000000..6fb00eab77 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetDatabase_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_get_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseRequest( + name="name_value", + ) + + # Make the request + response = await client.get_database(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetDatabase_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_async.py new file mode 100644 index 0000000000..1d386931a8 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDatabaseDdl +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_get_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseDdlRequest( + database="database_value", + ) + + # Make the request + response = await client.get_database_ddl(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_sync.py new file mode 100644 index 0000000000..79b8d9516a --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDatabaseDdl +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_get_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseDdlRequest( + database="database_value", + ) + + # Make the request + response = client.get_database_ddl(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_sync.py new file mode 100644 index 0000000000..5f5f80083e --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetDatabase_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_get_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.GetDatabaseRequest( + name="name_value", + ) + + # Make the request + response = client.get_database(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetDatabase_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_async.py new file mode 100644 index 0000000000..3b4e55b75b --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetIamPolicy_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +async def sample_get_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = await client.get_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetIamPolicy_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_sync.py new file mode 100644 index 0000000000..84c49219c5 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_GetIamPolicy_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +def sample_get_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.get_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_GetIamPolicy_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_async.py new file mode 100644 index 0000000000..2c13cc98cd --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBackupOperations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListBackupOperations_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_list_backup_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backup_operations(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListBackupOperations_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_sync.py new file mode 100644 index 0000000000..cebc0ff3c3 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBackupOperations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListBackupOperations_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_list_backup_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backup_operations(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListBackupOperations_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_async.py new file mode 100644 index 0000000000..f23a15cc85 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBackups +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListBackups_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_list_backups(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backups(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListBackups_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_sync.py new file mode 100644 index 0000000000..93105567fa --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBackups +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListBackups_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_list_backups(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListBackupsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_backups(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListBackups_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_async.py new file mode 100644 index 0000000000..8611d349ac --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatabaseOperations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_list_database_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabaseOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_database_operations(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_sync.py new file mode 100644 index 0000000000..10b059bc4a --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatabaseOperations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_list_database_operations(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabaseOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_database_operations(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_async.py new file mode 100644 index 0000000000..b4848d4be0 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatabaseRoles +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListDatabaseRoles_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_list_database_roles(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabaseRolesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_database_roles(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListDatabaseRoles_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_sync.py new file mode 100644 index 0000000000..b46bc5c8f4 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatabaseRoles +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListDatabaseRoles_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_list_database_roles(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabaseRolesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_database_roles(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListDatabaseRoles_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_async.py new file mode 100644 index 0000000000..13f1472d56 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatabases +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListDatabases_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_list_databases(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabasesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_databases(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListDatabases_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_sync.py new file mode 100644 index 0000000000..97bd5a23a3 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatabases +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_ListDatabases_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_list_databases(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.ListDatabasesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_databases(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_ListDatabases_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_async.py new file mode 100644 index 0000000000..bf5b073250 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_async.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RestoreDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_RestoreDatabase_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_restore_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.RestoreDatabaseRequest( + backup="backup_value", + parent="parent_value", + database_id="database_id_value", + ) + + # Make the request + operation = client.restore_database(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_RestoreDatabase_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_sync.py new file mode 100644 index 0000000000..92a98e4868 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_sync.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RestoreDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_RestoreDatabase_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_restore_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.RestoreDatabaseRequest( + backup="backup_value", + parent="parent_value", + database_id="database_id_value", + ) + + # Make the request + operation = client.restore_database(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_RestoreDatabase_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_async.py new file mode 100644 index 0000000000..9c045ccdf3 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_SetIamPolicy_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +async def sample_set_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = await client.set_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_SetIamPolicy_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_sync.py new file mode 100644 index 0000000000..e2ba9269ed --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_SetIamPolicy_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +def sample_set_iam_policy(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.set_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_SetIamPolicy_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_async.py new file mode 100644 index 0000000000..b96cd5a67b --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for TestIamPermissions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_TestIamPermissions_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +async def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value1', 'permissions_value2'], + ) + + # Make the request + response = await client.test_iam_permissions(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_TestIamPermissions_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_sync.py new file mode 100644 index 0000000000..40a31194ae --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for TestIamPermissions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_TestIamPermissions_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value1', 'permissions_value2'], + ) + + # Make the request + response = client.test_iam_permissions(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_TestIamPermissions_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_async.py new file mode 100644 index 0000000000..c12a2a3721 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_UpdateBackup_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_update_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateBackupRequest( + ) + + # Make the request + response = await client.update_backup(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_UpdateBackup_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_sync.py new file mode 100644 index 0000000000..cf4ec006ba --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateBackup +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_UpdateBackup_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_update_backup(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateBackupRequest( + ) + + # Make the request + response = client.update_backup(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_UpdateBackup_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_async.py new file mode 100644 index 0000000000..4167edafc9 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_async.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_UpdateDatabase_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_update_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + database = spanner_admin_database_v1.Database() + database.name = "name_value" + + request = spanner_admin_database_v1.UpdateDatabaseRequest( + database=database, + ) + + # Make the request + operation = client.update_database(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_UpdateDatabase_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_async.py new file mode 100644 index 0000000000..7b7d438b6e --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_async.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateDatabaseDdl +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +async def sample_update_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateDatabaseDdlRequest( + database="database_value", + statements=['statements_value1', 'statements_value2'], + ) + + # Make the request + operation = client.update_database_ddl(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_sync.py new file mode 100644 index 0000000000..e06df63277 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_sync.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateDatabaseDdl +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_update_database_ddl(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + request = spanner_admin_database_v1.UpdateDatabaseDdlRequest( + database="database_value", + statements=['statements_value1', 'statements_value2'], + ) + + # Make the request + operation = client.update_database_ddl(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_sync.py new file mode 100644 index 0000000000..6830e012c1 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_sync.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateDatabase +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-database + + +# [START spanner_v1_generated_DatabaseAdmin_UpdateDatabase_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_database_v1 + + +def sample_update_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + database = spanner_admin_database_v1.Database() + database.name = "name_value" + + request = spanner_admin_database_v1.UpdateDatabaseRequest( + database=database, + ) + + # Make the request + operation = client.update_database(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_DatabaseAdmin_UpdateDatabase_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/scripts/fixup_spanner_admin_database_v1_keywords.py b/owl-bot-staging/spanner_admin_database/v1/scripts/fixup_spanner_admin_database_v1_keywords.py new file mode 100644 index 0000000000..b358554082 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/scripts/fixup_spanner_admin_database_v1_keywords.py @@ -0,0 +1,195 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import argparse +import os +import libcst as cst +import pathlib +import sys +from typing import (Any, Callable, Dict, List, Sequence, Tuple) + + +def partition( + predicate: Callable[[Any], bool], + iterator: Sequence[Any] +) -> Tuple[List[Any], List[Any]]: + """A stable, out-of-place partition.""" + results = ([], []) + + for i in iterator: + results[int(predicate(i))].append(i) + + # Returns trueList, falseList + return results[1], results[0] + + +class spanner_admin_databaseCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'copy_backup': ('parent', 'backup_id', 'source_backup', 'expire_time', 'encryption_config', ), + 'create_backup': ('parent', 'backup_id', 'backup', 'encryption_config', ), + 'create_database': ('parent', 'create_statement', 'extra_statements', 'encryption_config', 'database_dialect', ), + 'delete_backup': ('name', ), + 'drop_database': ('database', ), + 'get_backup': ('name', ), + 'get_database': ('name', ), + 'get_database_ddl': ('database', ), + 'get_iam_policy': ('resource', 'options', ), + 'list_backup_operations': ('parent', 'filter', 'page_size', 'page_token', ), + 'list_backups': ('parent', 'filter', 'page_size', 'page_token', ), + 'list_database_operations': ('parent', 'filter', 'page_size', 'page_token', ), + 'list_database_roles': ('parent', 'page_size', 'page_token', ), + 'list_databases': ('parent', 'page_size', 'page_token', ), + 'restore_database': ('parent', 'database_id', 'backup', 'encryption_config', ), + 'set_iam_policy': ('resource', 'policy', 'update_mask', ), + 'test_iam_permissions': ('resource', 'permissions', ), + 'update_backup': ('backup', 'update_mask', ), + 'update_database': ('database', 'update_mask', ), + 'update_database_ddl': ('database', 'statements', 'operation_id', ), + } + + def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: + try: + key = original.func.attr.value + kword_params = self.METHOD_TO_PARAMS[key] + except (AttributeError, KeyError): + # Either not a method from the API or too convoluted to be sure. + return updated + + # If the existing code is valid, keyword args come after positional args. + # Therefore, all positional args must map to the first parameters. + args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) + if any(k.keyword.value == "request" for k in kwargs): + # We've already fixed this file, don't fix it again. + return updated + + kwargs, ctrl_kwargs = partition( + lambda a: a.keyword.value not in self.CTRL_PARAMS, + kwargs + ) + + args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] + ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) + for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) + + request_arg = cst.Arg( + value=cst.Dict([ + cst.DictElement( + cst.SimpleString("'{}'".format(name)), +cst.Element(value=arg.value) + ) + # Note: the args + kwargs looks silly, but keep in mind that + # the control parameters had to be stripped out, and that + # those could have been passed positionally or by keyword. + for name, arg in zip(kword_params, args + kwargs)]), + keyword=cst.Name("request") + ) + + return updated.with_changes( + args=[request_arg] + ctrl_kwargs + ) + + +def fix_files( + in_dir: pathlib.Path, + out_dir: pathlib.Path, + *, + transformer=spanner_admin_databaseCallTransformer(), +): + """Duplicate the input dir to the output dir, fixing file method calls. + + Preconditions: + * in_dir is a real directory + * out_dir is a real, empty directory + """ + pyfile_gen = ( + pathlib.Path(os.path.join(root, f)) + for root, _, files in os.walk(in_dir) + for f in files if os.path.splitext(f)[1] == ".py" + ) + + for fpath in pyfile_gen: + with open(fpath, 'r') as f: + src = f.read() + + # Parse the code and insert method call fixes. + tree = cst.parse_module(src) + updated = tree.visit(transformer) + + # Create the path and directory structure for the new file. + updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) + updated_path.parent.mkdir(parents=True, exist_ok=True) + + # Generate the updated source file at the corresponding path. + with open(updated_path, 'w') as f: + f.write(updated.code) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description="""Fix up source that uses the spanner_admin_database client library. + +The existing sources are NOT overwritten but are copied to output_dir with changes made. + +Note: This tool operates at a best-effort level at converting positional + parameters in client method calls to keyword based parameters. + Cases where it WILL FAIL include + A) * or ** expansion in a method call. + B) Calls via function or method alias (includes free function calls) + C) Indirect or dispatched calls (e.g. the method is looked up dynamically) + + These all constitute false negatives. The tool will also detect false + positives when an API method shares a name with another method. +""") + parser.add_argument( + '-d', + '--input-directory', + required=True, + dest='input_dir', + help='the input directory to walk for python files to fix up', + ) + parser.add_argument( + '-o', + '--output-directory', + required=True, + dest='output_dir', + help='the directory to output files fixed via un-flattening', + ) + args = parser.parse_args() + input_dir = pathlib.Path(args.input_dir) + output_dir = pathlib.Path(args.output_dir) + if not input_dir.is_dir(): + print( + f"input directory '{input_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if not output_dir.is_dir(): + print( + f"output directory '{output_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if os.listdir(output_dir): + print( + f"output directory '{output_dir}' is not empty", + file=sys.stderr, + ) + sys.exit(-1) + + fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/spanner_admin_database/v1/setup.py b/owl-bot-staging/spanner_admin_database/v1/setup.py new file mode 100644 index 0000000000..3887fc3059 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/setup.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import io +import os + +import setuptools # type: ignore + +package_root = os.path.abspath(os.path.dirname(__file__)) + +name = 'google-cloud-spanner-admin-database' + + +description = "Google Cloud Spanner Admin Database API client library" + +version = {} +with open(os.path.join(package_root, 'google/cloud/spanner_admin_database/gapic_version.py')) as fp: + exec(fp.read(), version) +version = version["__version__"] + +if version[0] == "0": + release_status = "Development Status :: 4 - Beta" +else: + release_status = "Development Status :: 5 - Production/Stable" + +dependencies = [ + "google-api-core[grpc] >= 1.34.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "proto-plus >= 1.22.0, <2.0.0dev", + "proto-plus >= 1.22.2, <2.0.0dev; python_version>='3.11'", + "protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "grpc-google-iam-v1 >= 0.12.4, <1.0.0dev", +] +url = "https://github.com/googleapis/python-spanner-admin-database" + +package_root = os.path.abspath(os.path.dirname(__file__)) + +readme_filename = os.path.join(package_root, "README.rst") +with io.open(readme_filename, encoding="utf-8") as readme_file: + readme = readme_file.read() + +packages = [ + package + for package in setuptools.PEP420PackageFinder.find() + if package.startswith("google") +] + +namespaces = ["google", "google.cloud"] + +setuptools.setup( + name=name, + version=version, + description=description, + long_description=readme, + author="Google LLC", + author_email="googleapis-packages@google.com", + license="Apache 2.0", + url=url, + classifiers=[ + release_status, + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Operating System :: OS Independent", + "Topic :: Internet", + ], + platforms="Posix; MacOS X; Windows", + packages=packages, + python_requires=">=3.7", + namespace_packages=namespaces, + install_requires=dependencies, + include_package_data=True, + zip_safe=False, +) diff --git a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.10.txt b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.10.txt new file mode 100644 index 0000000000..ad3f0fa58e --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.10.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.11.txt b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.11.txt new file mode 100644 index 0000000000..ad3f0fa58e --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.11.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.12.txt b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.12.txt new file mode 100644 index 0000000000..ad3f0fa58e --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.12.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.7.txt b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.7.txt new file mode 100644 index 0000000000..2beecf99e0 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.7.txt @@ -0,0 +1,10 @@ +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file. +# Pin the version to the lower bound. +# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", +# Then this file should have google-cloud-foo==1.14.0 +google-api-core==1.34.0 +proto-plus==1.22.0 +protobuf==3.19.5 +grpc-google-iam-v1==0.12.4 diff --git a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.8.txt b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.8.txt new file mode 100644 index 0000000000..ad3f0fa58e --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.8.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.9.txt b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.9.txt new file mode 100644 index 0000000000..ad3f0fa58e --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.9.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_database/v1/tests/__init__.py b/owl-bot-staging/spanner_admin_database/v1/tests/__init__.py new file mode 100644 index 0000000000..231bc12501 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/tests/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner_admin_database/v1/tests/unit/__init__.py b/owl-bot-staging/spanner_admin_database/v1/tests/unit/__init__.py new file mode 100644 index 0000000000..231bc12501 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/tests/unit/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/__init__.py b/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/__init__.py new file mode 100644 index 0000000000..231bc12501 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/__init__.py b/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/__init__.py new file mode 100644 index 0000000000..231bc12501 --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py b/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py new file mode 100644 index 0000000000..28087d188d --- /dev/null +++ b/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py @@ -0,0 +1,12988 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock # pragma: NO COVER +except ImportError: # pragma: NO COVER + import mock + +import grpc +from grpc.experimental import aio +from collections.abc import Iterable +from google.protobuf import json_format +import json +import math +import pytest +from proto.marshal.rules.dates import DurationRule, TimestampRule +from proto.marshal.rules import wrappers +from requests import Response +from requests import Request, PreparedRequest +from requests.sessions import Session +from google.protobuf import json_format + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import future +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import operation +from google.api_core import operation_async # type: ignore +from google.api_core import operations_v1 +from google.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.spanner_admin_database_v1.services.database_admin import DatabaseAdminAsyncClient +from google.cloud.spanner_admin_database_v1.services.database_admin import DatabaseAdminClient +from google.cloud.spanner_admin_database_v1.services.database_admin import pagers +from google.cloud.spanner_admin_database_v1.services.database_admin import transports +from google.cloud.spanner_admin_database_v1.types import backup +from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup +from google.cloud.spanner_admin_database_v1.types import common +from google.cloud.spanner_admin_database_v1.types import spanner_database_admin +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from google.oauth2 import service_account +from google.protobuf import any_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore +from google.type import expr_pb2 # type: ignore +import google.auth + + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert DatabaseAdminClient._get_default_mtls_endpoint(None) is None + assert DatabaseAdminClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert DatabaseAdminClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert DatabaseAdminClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert DatabaseAdminClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert DatabaseAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class,transport_name", [ + (DatabaseAdminClient, "grpc"), + (DatabaseAdminAsyncClient, "grpc_asyncio"), + (DatabaseAdminClient, "rest"), +]) +def test_database_admin_client_from_service_account_info(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info, transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ( + 'spanner.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://spanner.googleapis.com' + ) + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.DatabaseAdminGrpcTransport, "grpc"), + (transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio"), + (transports.DatabaseAdminRestTransport, "rest"), +]) +def test_database_admin_client_service_account_always_use_jwt(transport_class, transport_name): + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class,transport_name", [ + (DatabaseAdminClient, "grpc"), + (DatabaseAdminAsyncClient, "grpc_asyncio"), + (DatabaseAdminClient, "rest"), +]) +def test_database_admin_client_from_service_account_file(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: + factory.return_value = creds + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ( + 'spanner.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://spanner.googleapis.com' + ) + + +def test_database_admin_client_get_transport_class(): + transport = DatabaseAdminClient.get_transport_class() + available_transports = [ + transports.DatabaseAdminGrpcTransport, + transports.DatabaseAdminRestTransport, + ] + assert transport in available_transports + + transport = DatabaseAdminClient.get_transport_class("grpc") + assert transport == transports.DatabaseAdminGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (DatabaseAdminClient, transports.DatabaseAdminGrpcTransport, "grpc"), + (DatabaseAdminAsyncClient, transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio"), + (DatabaseAdminClient, transports.DatabaseAdminRestTransport, "rest"), +]) +@mock.patch.object(DatabaseAdminClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatabaseAdminClient)) +@mock.patch.object(DatabaseAdminAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatabaseAdminAsyncClient)) +def test_database_admin_client_client_options(client_class, transport_class, transport_name): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(DatabaseAdminClient, 'get_transport_class') as gtc: + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(DatabaseAdminClient, 'get_transport_class') as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name, client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class(transport=transport_name) + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError): + client = client_class(transport=transport_name) + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + # Check the case api_endpoint is provided + options = client_options.ClientOptions(api_audience="https://language.googleapis.com") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience="https://language.googleapis.com" + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (DatabaseAdminClient, transports.DatabaseAdminGrpcTransport, "grpc", "true"), + (DatabaseAdminAsyncClient, transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (DatabaseAdminClient, transports.DatabaseAdminGrpcTransport, "grpc", "false"), + (DatabaseAdminAsyncClient, transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio", "false"), + (DatabaseAdminClient, transports.DatabaseAdminRestTransport, "rest", "true"), + (DatabaseAdminClient, transports.DatabaseAdminRestTransport, "rest", "false"), +]) +@mock.patch.object(DatabaseAdminClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatabaseAdminClient)) +@mock.patch.object(DatabaseAdminAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatabaseAdminAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_database_admin_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + +@pytest.mark.parametrize("client_class", [ + DatabaseAdminClient, DatabaseAdminAsyncClient +]) +@mock.patch.object(DatabaseAdminClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatabaseAdminClient)) +@mock.patch.object(DatabaseAdminAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatabaseAdminAsyncClient)) +def test_database_admin_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_client_cert_source): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (DatabaseAdminClient, transports.DatabaseAdminGrpcTransport, "grpc"), + (DatabaseAdminAsyncClient, transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio"), + (DatabaseAdminClient, transports.DatabaseAdminRestTransport, "rest"), +]) +def test_database_admin_client_client_options_scopes(client_class, transport_class, transport_name): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ + (DatabaseAdminClient, transports.DatabaseAdminGrpcTransport, "grpc", grpc_helpers), + (DatabaseAdminAsyncClient, transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), + (DatabaseAdminClient, transports.DatabaseAdminRestTransport, "rest", None), +]) +def test_database_admin_client_client_options_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + +def test_database_admin_client_client_options_from_dict(): + with mock.patch('google.cloud.spanner_admin_database_v1.services.database_admin.transports.DatabaseAdminGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = DatabaseAdminClient( + client_options={'api_endpoint': 'squid.clam.whelk'} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ + (DatabaseAdminClient, transports.DatabaseAdminGrpcTransport, "grpc", grpc_helpers), + (DatabaseAdminAsyncClient, transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), +]) +def test_database_admin_client_create_channel_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "spanner.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.admin', +), + scopes=None, + default_host="spanner.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.ListDatabasesRequest, + dict, +]) +def test_list_databases(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_databases), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.ListDatabasesResponse( + next_page_token='next_page_token_value', + ) + response = client.list_databases(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.ListDatabasesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListDatabasesPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_databases_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_databases), + '__call__') as call: + client.list_databases() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.ListDatabasesRequest() + +@pytest.mark.asyncio +async def test_list_databases_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.ListDatabasesRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_databases), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabasesResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_databases(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.ListDatabasesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListDatabasesAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_databases_async_from_dict(): + await test_list_databases_async(request_type=dict) + + +def test_list_databases_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.ListDatabasesRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_databases), + '__call__') as call: + call.return_value = spanner_database_admin.ListDatabasesResponse() + client.list_databases(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_list_databases_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.ListDatabasesRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_databases), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabasesResponse()) + await client.list_databases(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_list_databases_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_databases), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.ListDatabasesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_databases( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + + +def test_list_databases_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_databases( + spanner_database_admin.ListDatabasesRequest(), + parent='parent_value', + ) + +@pytest.mark.asyncio +async def test_list_databases_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_databases), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.ListDatabasesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabasesResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_databases( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_list_databases_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_databases( + spanner_database_admin.ListDatabasesRequest(), + parent='parent_value', + ) + + +def test_list_databases_pager(transport_name: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_databases), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + spanner_database_admin.Database(), + spanner_database_admin.Database(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + spanner_database_admin.Database(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_databases(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, spanner_database_admin.Database) + for i in results) +def test_list_databases_pages(transport_name: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_databases), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + spanner_database_admin.Database(), + spanner_database_admin.Database(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + spanner_database_admin.Database(), + ], + ), + RuntimeError, + ) + pages = list(client.list_databases(request={}).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.asyncio +async def test_list_databases_async_pager(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_databases), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + spanner_database_admin.Database(), + spanner_database_admin.Database(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + spanner_database_admin.Database(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_databases(request={},) + assert async_pager.next_page_token == 'abc' + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, spanner_database_admin.Database) + for i in responses) + + +@pytest.mark.asyncio +async def test_list_databases_async_pages(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_databases), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + spanner_database_admin.Database(), + spanner_database_admin.Database(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + spanner_database_admin.Database(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_databases(request={})).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.CreateDatabaseRequest, + dict, +]) +def test_create_database(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.create_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.CreateDatabaseRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_database_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_database), + '__call__') as call: + client.create_database() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.CreateDatabaseRequest() + +@pytest.mark.asyncio +async def test_create_database_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.CreateDatabaseRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.create_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.CreateDatabaseRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_database_async_from_dict(): + await test_create_database_async(request_type=dict) + + +def test_create_database_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.CreateDatabaseRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_database), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.create_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_create_database_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.CreateDatabaseRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_database), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.create_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_create_database_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_database( + parent='parent_value', + create_statement='create_statement_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + arg = args[0].create_statement + mock_val = 'create_statement_value' + assert arg == mock_val + + +def test_create_database_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_database( + spanner_database_admin.CreateDatabaseRequest(), + parent='parent_value', + create_statement='create_statement_value', + ) + +@pytest.mark.asyncio +async def test_create_database_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_database( + parent='parent_value', + create_statement='create_statement_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + arg = args[0].create_statement + mock_val = 'create_statement_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_create_database_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_database( + spanner_database_admin.CreateDatabaseRequest(), + parent='parent_value', + create_statement='create_statement_value', + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.GetDatabaseRequest, + dict, +]) +def test_get_database(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.Database( + name='name_value', + state=spanner_database_admin.Database.State.CREATING, + version_retention_period='version_retention_period_value', + default_leader='default_leader_value', + database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + enable_drop_protection=True, + reconciling=True, + ) + response = client.get_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.GetDatabaseRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner_database_admin.Database) + assert response.name == 'name_value' + assert response.state == spanner_database_admin.Database.State.CREATING + assert response.version_retention_period == 'version_retention_period_value' + assert response.default_leader == 'default_leader_value' + assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.enable_drop_protection is True + assert response.reconciling is True + + +def test_get_database_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_database), + '__call__') as call: + client.get_database() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.GetDatabaseRequest() + +@pytest.mark.asyncio +async def test_get_database_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.GetDatabaseRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.Database( + name='name_value', + state=spanner_database_admin.Database.State.CREATING, + version_retention_period='version_retention_period_value', + default_leader='default_leader_value', + database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + enable_drop_protection=True, + reconciling=True, + )) + response = await client.get_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.GetDatabaseRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner_database_admin.Database) + assert response.name == 'name_value' + assert response.state == spanner_database_admin.Database.State.CREATING + assert response.version_retention_period == 'version_retention_period_value' + assert response.default_leader == 'default_leader_value' + assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.enable_drop_protection is True + assert response.reconciling is True + + +@pytest.mark.asyncio +async def test_get_database_async_from_dict(): + await test_get_database_async(request_type=dict) + + +def test_get_database_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.GetDatabaseRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_database), + '__call__') as call: + call.return_value = spanner_database_admin.Database() + client.get_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_get_database_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.GetDatabaseRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_database), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.Database()) + await client.get_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +def test_get_database_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.Database() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_database( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + + +def test_get_database_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_database( + spanner_database_admin.GetDatabaseRequest(), + name='name_value', + ) + +@pytest.mark.asyncio +async def test_get_database_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.Database() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.Database()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_database( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_get_database_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_database( + spanner_database_admin.GetDatabaseRequest(), + name='name_value', + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.UpdateDatabaseRequest, + dict, +]) +def test_update_database(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.update_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.UpdateDatabaseRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_database_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_database), + '__call__') as call: + client.update_database() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.UpdateDatabaseRequest() + +@pytest.mark.asyncio +async def test_update_database_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.UpdateDatabaseRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.update_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.UpdateDatabaseRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_database_async_from_dict(): + await test_update_database_async(request_type=dict) + + +def test_update_database_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.UpdateDatabaseRequest() + + request.database.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_database), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.update_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'database.name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_update_database_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.UpdateDatabaseRequest() + + request.database.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_database), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.update_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'database.name=name_value', + ) in kw['metadata'] + + +def test_update_database_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_database( + database=spanner_database_admin.Database(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = spanner_database_admin.Database(name='name_value') + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) + assert arg == mock_val + + +def test_update_database_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_database( + spanner_database_admin.UpdateDatabaseRequest(), + database=spanner_database_admin.Database(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + +@pytest.mark.asyncio +async def test_update_database_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_database( + database=spanner_database_admin.Database(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = spanner_database_admin.Database(name='name_value') + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) + assert arg == mock_val + +@pytest.mark.asyncio +async def test_update_database_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_database( + spanner_database_admin.UpdateDatabaseRequest(), + database=spanner_database_admin.Database(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.UpdateDatabaseDdlRequest, + dict, +]) +def test_update_database_ddl(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_database_ddl), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.update_database_ddl(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.UpdateDatabaseDdlRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_database_ddl_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_database_ddl), + '__call__') as call: + client.update_database_ddl() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.UpdateDatabaseDdlRequest() + +@pytest.mark.asyncio +async def test_update_database_ddl_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.UpdateDatabaseDdlRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_database_ddl), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.update_database_ddl(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.UpdateDatabaseDdlRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_database_ddl_async_from_dict(): + await test_update_database_ddl_async(request_type=dict) + + +def test_update_database_ddl_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.UpdateDatabaseDdlRequest() + + request.database = 'database_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_database_ddl), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.update_database_ddl(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'database=database_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_update_database_ddl_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.UpdateDatabaseDdlRequest() + + request.database = 'database_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_database_ddl), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.update_database_ddl(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'database=database_value', + ) in kw['metadata'] + + +def test_update_database_ddl_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_database_ddl), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_database_ddl( + database='database_value', + statements=['statements_value'], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = 'database_value' + assert arg == mock_val + arg = args[0].statements + mock_val = ['statements_value'] + assert arg == mock_val + + +def test_update_database_ddl_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_database_ddl( + spanner_database_admin.UpdateDatabaseDdlRequest(), + database='database_value', + statements=['statements_value'], + ) + +@pytest.mark.asyncio +async def test_update_database_ddl_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_database_ddl), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_database_ddl( + database='database_value', + statements=['statements_value'], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = 'database_value' + assert arg == mock_val + arg = args[0].statements + mock_val = ['statements_value'] + assert arg == mock_val + +@pytest.mark.asyncio +async def test_update_database_ddl_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_database_ddl( + spanner_database_admin.UpdateDatabaseDdlRequest(), + database='database_value', + statements=['statements_value'], + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.DropDatabaseRequest, + dict, +]) +def test_drop_database(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.drop_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.drop_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.DropDatabaseRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_drop_database_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.drop_database), + '__call__') as call: + client.drop_database() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.DropDatabaseRequest() + +@pytest.mark.asyncio +async def test_drop_database_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.DropDatabaseRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.drop_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.drop_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.DropDatabaseRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_drop_database_async_from_dict(): + await test_drop_database_async(request_type=dict) + + +def test_drop_database_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.DropDatabaseRequest() + + request.database = 'database_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.drop_database), + '__call__') as call: + call.return_value = None + client.drop_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'database=database_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_drop_database_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.DropDatabaseRequest() + + request.database = 'database_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.drop_database), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.drop_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'database=database_value', + ) in kw['metadata'] + + +def test_drop_database_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.drop_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.drop_database( + database='database_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = 'database_value' + assert arg == mock_val + + +def test_drop_database_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.drop_database( + spanner_database_admin.DropDatabaseRequest(), + database='database_value', + ) + +@pytest.mark.asyncio +async def test_drop_database_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.drop_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.drop_database( + database='database_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = 'database_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_drop_database_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.drop_database( + spanner_database_admin.DropDatabaseRequest(), + database='database_value', + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.GetDatabaseDdlRequest, + dict, +]) +def test_get_database_ddl(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_database_ddl), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.GetDatabaseDdlResponse( + statements=['statements_value'], + ) + response = client.get_database_ddl(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.GetDatabaseDdlRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner_database_admin.GetDatabaseDdlResponse) + assert response.statements == ['statements_value'] + + +def test_get_database_ddl_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_database_ddl), + '__call__') as call: + client.get_database_ddl() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.GetDatabaseDdlRequest() + +@pytest.mark.asyncio +async def test_get_database_ddl_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.GetDatabaseDdlRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_database_ddl), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.GetDatabaseDdlResponse( + statements=['statements_value'], + )) + response = await client.get_database_ddl(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.GetDatabaseDdlRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner_database_admin.GetDatabaseDdlResponse) + assert response.statements == ['statements_value'] + + +@pytest.mark.asyncio +async def test_get_database_ddl_async_from_dict(): + await test_get_database_ddl_async(request_type=dict) + + +def test_get_database_ddl_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.GetDatabaseDdlRequest() + + request.database = 'database_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_database_ddl), + '__call__') as call: + call.return_value = spanner_database_admin.GetDatabaseDdlResponse() + client.get_database_ddl(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'database=database_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_get_database_ddl_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.GetDatabaseDdlRequest() + + request.database = 'database_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_database_ddl), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.GetDatabaseDdlResponse()) + await client.get_database_ddl(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'database=database_value', + ) in kw['metadata'] + + +def test_get_database_ddl_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_database_ddl), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.GetDatabaseDdlResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_database_ddl( + database='database_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = 'database_value' + assert arg == mock_val + + +def test_get_database_ddl_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_database_ddl( + spanner_database_admin.GetDatabaseDdlRequest(), + database='database_value', + ) + +@pytest.mark.asyncio +async def test_get_database_ddl_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_database_ddl), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.GetDatabaseDdlResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.GetDatabaseDdlResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_database_ddl( + database='database_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = 'database_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_get_database_ddl_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_database_ddl( + spanner_database_admin.GetDatabaseDdlRequest(), + database='database_value', + ) + + +@pytest.mark.parametrize("request_type", [ + iam_policy_pb2.SetIamPolicyRequest, + dict, +]) +def test_set_iam_policy(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b'etag_blob', + ) + response = client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b'etag_blob' + + +def test_set_iam_policy_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + client.set_iam_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = 'grpc_asyncio', request_type=iam_policy_pb2.SetIamPolicyRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy( + version=774, + etag=b'etag_blob', + )) + response = await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b'etag_blob' + + +@pytest.mark.asyncio +async def test_set_iam_policy_async_from_dict(): + await test_set_iam_policy_async(request_type=dict) + + +def test_set_iam_policy_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + + request.resource = 'resource_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + call.return_value = policy_pb2.Policy() + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'resource=resource_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + + request.resource = 'resource_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'resource=resource_value', + ) in kw['metadata'] + +def test_set_iam_policy_from_dict_foreign(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.set_iam_policy(request={ + 'resource': 'resource_value', + 'policy': policy_pb2.Policy(version=774), + 'update_mask': field_mask_pb2.FieldMask(paths=['paths_value']), + } + ) + call.assert_called() + + +def test_set_iam_policy_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.set_iam_policy( + resource='resource_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].resource + mock_val = 'resource_value' + assert arg == mock_val + + +def test_set_iam_policy_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.set_iam_policy( + iam_policy_pb2.SetIamPolicyRequest(), + resource='resource_value', + ) + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.set_iam_policy( + resource='resource_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].resource + mock_val = 'resource_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.set_iam_policy( + iam_policy_pb2.SetIamPolicyRequest(), + resource='resource_value', + ) + + +@pytest.mark.parametrize("request_type", [ + iam_policy_pb2.GetIamPolicyRequest, + dict, +]) +def test_get_iam_policy(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b'etag_blob', + ) + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b'etag_blob' + + +def test_get_iam_policy_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + client.get_iam_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = 'grpc_asyncio', request_type=iam_policy_pb2.GetIamPolicyRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy( + version=774, + etag=b'etag_blob', + )) + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b'etag_blob' + + +@pytest.mark.asyncio +async def test_get_iam_policy_async_from_dict(): + await test_get_iam_policy_async(request_type=dict) + + +def test_get_iam_policy_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + + request.resource = 'resource_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + call.return_value = policy_pb2.Policy() + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'resource=resource_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + + request.resource = 'resource_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'resource=resource_value', + ) in kw['metadata'] + +def test_get_iam_policy_from_dict_foreign(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.get_iam_policy(request={ + 'resource': 'resource_value', + 'options': options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_get_iam_policy_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_iam_policy( + resource='resource_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].resource + mock_val = 'resource_value' + assert arg == mock_val + + +def test_get_iam_policy_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_iam_policy( + iam_policy_pb2.GetIamPolicyRequest(), + resource='resource_value', + ) + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_iam_policy( + resource='resource_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].resource + mock_val = 'resource_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_iam_policy( + iam_policy_pb2.GetIamPolicyRequest(), + resource='resource_value', + ) + + +@pytest.mark.parametrize("request_type", [ + iam_policy_pb2.TestIamPermissionsRequest, + dict, +]) +def test_test_iam_permissions(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=['permissions_value'], + ) + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + assert response.permissions == ['permissions_value'] + + +def test_test_iam_permissions_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + client.test_iam_permissions() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = 'grpc_asyncio', request_type=iam_policy_pb2.TestIamPermissionsRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(iam_policy_pb2.TestIamPermissionsResponse( + permissions=['permissions_value'], + )) + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + assert response.permissions == ['permissions_value'] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async_from_dict(): + await test_test_iam_permissions_async(request_type=dict) + + +def test_test_iam_permissions_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + + request.resource = 'resource_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'resource=resource_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + + request.resource = 'resource_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(iam_policy_pb2.TestIamPermissionsResponse()) + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'resource=resource_value', + ) in kw['metadata'] + +def test_test_iam_permissions_from_dict_foreign(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + response = client.test_iam_permissions(request={ + 'resource': 'resource_value', + 'permissions': ['permissions_value'], + } + ) + call.assert_called() + + +def test_test_iam_permissions_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.test_iam_permissions( + resource='resource_value', + permissions=['permissions_value'], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].resource + mock_val = 'resource_value' + assert arg == mock_val + arg = args[0].permissions + mock_val = ['permissions_value'] + assert arg == mock_val + + +def test_test_iam_permissions_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.test_iam_permissions( + iam_policy_pb2.TestIamPermissionsRequest(), + resource='resource_value', + permissions=['permissions_value'], + ) + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(iam_policy_pb2.TestIamPermissionsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.test_iam_permissions( + resource='resource_value', + permissions=['permissions_value'], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].resource + mock_val = 'resource_value' + assert arg == mock_val + arg = args[0].permissions + mock_val = ['permissions_value'] + assert arg == mock_val + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.test_iam_permissions( + iam_policy_pb2.TestIamPermissionsRequest(), + resource='resource_value', + permissions=['permissions_value'], + ) + + +@pytest.mark.parametrize("request_type", [ + gsad_backup.CreateBackupRequest, + dict, +]) +def test_create_backup(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.create_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == gsad_backup.CreateBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_backup_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_backup), + '__call__') as call: + client.create_backup() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == gsad_backup.CreateBackupRequest() + +@pytest.mark.asyncio +async def test_create_backup_async(transport: str = 'grpc_asyncio', request_type=gsad_backup.CreateBackupRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.create_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == gsad_backup.CreateBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_backup_async_from_dict(): + await test_create_backup_async(request_type=dict) + + +def test_create_backup_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = gsad_backup.CreateBackupRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_backup), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.create_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_create_backup_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = gsad_backup.CreateBackupRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_backup), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.create_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_create_backup_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_backup( + parent='parent_value', + backup=gsad_backup.Backup(database='database_value'), + backup_id='backup_id_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + arg = args[0].backup + mock_val = gsad_backup.Backup(database='database_value') + assert arg == mock_val + arg = args[0].backup_id + mock_val = 'backup_id_value' + assert arg == mock_val + + +def test_create_backup_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_backup( + gsad_backup.CreateBackupRequest(), + parent='parent_value', + backup=gsad_backup.Backup(database='database_value'), + backup_id='backup_id_value', + ) + +@pytest.mark.asyncio +async def test_create_backup_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_backup( + parent='parent_value', + backup=gsad_backup.Backup(database='database_value'), + backup_id='backup_id_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + arg = args[0].backup + mock_val = gsad_backup.Backup(database='database_value') + assert arg == mock_val + arg = args[0].backup_id + mock_val = 'backup_id_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_create_backup_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_backup( + gsad_backup.CreateBackupRequest(), + parent='parent_value', + backup=gsad_backup.Backup(database='database_value'), + backup_id='backup_id_value', + ) + + +@pytest.mark.parametrize("request_type", [ + backup.CopyBackupRequest, + dict, +]) +def test_copy_backup(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.copy_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.copy_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == backup.CopyBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_copy_backup_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.copy_backup), + '__call__') as call: + client.copy_backup() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == backup.CopyBackupRequest() + +@pytest.mark.asyncio +async def test_copy_backup_async(transport: str = 'grpc_asyncio', request_type=backup.CopyBackupRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.copy_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.copy_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == backup.CopyBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_copy_backup_async_from_dict(): + await test_copy_backup_async(request_type=dict) + + +def test_copy_backup_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = backup.CopyBackupRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.copy_backup), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.copy_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_copy_backup_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = backup.CopyBackupRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.copy_backup), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.copy_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_copy_backup_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.copy_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.copy_backup( + parent='parent_value', + backup_id='backup_id_value', + source_backup='source_backup_value', + expire_time=timestamp_pb2.Timestamp(seconds=751), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + arg = args[0].backup_id + mock_val = 'backup_id_value' + assert arg == mock_val + arg = args[0].source_backup + mock_val = 'source_backup_value' + assert arg == mock_val + assert TimestampRule().to_proto(args[0].expire_time) == timestamp_pb2.Timestamp(seconds=751) + + +def test_copy_backup_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.copy_backup( + backup.CopyBackupRequest(), + parent='parent_value', + backup_id='backup_id_value', + source_backup='source_backup_value', + expire_time=timestamp_pb2.Timestamp(seconds=751), + ) + +@pytest.mark.asyncio +async def test_copy_backup_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.copy_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.copy_backup( + parent='parent_value', + backup_id='backup_id_value', + source_backup='source_backup_value', + expire_time=timestamp_pb2.Timestamp(seconds=751), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + arg = args[0].backup_id + mock_val = 'backup_id_value' + assert arg == mock_val + arg = args[0].source_backup + mock_val = 'source_backup_value' + assert arg == mock_val + assert TimestampRule().to_proto(args[0].expire_time) == timestamp_pb2.Timestamp(seconds=751) + +@pytest.mark.asyncio +async def test_copy_backup_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.copy_backup( + backup.CopyBackupRequest(), + parent='parent_value', + backup_id='backup_id_value', + source_backup='source_backup_value', + expire_time=timestamp_pb2.Timestamp(seconds=751), + ) + + +@pytest.mark.parametrize("request_type", [ + backup.GetBackupRequest, + dict, +]) +def test_get_backup(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = backup.Backup( + database='database_value', + name='name_value', + size_bytes=1089, + state=backup.Backup.State.CREATING, + referencing_databases=['referencing_databases_value'], + database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + referencing_backups=['referencing_backups_value'], + ) + response = client.get_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == backup.GetBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, backup.Backup) + assert response.database == 'database_value' + assert response.name == 'name_value' + assert response.size_bytes == 1089 + assert response.state == backup.Backup.State.CREATING + assert response.referencing_databases == ['referencing_databases_value'] + assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.referencing_backups == ['referencing_backups_value'] + + +def test_get_backup_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_backup), + '__call__') as call: + client.get_backup() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == backup.GetBackupRequest() + +@pytest.mark.asyncio +async def test_get_backup_async(transport: str = 'grpc_asyncio', request_type=backup.GetBackupRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(backup.Backup( + database='database_value', + name='name_value', + size_bytes=1089, + state=backup.Backup.State.CREATING, + referencing_databases=['referencing_databases_value'], + database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + referencing_backups=['referencing_backups_value'], + )) + response = await client.get_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == backup.GetBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, backup.Backup) + assert response.database == 'database_value' + assert response.name == 'name_value' + assert response.size_bytes == 1089 + assert response.state == backup.Backup.State.CREATING + assert response.referencing_databases == ['referencing_databases_value'] + assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.referencing_backups == ['referencing_backups_value'] + + +@pytest.mark.asyncio +async def test_get_backup_async_from_dict(): + await test_get_backup_async(request_type=dict) + + +def test_get_backup_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = backup.GetBackupRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_backup), + '__call__') as call: + call.return_value = backup.Backup() + client.get_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_get_backup_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = backup.GetBackupRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_backup), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(backup.Backup()) + await client.get_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +def test_get_backup_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = backup.Backup() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_backup( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + + +def test_get_backup_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_backup( + backup.GetBackupRequest(), + name='name_value', + ) + +@pytest.mark.asyncio +async def test_get_backup_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = backup.Backup() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(backup.Backup()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_backup( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_get_backup_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_backup( + backup.GetBackupRequest(), + name='name_value', + ) + + +@pytest.mark.parametrize("request_type", [ + gsad_backup.UpdateBackupRequest, + dict, +]) +def test_update_backup(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = gsad_backup.Backup( + database='database_value', + name='name_value', + size_bytes=1089, + state=gsad_backup.Backup.State.CREATING, + referencing_databases=['referencing_databases_value'], + database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + referencing_backups=['referencing_backups_value'], + ) + response = client.update_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == gsad_backup.UpdateBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gsad_backup.Backup) + assert response.database == 'database_value' + assert response.name == 'name_value' + assert response.size_bytes == 1089 + assert response.state == gsad_backup.Backup.State.CREATING + assert response.referencing_databases == ['referencing_databases_value'] + assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.referencing_backups == ['referencing_backups_value'] + + +def test_update_backup_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_backup), + '__call__') as call: + client.update_backup() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == gsad_backup.UpdateBackupRequest() + +@pytest.mark.asyncio +async def test_update_backup_async(transport: str = 'grpc_asyncio', request_type=gsad_backup.UpdateBackupRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(gsad_backup.Backup( + database='database_value', + name='name_value', + size_bytes=1089, + state=gsad_backup.Backup.State.CREATING, + referencing_databases=['referencing_databases_value'], + database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + referencing_backups=['referencing_backups_value'], + )) + response = await client.update_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == gsad_backup.UpdateBackupRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gsad_backup.Backup) + assert response.database == 'database_value' + assert response.name == 'name_value' + assert response.size_bytes == 1089 + assert response.state == gsad_backup.Backup.State.CREATING + assert response.referencing_databases == ['referencing_databases_value'] + assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.referencing_backups == ['referencing_backups_value'] + + +@pytest.mark.asyncio +async def test_update_backup_async_from_dict(): + await test_update_backup_async(request_type=dict) + + +def test_update_backup_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = gsad_backup.UpdateBackupRequest() + + request.backup.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_backup), + '__call__') as call: + call.return_value = gsad_backup.Backup() + client.update_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'backup.name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_update_backup_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = gsad_backup.UpdateBackupRequest() + + request.backup.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_backup), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gsad_backup.Backup()) + await client.update_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'backup.name=name_value', + ) in kw['metadata'] + + +def test_update_backup_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = gsad_backup.Backup() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_backup( + backup=gsad_backup.Backup(database='database_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].backup + mock_val = gsad_backup.Backup(database='database_value') + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) + assert arg == mock_val + + +def test_update_backup_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_backup( + gsad_backup.UpdateBackupRequest(), + backup=gsad_backup.Backup(database='database_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + +@pytest.mark.asyncio +async def test_update_backup_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = gsad_backup.Backup() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gsad_backup.Backup()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_backup( + backup=gsad_backup.Backup(database='database_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].backup + mock_val = gsad_backup.Backup(database='database_value') + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) + assert arg == mock_val + +@pytest.mark.asyncio +async def test_update_backup_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_backup( + gsad_backup.UpdateBackupRequest(), + backup=gsad_backup.Backup(database='database_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +@pytest.mark.parametrize("request_type", [ + backup.DeleteBackupRequest, + dict, +]) +def test_delete_backup(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == backup.DeleteBackupRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_backup_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_backup), + '__call__') as call: + client.delete_backup() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == backup.DeleteBackupRequest() + +@pytest.mark.asyncio +async def test_delete_backup_async(transport: str = 'grpc_asyncio', request_type=backup.DeleteBackupRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == backup.DeleteBackupRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_backup_async_from_dict(): + await test_delete_backup_async(request_type=dict) + + +def test_delete_backup_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = backup.DeleteBackupRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_backup), + '__call__') as call: + call.return_value = None + client.delete_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_delete_backup_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = backup.DeleteBackupRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_backup), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_backup(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +def test_delete_backup_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_backup( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + + +def test_delete_backup_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_backup( + backup.DeleteBackupRequest(), + name='name_value', + ) + +@pytest.mark.asyncio +async def test_delete_backup_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_backup), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_backup( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_delete_backup_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_backup( + backup.DeleteBackupRequest(), + name='name_value', + ) + + +@pytest.mark.parametrize("request_type", [ + backup.ListBackupsRequest, + dict, +]) +def test_list_backups(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backups), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = backup.ListBackupsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_backups(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == backup.ListBackupsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListBackupsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_backups_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backups), + '__call__') as call: + client.list_backups() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == backup.ListBackupsRequest() + +@pytest.mark.asyncio +async def test_list_backups_async(transport: str = 'grpc_asyncio', request_type=backup.ListBackupsRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backups), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(backup.ListBackupsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_backups(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == backup.ListBackupsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListBackupsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_backups_async_from_dict(): + await test_list_backups_async(request_type=dict) + + +def test_list_backups_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = backup.ListBackupsRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backups), + '__call__') as call: + call.return_value = backup.ListBackupsResponse() + client.list_backups(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_list_backups_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = backup.ListBackupsRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backups), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(backup.ListBackupsResponse()) + await client.list_backups(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_list_backups_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backups), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = backup.ListBackupsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_backups( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + + +def test_list_backups_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_backups( + backup.ListBackupsRequest(), + parent='parent_value', + ) + +@pytest.mark.asyncio +async def test_list_backups_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backups), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = backup.ListBackupsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(backup.ListBackupsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_backups( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_list_backups_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_backups( + backup.ListBackupsRequest(), + parent='parent_value', + ) + + +def test_list_backups_pager(transport_name: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backups), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + backup.Backup(), + backup.Backup(), + ], + next_page_token='abc', + ), + backup.ListBackupsResponse( + backups=[], + next_page_token='def', + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + ], + next_page_token='ghi', + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + backup.Backup(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_backups(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, backup.Backup) + for i in results) +def test_list_backups_pages(transport_name: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backups), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + backup.Backup(), + backup.Backup(), + ], + next_page_token='abc', + ), + backup.ListBackupsResponse( + backups=[], + next_page_token='def', + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + ], + next_page_token='ghi', + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + backup.Backup(), + ], + ), + RuntimeError, + ) + pages = list(client.list_backups(request={}).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.asyncio +async def test_list_backups_async_pager(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backups), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + backup.Backup(), + backup.Backup(), + ], + next_page_token='abc', + ), + backup.ListBackupsResponse( + backups=[], + next_page_token='def', + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + ], + next_page_token='ghi', + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + backup.Backup(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_backups(request={},) + assert async_pager.next_page_token == 'abc' + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, backup.Backup) + for i in responses) + + +@pytest.mark.asyncio +async def test_list_backups_async_pages(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backups), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + backup.Backup(), + backup.Backup(), + ], + next_page_token='abc', + ), + backup.ListBackupsResponse( + backups=[], + next_page_token='def', + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + ], + next_page_token='ghi', + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + backup.Backup(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_backups(request={})).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.RestoreDatabaseRequest, + dict, +]) +def test_restore_database(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.restore_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.restore_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.RestoreDatabaseRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_restore_database_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.restore_database), + '__call__') as call: + client.restore_database() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.RestoreDatabaseRequest() + +@pytest.mark.asyncio +async def test_restore_database_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.RestoreDatabaseRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.restore_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.restore_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.RestoreDatabaseRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_restore_database_async_from_dict(): + await test_restore_database_async(request_type=dict) + + +def test_restore_database_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.RestoreDatabaseRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.restore_database), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.restore_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_restore_database_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.RestoreDatabaseRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.restore_database), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.restore_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_restore_database_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.restore_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.restore_database( + parent='parent_value', + database_id='database_id_value', + backup='backup_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + arg = args[0].database_id + mock_val = 'database_id_value' + assert arg == mock_val + assert args[0].backup == 'backup_value' + + +def test_restore_database_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.restore_database( + spanner_database_admin.RestoreDatabaseRequest(), + parent='parent_value', + database_id='database_id_value', + backup='backup_value', + ) + +@pytest.mark.asyncio +async def test_restore_database_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.restore_database), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.restore_database( + parent='parent_value', + database_id='database_id_value', + backup='backup_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + arg = args[0].database_id + mock_val = 'database_id_value' + assert arg == mock_val + assert args[0].backup == 'backup_value' + +@pytest.mark.asyncio +async def test_restore_database_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.restore_database( + spanner_database_admin.RestoreDatabaseRequest(), + parent='parent_value', + database_id='database_id_value', + backup='backup_value', + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.ListDatabaseOperationsRequest, + dict, +]) +def test_list_database_operations(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_operations), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.ListDatabaseOperationsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_database_operations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.ListDatabaseOperationsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListDatabaseOperationsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_database_operations_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_operations), + '__call__') as call: + client.list_database_operations() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.ListDatabaseOperationsRequest() + +@pytest.mark.asyncio +async def test_list_database_operations_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.ListDatabaseOperationsRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_operations), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabaseOperationsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_database_operations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.ListDatabaseOperationsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListDatabaseOperationsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_database_operations_async_from_dict(): + await test_list_database_operations_async(request_type=dict) + + +def test_list_database_operations_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.ListDatabaseOperationsRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_operations), + '__call__') as call: + call.return_value = spanner_database_admin.ListDatabaseOperationsResponse() + client.list_database_operations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_list_database_operations_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.ListDatabaseOperationsRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_operations), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabaseOperationsResponse()) + await client.list_database_operations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_list_database_operations_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_operations), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.ListDatabaseOperationsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_database_operations( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + + +def test_list_database_operations_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_database_operations( + spanner_database_admin.ListDatabaseOperationsRequest(), + parent='parent_value', + ) + +@pytest.mark.asyncio +async def test_list_database_operations_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_operations), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.ListDatabaseOperationsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabaseOperationsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_database_operations( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_list_database_operations_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_database_operations( + spanner_database_admin.ListDatabaseOperationsRequest(), + parent='parent_value', + ) + + +def test_list_database_operations_pager(transport_name: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_operations), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_database_operations(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, operations_pb2.Operation) + for i in results) +def test_list_database_operations_pages(transport_name: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_operations), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + pages = list(client.list_database_operations(request={}).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.asyncio +async def test_list_database_operations_async_pager(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_operations), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_database_operations(request={},) + assert async_pager.next_page_token == 'abc' + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, operations_pb2.Operation) + for i in responses) + + +@pytest.mark.asyncio +async def test_list_database_operations_async_pages(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_operations), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_database_operations(request={})).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.parametrize("request_type", [ + backup.ListBackupOperationsRequest, + dict, +]) +def test_list_backup_operations(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backup_operations), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = backup.ListBackupOperationsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_backup_operations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == backup.ListBackupOperationsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListBackupOperationsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_backup_operations_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backup_operations), + '__call__') as call: + client.list_backup_operations() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == backup.ListBackupOperationsRequest() + +@pytest.mark.asyncio +async def test_list_backup_operations_async(transport: str = 'grpc_asyncio', request_type=backup.ListBackupOperationsRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backup_operations), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(backup.ListBackupOperationsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_backup_operations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == backup.ListBackupOperationsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListBackupOperationsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_backup_operations_async_from_dict(): + await test_list_backup_operations_async(request_type=dict) + + +def test_list_backup_operations_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = backup.ListBackupOperationsRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backup_operations), + '__call__') as call: + call.return_value = backup.ListBackupOperationsResponse() + client.list_backup_operations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_list_backup_operations_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = backup.ListBackupOperationsRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backup_operations), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(backup.ListBackupOperationsResponse()) + await client.list_backup_operations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_list_backup_operations_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backup_operations), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = backup.ListBackupOperationsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_backup_operations( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + + +def test_list_backup_operations_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_backup_operations( + backup.ListBackupOperationsRequest(), + parent='parent_value', + ) + +@pytest.mark.asyncio +async def test_list_backup_operations_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backup_operations), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = backup.ListBackupOperationsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(backup.ListBackupOperationsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_backup_operations( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_list_backup_operations_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_backup_operations( + backup.ListBackupOperationsRequest(), + parent='parent_value', + ) + + +def test_list_backup_operations_pager(transport_name: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backup_operations), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + backup.ListBackupOperationsResponse( + operations=[], + next_page_token='def', + ), + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_backup_operations(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, operations_pb2.Operation) + for i in results) +def test_list_backup_operations_pages(transport_name: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backup_operations), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + backup.ListBackupOperationsResponse( + operations=[], + next_page_token='def', + ), + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + pages = list(client.list_backup_operations(request={}).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.asyncio +async def test_list_backup_operations_async_pager(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backup_operations), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + backup.ListBackupOperationsResponse( + operations=[], + next_page_token='def', + ), + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_backup_operations(request={},) + assert async_pager.next_page_token == 'abc' + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, operations_pb2.Operation) + for i in responses) + + +@pytest.mark.asyncio +async def test_list_backup_operations_async_pages(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_backup_operations), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + backup.ListBackupOperationsResponse( + operations=[], + next_page_token='def', + ), + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_backup_operations(request={})).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.ListDatabaseRolesRequest, + dict, +]) +def test_list_database_roles(request_type, transport: str = 'grpc'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_roles), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.ListDatabaseRolesResponse( + next_page_token='next_page_token_value', + ) + response = client.list_database_roles(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.ListDatabaseRolesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListDatabaseRolesPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_database_roles_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_roles), + '__call__') as call: + client.list_database_roles() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.ListDatabaseRolesRequest() + +@pytest.mark.asyncio +async def test_list_database_roles_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.ListDatabaseRolesRequest): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_roles), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabaseRolesResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_database_roles(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.ListDatabaseRolesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListDatabaseRolesAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_database_roles_async_from_dict(): + await test_list_database_roles_async(request_type=dict) + + +def test_list_database_roles_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.ListDatabaseRolesRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_roles), + '__call__') as call: + call.return_value = spanner_database_admin.ListDatabaseRolesResponse() + client.list_database_roles(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_list_database_roles_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.ListDatabaseRolesRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_roles), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabaseRolesResponse()) + await client.list_database_roles(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_list_database_roles_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_roles), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.ListDatabaseRolesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_database_roles( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + + +def test_list_database_roles_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_database_roles( + spanner_database_admin.ListDatabaseRolesRequest(), + parent='parent_value', + ) + +@pytest.mark.asyncio +async def test_list_database_roles_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_roles), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_database_admin.ListDatabaseRolesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabaseRolesResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_database_roles( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_list_database_roles_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_database_roles( + spanner_database_admin.ListDatabaseRolesRequest(), + parent='parent_value', + ) + + +def test_list_database_roles_pager(transport_name: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_roles), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_database_roles(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, spanner_database_admin.DatabaseRole) + for i in results) +def test_list_database_roles_pages(transport_name: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_roles), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + ], + ), + RuntimeError, + ) + pages = list(client.list_database_roles(request={}).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.asyncio +async def test_list_database_roles_async_pager(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_roles), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_database_roles(request={},) + assert async_pager.next_page_token == 'abc' + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, spanner_database_admin.DatabaseRole) + for i in responses) + + +@pytest.mark.asyncio +async def test_list_database_roles_async_pages(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_database_roles), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_database_roles(request={})).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.ListDatabasesRequest, + dict, +]) +def test_list_databases_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.ListDatabasesResponse( + next_page_token='next_page_token_value', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_database_admin.ListDatabasesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.list_databases(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListDatabasesPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_databases_rest_required_fields(request_type=spanner_database_admin.ListDatabasesRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_databases._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_databases._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("page_size", "page_token", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.ListDatabasesResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner_database_admin.ListDatabasesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.list_databases(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_list_databases_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.list_databases._get_unset_required_fields({}) + assert set(unset_fields) == (set(("pageSize", "pageToken", )) & set(("parent", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_databases_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_list_databases") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_list_databases") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_database_admin.ListDatabasesRequest.pb(spanner_database_admin.ListDatabasesRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner_database_admin.ListDatabasesResponse.to_json(spanner_database_admin.ListDatabasesResponse()) + + request = spanner_database_admin.ListDatabasesRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner_database_admin.ListDatabasesResponse() + + client.list_databases(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_list_databases_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.ListDatabasesRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.list_databases(request) + + +def test_list_databases_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.ListDatabasesResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'projects/sample1/instances/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_database_admin.ListDatabasesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.list_databases(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/databases" % client.transport._host, args[1]) + + +def test_list_databases_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_databases( + spanner_database_admin.ListDatabasesRequest(), + parent='parent_value', + ) + + +def test_list_databases_rest_pager(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + #with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + spanner_database_admin.Database(), + spanner_database_admin.Database(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabasesResponse( + databases=[ + spanner_database_admin.Database(), + spanner_database_admin.Database(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(spanner_database_admin.ListDatabasesResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode('UTF-8') + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {'parent': 'projects/sample1/instances/sample2'} + + pager = client.list_databases(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, spanner_database_admin.Database) + for i in results) + + pages = list(client.list_databases(request=sample_request).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.CreateDatabaseRequest, + dict, +]) +def test_create_database_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.create_database(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_create_database_rest_required_fields(request_type=spanner_database_admin.CreateDatabaseRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["create_statement"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_database._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + jsonified_request["createStatement"] = 'create_statement_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_database._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + assert "createStatement" in jsonified_request + assert jsonified_request["createStatement"] == 'create_statement_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.create_database(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_create_database_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.create_database._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("parent", "createStatement", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_database_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(operation.Operation, "_set_result_from_operation"), \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_create_database") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_create_database") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_database_admin.CreateDatabaseRequest.pb(spanner_database_admin.CreateDatabaseRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) + + request = spanner_database_admin.CreateDatabaseRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.create_database(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_create_database_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.CreateDatabaseRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.create_database(request) + + +def test_create_database_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'projects/sample1/instances/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + create_statement='create_statement_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.create_database(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/databases" % client.transport._host, args[1]) + + +def test_create_database_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_database( + spanner_database_admin.CreateDatabaseRequest(), + parent='parent_value', + create_statement='create_statement_value', + ) + + +def test_create_database_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.GetDatabaseRequest, + dict, +]) +def test_get_database_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.Database( + name='name_value', + state=spanner_database_admin.Database.State.CREATING, + version_retention_period='version_retention_period_value', + default_leader='default_leader_value', + database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + enable_drop_protection=True, + reconciling=True, + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_database_admin.Database.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.get_database(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner_database_admin.Database) + assert response.name == 'name_value' + assert response.state == spanner_database_admin.Database.State.CREATING + assert response.version_retention_period == 'version_retention_period_value' + assert response.default_leader == 'default_leader_value' + assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.enable_drop_protection is True + assert response.reconciling is True + + +def test_get_database_rest_required_fields(request_type=spanner_database_admin.GetDatabaseRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_database._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = 'name_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_database._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == 'name_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.Database() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner_database_admin.Database.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.get_database(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_get_database_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.get_database._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_database_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_get_database") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_get_database") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_database_admin.GetDatabaseRequest.pb(spanner_database_admin.GetDatabaseRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner_database_admin.Database.to_json(spanner_database_admin.Database()) + + request = spanner_database_admin.GetDatabaseRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner_database_admin.Database() + + client.get_database(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_get_database_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.GetDatabaseRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.get_database(request) + + +def test_get_database_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.Database() + + # get arguments that satisfy an http rule for this method + sample_request = {'name': 'projects/sample1/instances/sample2/databases/sample3'} + + # get truthy value for each flattened field + mock_args = dict( + name='name_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_database_admin.Database.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.get_database(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{name=projects/*/instances/*/databases/*}" % client.transport._host, args[1]) + + +def test_get_database_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_database( + spanner_database_admin.GetDatabaseRequest(), + name='name_value', + ) + + +def test_get_database_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.UpdateDatabaseRequest, + dict, +]) +def test_update_database_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'database': {'name': 'projects/sample1/instances/sample2/databases/sample3'}} + request_init["database"] = {'name': 'projects/sample1/instances/sample2/databases/sample3', 'state': 1, 'create_time': {'seconds': 751, 'nanos': 543}, 'restore_info': {'source_type': 1, 'backup_info': {'backup': 'backup_value', 'version_time': {}, 'create_time': {}, 'source_database': 'source_database_value'}}, 'encryption_config': {'kms_key_name': 'kms_key_name_value'}, 'encryption_info': [{'encryption_type': 1, 'encryption_status': {'code': 411, 'message': 'message_value', 'details': [{'type_url': 'type.googleapis.com/google.protobuf.Duration', 'value': b'\x08\x0c\x10\xdb\x07'}]}, 'kms_key_version': 'kms_key_version_value'}], 'version_retention_period': 'version_retention_period_value', 'earliest_version_time': {}, 'default_leader': 'default_leader_value', 'database_dialect': 1, 'enable_drop_protection': True, 'reconciling': True} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.update_database(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_update_database_rest_required_fields(request_type=spanner_database_admin.UpdateDatabaseRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_database._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_database._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("update_mask", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "patch", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.update_database(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_update_database_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.update_database._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask", )) & set(("database", "updateMask", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_database_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(operation.Operation, "_set_result_from_operation"), \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_update_database") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_update_database") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_database_admin.UpdateDatabaseRequest.pb(spanner_database_admin.UpdateDatabaseRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) + + request = spanner_database_admin.UpdateDatabaseRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.update_database(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_update_database_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.UpdateDatabaseRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'database': {'name': 'projects/sample1/instances/sample2/databases/sample3'}} + request_init["database"] = {'name': 'projects/sample1/instances/sample2/databases/sample3', 'state': 1, 'create_time': {'seconds': 751, 'nanos': 543}, 'restore_info': {'source_type': 1, 'backup_info': {'backup': 'backup_value', 'version_time': {}, 'create_time': {}, 'source_database': 'source_database_value'}}, 'encryption_config': {'kms_key_name': 'kms_key_name_value'}, 'encryption_info': [{'encryption_type': 1, 'encryption_status': {'code': 411, 'message': 'message_value', 'details': [{'type_url': 'type.googleapis.com/google.protobuf.Duration', 'value': b'\x08\x0c\x10\xdb\x07'}]}, 'kms_key_version': 'kms_key_version_value'}], 'version_retention_period': 'version_retention_period_value', 'earliest_version_time': {}, 'default_leader': 'default_leader_value', 'database_dialect': 1, 'enable_drop_protection': True, 'reconciling': True} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.update_database(request) + + +def test_update_database_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # get arguments that satisfy an http rule for this method + sample_request = {'database': {'name': 'projects/sample1/instances/sample2/databases/sample3'}} + + # get truthy value for each flattened field + mock_args = dict( + database=spanner_database_admin.Database(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.update_database(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{database.name=projects/*/instances/*/databases/*}" % client.transport._host, args[1]) + + +def test_update_database_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_database( + spanner_database_admin.UpdateDatabaseRequest(), + database=spanner_database_admin.Database(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +def test_update_database_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.UpdateDatabaseDdlRequest, + dict, +]) +def test_update_database_ddl_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.update_database_ddl(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_update_database_ddl_rest_required_fields(request_type=spanner_database_admin.UpdateDatabaseDdlRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["database"] = "" + request_init["statements"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_database_ddl._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["database"] = 'database_value' + jsonified_request["statements"] = 'statements_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_database_ddl._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "database" in jsonified_request + assert jsonified_request["database"] == 'database_value' + assert "statements" in jsonified_request + assert jsonified_request["statements"] == 'statements_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "patch", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.update_database_ddl(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_update_database_ddl_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.update_database_ddl._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("database", "statements", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_database_ddl_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(operation.Operation, "_set_result_from_operation"), \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_update_database_ddl") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_update_database_ddl") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_database_admin.UpdateDatabaseDdlRequest.pb(spanner_database_admin.UpdateDatabaseDdlRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) + + request = spanner_database_admin.UpdateDatabaseDdlRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.update_database_ddl(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_update_database_ddl_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.UpdateDatabaseDdlRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.update_database_ddl(request) + + +def test_update_database_ddl_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # get arguments that satisfy an http rule for this method + sample_request = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + + # get truthy value for each flattened field + mock_args = dict( + database='database_value', + statements=['statements_value'], + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.update_database_ddl(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{database=projects/*/instances/*/databases/*}/ddl" % client.transport._host, args[1]) + + +def test_update_database_ddl_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_database_ddl( + spanner_database_admin.UpdateDatabaseDdlRequest(), + database='database_value', + statements=['statements_value'], + ) + + +def test_update_database_ddl_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.DropDatabaseRequest, + dict, +]) +def test_drop_database_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.drop_database(request) + + # Establish that the response is the type that we expect. + assert response is None + + +def test_drop_database_rest_required_fields(request_type=spanner_database_admin.DropDatabaseRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["database"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).drop_database._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["database"] = 'database_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).drop_database._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "database" in jsonified_request + assert jsonified_request["database"] == 'database_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = None + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "delete", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.drop_database(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_drop_database_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.drop_database._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("database", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_drop_database_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_drop_database") as pre: + pre.assert_not_called() + pb_message = spanner_database_admin.DropDatabaseRequest.pb(spanner_database_admin.DropDatabaseRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + + request = spanner_database_admin.DropDatabaseRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + + client.drop_database(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + + +def test_drop_database_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.DropDatabaseRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.drop_database(request) + + +def test_drop_database_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # get arguments that satisfy an http rule for this method + sample_request = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + + # get truthy value for each flattened field + mock_args = dict( + database='database_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.drop_database(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{database=projects/*/instances/*/databases/*}" % client.transport._host, args[1]) + + +def test_drop_database_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.drop_database( + spanner_database_admin.DropDatabaseRequest(), + database='database_value', + ) + + +def test_drop_database_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.GetDatabaseDdlRequest, + dict, +]) +def test_get_database_ddl_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.GetDatabaseDdlResponse( + statements=['statements_value'], + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_database_admin.GetDatabaseDdlResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.get_database_ddl(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner_database_admin.GetDatabaseDdlResponse) + assert response.statements == ['statements_value'] + + +def test_get_database_ddl_rest_required_fields(request_type=spanner_database_admin.GetDatabaseDdlRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["database"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_database_ddl._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["database"] = 'database_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_database_ddl._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "database" in jsonified_request + assert jsonified_request["database"] == 'database_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.GetDatabaseDdlResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner_database_admin.GetDatabaseDdlResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.get_database_ddl(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_get_database_ddl_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.get_database_ddl._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("database", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_database_ddl_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_get_database_ddl") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_get_database_ddl") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_database_admin.GetDatabaseDdlRequest.pb(spanner_database_admin.GetDatabaseDdlRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner_database_admin.GetDatabaseDdlResponse.to_json(spanner_database_admin.GetDatabaseDdlResponse()) + + request = spanner_database_admin.GetDatabaseDdlRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner_database_admin.GetDatabaseDdlResponse() + + client.get_database_ddl(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_get_database_ddl_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.GetDatabaseDdlRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.get_database_ddl(request) + + +def test_get_database_ddl_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.GetDatabaseDdlResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'database': 'projects/sample1/instances/sample2/databases/sample3'} + + # get truthy value for each flattened field + mock_args = dict( + database='database_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_database_admin.GetDatabaseDdlResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.get_database_ddl(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{database=projects/*/instances/*/databases/*}/ddl" % client.transport._host, args[1]) + + +def test_get_database_ddl_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_database_ddl( + spanner_database_admin.GetDatabaseDdlRequest(), + database='database_value', + ) + + +def test_get_database_ddl_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + iam_policy_pb2.SetIamPolicyRequest, + dict, +]) +def test_set_iam_policy_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = policy_pb2.Policy( + version=774, + etag=b'etag_blob', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.set_iam_policy(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b'etag_blob' + + +def test_set_iam_policy_rest_required_fields(request_type=iam_policy_pb2.SetIamPolicyRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["resource"] = "" + request = request_type(**request_init) + pb_request = request + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).set_iam_policy._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["resource"] = 'resource_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).set_iam_policy._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "resource" in jsonified_request + assert jsonified_request["resource"] == 'resource_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = policy_pb2.Policy() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.set_iam_policy(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_set_iam_policy_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.set_iam_policy._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("resource", "policy", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_set_iam_policy_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_set_iam_policy") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_set_iam_policy") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = iam_policy_pb2.SetIamPolicyRequest() + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(policy_pb2.Policy()) + + request = iam_policy_pb2.SetIamPolicyRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = policy_pb2.Policy() + + client.set_iam_policy(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_set_iam_policy_rest_bad_request(transport: str = 'rest', request_type=iam_policy_pb2.SetIamPolicyRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.set_iam_policy(request) + + +def test_set_iam_policy_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = policy_pb2.Policy() + + # get arguments that satisfy an http rule for this method + sample_request = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} + + # get truthy value for each flattened field + mock_args = dict( + resource='resource_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.set_iam_policy(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{resource=projects/*/instances/*/databases/*}:setIamPolicy" % client.transport._host, args[1]) + + +def test_set_iam_policy_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.set_iam_policy( + iam_policy_pb2.SetIamPolicyRequest(), + resource='resource_value', + ) + + +def test_set_iam_policy_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + iam_policy_pb2.GetIamPolicyRequest, + dict, +]) +def test_get_iam_policy_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = policy_pb2.Policy( + version=774, + etag=b'etag_blob', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.get_iam_policy(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b'etag_blob' + + +def test_get_iam_policy_rest_required_fields(request_type=iam_policy_pb2.GetIamPolicyRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["resource"] = "" + request = request_type(**request_init) + pb_request = request + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_iam_policy._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["resource"] = 'resource_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_iam_policy._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "resource" in jsonified_request + assert jsonified_request["resource"] == 'resource_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = policy_pb2.Policy() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.get_iam_policy(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_get_iam_policy_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.get_iam_policy._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("resource", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_iam_policy_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_get_iam_policy") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_get_iam_policy") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = iam_policy_pb2.GetIamPolicyRequest() + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(policy_pb2.Policy()) + + request = iam_policy_pb2.GetIamPolicyRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = policy_pb2.Policy() + + client.get_iam_policy(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_get_iam_policy_rest_bad_request(transport: str = 'rest', request_type=iam_policy_pb2.GetIamPolicyRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.get_iam_policy(request) + + +def test_get_iam_policy_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = policy_pb2.Policy() + + # get arguments that satisfy an http rule for this method + sample_request = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} + + # get truthy value for each flattened field + mock_args = dict( + resource='resource_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.get_iam_policy(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{resource=projects/*/instances/*/databases/*}:getIamPolicy" % client.transport._host, args[1]) + + +def test_get_iam_policy_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_iam_policy( + iam_policy_pb2.GetIamPolicyRequest(), + resource='resource_value', + ) + + +def test_get_iam_policy_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + iam_policy_pb2.TestIamPermissionsRequest, + dict, +]) +def test_test_iam_permissions_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=['permissions_value'], + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.test_iam_permissions(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + assert response.permissions == ['permissions_value'] + + +def test_test_iam_permissions_rest_required_fields(request_type=iam_policy_pb2.TestIamPermissionsRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["resource"] = "" + request_init["permissions"] = "" + request = request_type(**request_init) + pb_request = request + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).test_iam_permissions._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["resource"] = 'resource_value' + jsonified_request["permissions"] = 'permissions_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).test_iam_permissions._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "resource" in jsonified_request + assert jsonified_request["resource"] == 'resource_value' + assert "permissions" in jsonified_request + assert jsonified_request["permissions"] == 'permissions_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = iam_policy_pb2.TestIamPermissionsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.test_iam_permissions(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_test_iam_permissions_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.test_iam_permissions._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("resource", "permissions", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_test_iam_permissions_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_test_iam_permissions") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_test_iam_permissions") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = iam_policy_pb2.TestIamPermissionsRequest() + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(iam_policy_pb2.TestIamPermissionsResponse()) + + request = iam_policy_pb2.TestIamPermissionsRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_test_iam_permissions_rest_bad_request(transport: str = 'rest', request_type=iam_policy_pb2.TestIamPermissionsRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.test_iam_permissions(request) + + +def test_test_iam_permissions_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = iam_policy_pb2.TestIamPermissionsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} + + # get truthy value for each flattened field + mock_args = dict( + resource='resource_value', + permissions=['permissions_value'], + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.test_iam_permissions(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{resource=projects/*/instances/*/databases/*}:testIamPermissions" % client.transport._host, args[1]) + + +def test_test_iam_permissions_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.test_iam_permissions( + iam_policy_pb2.TestIamPermissionsRequest(), + resource='resource_value', + permissions=['permissions_value'], + ) + + +def test_test_iam_permissions_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + gsad_backup.CreateBackupRequest, + dict, +]) +def test_create_backup_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request_init["backup"] = {'database': 'database_value', 'version_time': {'seconds': 751, 'nanos': 543}, 'expire_time': {}, 'name': 'name_value', 'create_time': {}, 'size_bytes': 1089, 'state': 1, 'referencing_databases': ['referencing_databases_value1', 'referencing_databases_value2'], 'encryption_info': {'encryption_type': 1, 'encryption_status': {'code': 411, 'message': 'message_value', 'details': [{'type_url': 'type.googleapis.com/google.protobuf.Duration', 'value': b'\x08\x0c\x10\xdb\x07'}]}, 'kms_key_version': 'kms_key_version_value'}, 'database_dialect': 1, 'referencing_backups': ['referencing_backups_value1', 'referencing_backups_value2'], 'max_expire_time': {}} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.create_backup(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_create_backup_rest_required_fields(request_type=gsad_backup.CreateBackupRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["backup_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + assert "backupId" not in jsonified_request + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_backup._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "backupId" in jsonified_request + assert jsonified_request["backupId"] == request_init["backup_id"] + + jsonified_request["parent"] = 'parent_value' + jsonified_request["backupId"] = 'backup_id_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_backup._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("backup_id", "encryption_config", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + assert "backupId" in jsonified_request + assert jsonified_request["backupId"] == 'backup_id_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.create_backup(request) + + expected_params = [ + ( + "backupId", + "", + ), + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_create_backup_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.create_backup._get_unset_required_fields({}) + assert set(unset_fields) == (set(("backupId", "encryptionConfig", )) & set(("parent", "backupId", "backup", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_backup_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(operation.Operation, "_set_result_from_operation"), \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_create_backup") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_create_backup") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = gsad_backup.CreateBackupRequest.pb(gsad_backup.CreateBackupRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) + + request = gsad_backup.CreateBackupRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.create_backup(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_create_backup_rest_bad_request(transport: str = 'rest', request_type=gsad_backup.CreateBackupRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request_init["backup"] = {'database': 'database_value', 'version_time': {'seconds': 751, 'nanos': 543}, 'expire_time': {}, 'name': 'name_value', 'create_time': {}, 'size_bytes': 1089, 'state': 1, 'referencing_databases': ['referencing_databases_value1', 'referencing_databases_value2'], 'encryption_info': {'encryption_type': 1, 'encryption_status': {'code': 411, 'message': 'message_value', 'details': [{'type_url': 'type.googleapis.com/google.protobuf.Duration', 'value': b'\x08\x0c\x10\xdb\x07'}]}, 'kms_key_version': 'kms_key_version_value'}, 'database_dialect': 1, 'referencing_backups': ['referencing_backups_value1', 'referencing_backups_value2'], 'max_expire_time': {}} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.create_backup(request) + + +def test_create_backup_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'projects/sample1/instances/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + backup=gsad_backup.Backup(database='database_value'), + backup_id='backup_id_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.create_backup(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/backups" % client.transport._host, args[1]) + + +def test_create_backup_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_backup( + gsad_backup.CreateBackupRequest(), + parent='parent_value', + backup=gsad_backup.Backup(database='database_value'), + backup_id='backup_id_value', + ) + + +def test_create_backup_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + backup.CopyBackupRequest, + dict, +]) +def test_copy_backup_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.copy_backup(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_copy_backup_rest_required_fields(request_type=backup.CopyBackupRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["backup_id"] = "" + request_init["source_backup"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).copy_backup._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + jsonified_request["backupId"] = 'backup_id_value' + jsonified_request["sourceBackup"] = 'source_backup_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).copy_backup._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + assert "backupId" in jsonified_request + assert jsonified_request["backupId"] == 'backup_id_value' + assert "sourceBackup" in jsonified_request + assert jsonified_request["sourceBackup"] == 'source_backup_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.copy_backup(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_copy_backup_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.copy_backup._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("parent", "backupId", "sourceBackup", "expireTime", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_copy_backup_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(operation.Operation, "_set_result_from_operation"), \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_copy_backup") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_copy_backup") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = backup.CopyBackupRequest.pb(backup.CopyBackupRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) + + request = backup.CopyBackupRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.copy_backup(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_copy_backup_rest_bad_request(transport: str = 'rest', request_type=backup.CopyBackupRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.copy_backup(request) + + +def test_copy_backup_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'projects/sample1/instances/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + backup_id='backup_id_value', + source_backup='source_backup_value', + expire_time=timestamp_pb2.Timestamp(seconds=751), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.copy_backup(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/backups:copy" % client.transport._host, args[1]) + + +def test_copy_backup_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.copy_backup( + backup.CopyBackupRequest(), + parent='parent_value', + backup_id='backup_id_value', + source_backup='source_backup_value', + expire_time=timestamp_pb2.Timestamp(seconds=751), + ) + + +def test_copy_backup_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + backup.GetBackupRequest, + dict, +]) +def test_get_backup_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instances/sample2/backups/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = backup.Backup( + database='database_value', + name='name_value', + size_bytes=1089, + state=backup.Backup.State.CREATING, + referencing_databases=['referencing_databases_value'], + database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + referencing_backups=['referencing_backups_value'], + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = backup.Backup.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.get_backup(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, backup.Backup) + assert response.database == 'database_value' + assert response.name == 'name_value' + assert response.size_bytes == 1089 + assert response.state == backup.Backup.State.CREATING + assert response.referencing_databases == ['referencing_databases_value'] + assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.referencing_backups == ['referencing_backups_value'] + + +def test_get_backup_rest_required_fields(request_type=backup.GetBackupRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_backup._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = 'name_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_backup._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == 'name_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = backup.Backup() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = backup.Backup.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.get_backup(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_get_backup_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.get_backup._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_backup_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_get_backup") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_get_backup") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = backup.GetBackupRequest.pb(backup.GetBackupRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = backup.Backup.to_json(backup.Backup()) + + request = backup.GetBackupRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = backup.Backup() + + client.get_backup(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_get_backup_rest_bad_request(transport: str = 'rest', request_type=backup.GetBackupRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instances/sample2/backups/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.get_backup(request) + + +def test_get_backup_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = backup.Backup() + + # get arguments that satisfy an http rule for this method + sample_request = {'name': 'projects/sample1/instances/sample2/backups/sample3'} + + # get truthy value for each flattened field + mock_args = dict( + name='name_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = backup.Backup.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.get_backup(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{name=projects/*/instances/*/backups/*}" % client.transport._host, args[1]) + + +def test_get_backup_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_backup( + backup.GetBackupRequest(), + name='name_value', + ) + + +def test_get_backup_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + gsad_backup.UpdateBackupRequest, + dict, +]) +def test_update_backup_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'backup': {'name': 'projects/sample1/instances/sample2/backups/sample3'}} + request_init["backup"] = {'database': 'database_value', 'version_time': {'seconds': 751, 'nanos': 543}, 'expire_time': {}, 'name': 'projects/sample1/instances/sample2/backups/sample3', 'create_time': {}, 'size_bytes': 1089, 'state': 1, 'referencing_databases': ['referencing_databases_value1', 'referencing_databases_value2'], 'encryption_info': {'encryption_type': 1, 'encryption_status': {'code': 411, 'message': 'message_value', 'details': [{'type_url': 'type.googleapis.com/google.protobuf.Duration', 'value': b'\x08\x0c\x10\xdb\x07'}]}, 'kms_key_version': 'kms_key_version_value'}, 'database_dialect': 1, 'referencing_backups': ['referencing_backups_value1', 'referencing_backups_value2'], 'max_expire_time': {}} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = gsad_backup.Backup( + database='database_value', + name='name_value', + size_bytes=1089, + state=gsad_backup.Backup.State.CREATING, + referencing_databases=['referencing_databases_value'], + database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + referencing_backups=['referencing_backups_value'], + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = gsad_backup.Backup.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.update_backup(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, gsad_backup.Backup) + assert response.database == 'database_value' + assert response.name == 'name_value' + assert response.size_bytes == 1089 + assert response.state == gsad_backup.Backup.State.CREATING + assert response.referencing_databases == ['referencing_databases_value'] + assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.referencing_backups == ['referencing_backups_value'] + + +def test_update_backup_rest_required_fields(request_type=gsad_backup.UpdateBackupRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_backup._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_backup._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("update_mask", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = gsad_backup.Backup() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "patch", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = gsad_backup.Backup.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.update_backup(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_update_backup_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.update_backup._get_unset_required_fields({}) + assert set(unset_fields) == (set(("updateMask", )) & set(("backup", "updateMask", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_backup_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_update_backup") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_update_backup") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = gsad_backup.UpdateBackupRequest.pb(gsad_backup.UpdateBackupRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = gsad_backup.Backup.to_json(gsad_backup.Backup()) + + request = gsad_backup.UpdateBackupRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = gsad_backup.Backup() + + client.update_backup(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_update_backup_rest_bad_request(transport: str = 'rest', request_type=gsad_backup.UpdateBackupRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'backup': {'name': 'projects/sample1/instances/sample2/backups/sample3'}} + request_init["backup"] = {'database': 'database_value', 'version_time': {'seconds': 751, 'nanos': 543}, 'expire_time': {}, 'name': 'projects/sample1/instances/sample2/backups/sample3', 'create_time': {}, 'size_bytes': 1089, 'state': 1, 'referencing_databases': ['referencing_databases_value1', 'referencing_databases_value2'], 'encryption_info': {'encryption_type': 1, 'encryption_status': {'code': 411, 'message': 'message_value', 'details': [{'type_url': 'type.googleapis.com/google.protobuf.Duration', 'value': b'\x08\x0c\x10\xdb\x07'}]}, 'kms_key_version': 'kms_key_version_value'}, 'database_dialect': 1, 'referencing_backups': ['referencing_backups_value1', 'referencing_backups_value2'], 'max_expire_time': {}} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.update_backup(request) + + +def test_update_backup_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = gsad_backup.Backup() + + # get arguments that satisfy an http rule for this method + sample_request = {'backup': {'name': 'projects/sample1/instances/sample2/backups/sample3'}} + + # get truthy value for each flattened field + mock_args = dict( + backup=gsad_backup.Backup(database='database_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = gsad_backup.Backup.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.update_backup(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{backup.name=projects/*/instances/*/backups/*}" % client.transport._host, args[1]) + + +def test_update_backup_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_backup( + gsad_backup.UpdateBackupRequest(), + backup=gsad_backup.Backup(database='database_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +def test_update_backup_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + backup.DeleteBackupRequest, + dict, +]) +def test_delete_backup_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instances/sample2/backups/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.delete_backup(request) + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_backup_rest_required_fields(request_type=backup.DeleteBackupRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_backup._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = 'name_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_backup._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == 'name_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = None + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "delete", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.delete_backup(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_delete_backup_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.delete_backup._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_backup_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_delete_backup") as pre: + pre.assert_not_called() + pb_message = backup.DeleteBackupRequest.pb(backup.DeleteBackupRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + + request = backup.DeleteBackupRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + + client.delete_backup(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + + +def test_delete_backup_rest_bad_request(transport: str = 'rest', request_type=backup.DeleteBackupRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instances/sample2/backups/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.delete_backup(request) + + +def test_delete_backup_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # get arguments that satisfy an http rule for this method + sample_request = {'name': 'projects/sample1/instances/sample2/backups/sample3'} + + # get truthy value for each flattened field + mock_args = dict( + name='name_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.delete_backup(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{name=projects/*/instances/*/backups/*}" % client.transport._host, args[1]) + + +def test_delete_backup_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_backup( + backup.DeleteBackupRequest(), + name='name_value', + ) + + +def test_delete_backup_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + backup.ListBackupsRequest, + dict, +]) +def test_list_backups_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = backup.ListBackupsResponse( + next_page_token='next_page_token_value', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = backup.ListBackupsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.list_backups(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListBackupsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_backups_rest_required_fields(request_type=backup.ListBackupsRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_backups._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_backups._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("filter", "page_size", "page_token", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = backup.ListBackupsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = backup.ListBackupsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.list_backups(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_list_backups_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.list_backups._get_unset_required_fields({}) + assert set(unset_fields) == (set(("filter", "pageSize", "pageToken", )) & set(("parent", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_backups_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_list_backups") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_list_backups") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = backup.ListBackupsRequest.pb(backup.ListBackupsRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = backup.ListBackupsResponse.to_json(backup.ListBackupsResponse()) + + request = backup.ListBackupsRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = backup.ListBackupsResponse() + + client.list_backups(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_list_backups_rest_bad_request(transport: str = 'rest', request_type=backup.ListBackupsRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.list_backups(request) + + +def test_list_backups_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = backup.ListBackupsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'projects/sample1/instances/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = backup.ListBackupsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.list_backups(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/backups" % client.transport._host, args[1]) + + +def test_list_backups_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_backups( + backup.ListBackupsRequest(), + parent='parent_value', + ) + + +def test_list_backups_rest_pager(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + #with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + backup.Backup(), + backup.Backup(), + ], + next_page_token='abc', + ), + backup.ListBackupsResponse( + backups=[], + next_page_token='def', + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + ], + next_page_token='ghi', + ), + backup.ListBackupsResponse( + backups=[ + backup.Backup(), + backup.Backup(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(backup.ListBackupsResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode('UTF-8') + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {'parent': 'projects/sample1/instances/sample2'} + + pager = client.list_backups(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, backup.Backup) + for i in results) + + pages = list(client.list_backups(request=sample_request).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.RestoreDatabaseRequest, + dict, +]) +def test_restore_database_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.restore_database(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_restore_database_rest_required_fields(request_type=spanner_database_admin.RestoreDatabaseRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["database_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).restore_database._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + jsonified_request["databaseId"] = 'database_id_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).restore_database._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + assert "databaseId" in jsonified_request + assert jsonified_request["databaseId"] == 'database_id_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.restore_database(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_restore_database_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.restore_database._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("parent", "databaseId", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_restore_database_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(operation.Operation, "_set_result_from_operation"), \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_restore_database") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_restore_database") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_database_admin.RestoreDatabaseRequest.pb(spanner_database_admin.RestoreDatabaseRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) + + request = spanner_database_admin.RestoreDatabaseRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.restore_database(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_restore_database_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.RestoreDatabaseRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.restore_database(request) + + +def test_restore_database_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'projects/sample1/instances/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + database_id='database_id_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.restore_database(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/databases:restore" % client.transport._host, args[1]) + + +def test_restore_database_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.restore_database( + spanner_database_admin.RestoreDatabaseRequest(), + parent='parent_value', + database_id='database_id_value', + backup='backup_value', + ) + + +def test_restore_database_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.ListDatabaseOperationsRequest, + dict, +]) +def test_list_database_operations_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.ListDatabaseOperationsResponse( + next_page_token='next_page_token_value', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_database_admin.ListDatabaseOperationsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.list_database_operations(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListDatabaseOperationsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_database_operations_rest_required_fields(request_type=spanner_database_admin.ListDatabaseOperationsRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_database_operations._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_database_operations._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("filter", "page_size", "page_token", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.ListDatabaseOperationsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner_database_admin.ListDatabaseOperationsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.list_database_operations(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_list_database_operations_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.list_database_operations._get_unset_required_fields({}) + assert set(unset_fields) == (set(("filter", "pageSize", "pageToken", )) & set(("parent", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_database_operations_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_list_database_operations") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_list_database_operations") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_database_admin.ListDatabaseOperationsRequest.pb(spanner_database_admin.ListDatabaseOperationsRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner_database_admin.ListDatabaseOperationsResponse.to_json(spanner_database_admin.ListDatabaseOperationsResponse()) + + request = spanner_database_admin.ListDatabaseOperationsRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner_database_admin.ListDatabaseOperationsResponse() + + client.list_database_operations(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_list_database_operations_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.ListDatabaseOperationsRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.list_database_operations(request) + + +def test_list_database_operations_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.ListDatabaseOperationsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'projects/sample1/instances/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_database_admin.ListDatabaseOperationsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.list_database_operations(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/databaseOperations" % client.transport._host, args[1]) + + +def test_list_database_operations_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_database_operations( + spanner_database_admin.ListDatabaseOperationsRequest(), + parent='parent_value', + ) + + +def test_list_database_operations_rest_pager(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + #with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabaseOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(spanner_database_admin.ListDatabaseOperationsResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode('UTF-8') + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {'parent': 'projects/sample1/instances/sample2'} + + pager = client.list_database_operations(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, operations_pb2.Operation) + for i in results) + + pages = list(client.list_database_operations(request=sample_request).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize("request_type", [ + backup.ListBackupOperationsRequest, + dict, +]) +def test_list_backup_operations_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = backup.ListBackupOperationsResponse( + next_page_token='next_page_token_value', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = backup.ListBackupOperationsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.list_backup_operations(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListBackupOperationsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_backup_operations_rest_required_fields(request_type=backup.ListBackupOperationsRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_backup_operations._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_backup_operations._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("filter", "page_size", "page_token", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = backup.ListBackupOperationsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = backup.ListBackupOperationsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.list_backup_operations(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_list_backup_operations_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.list_backup_operations._get_unset_required_fields({}) + assert set(unset_fields) == (set(("filter", "pageSize", "pageToken", )) & set(("parent", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_backup_operations_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_list_backup_operations") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_list_backup_operations") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = backup.ListBackupOperationsRequest.pb(backup.ListBackupOperationsRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = backup.ListBackupOperationsResponse.to_json(backup.ListBackupOperationsResponse()) + + request = backup.ListBackupOperationsRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = backup.ListBackupOperationsResponse() + + client.list_backup_operations(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_list_backup_operations_rest_bad_request(transport: str = 'rest', request_type=backup.ListBackupOperationsRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.list_backup_operations(request) + + +def test_list_backup_operations_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = backup.ListBackupOperationsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'projects/sample1/instances/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = backup.ListBackupOperationsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.list_backup_operations(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/backupOperations" % client.transport._host, args[1]) + + +def test_list_backup_operations_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_backup_operations( + backup.ListBackupOperationsRequest(), + parent='parent_value', + ) + + +def test_list_backup_operations_rest_pager(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + #with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + backup.ListBackupOperationsResponse( + operations=[], + next_page_token='def', + ), + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + backup.ListBackupOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(backup.ListBackupOperationsResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode('UTF-8') + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {'parent': 'projects/sample1/instances/sample2'} + + pager = client.list_backup_operations(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, operations_pb2.Operation) + for i in results) + + pages = list(client.list_backup_operations(request=sample_request).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize("request_type", [ + spanner_database_admin.ListDatabaseRolesRequest, + dict, +]) +def test_list_database_roles_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.ListDatabaseRolesResponse( + next_page_token='next_page_token_value', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_database_admin.ListDatabaseRolesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.list_database_roles(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListDatabaseRolesPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_database_roles_rest_required_fields(request_type=spanner_database_admin.ListDatabaseRolesRequest): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_database_roles._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_database_roles._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("page_size", "page_token", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.ListDatabaseRolesResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner_database_admin.ListDatabaseRolesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.list_database_roles(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_list_database_roles_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.list_database_roles._get_unset_required_fields({}) + assert set(unset_fields) == (set(("pageSize", "pageToken", )) & set(("parent", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_database_roles_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_list_database_roles") as post, \ + mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_list_database_roles") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_database_admin.ListDatabaseRolesRequest.pb(spanner_database_admin.ListDatabaseRolesRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner_database_admin.ListDatabaseRolesResponse.to_json(spanner_database_admin.ListDatabaseRolesResponse()) + + request = spanner_database_admin.ListDatabaseRolesRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner_database_admin.ListDatabaseRolesResponse() + + client.list_database_roles(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_list_database_roles_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.ListDatabaseRolesRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1/instances/sample2/databases/sample3'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.list_database_roles(request) + + +def test_list_database_roles_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_database_admin.ListDatabaseRolesResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'projects/sample1/instances/sample2/databases/sample3'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_database_admin.ListDatabaseRolesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.list_database_roles(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{parent=projects/*/instances/*/databases/*}/databaseRoles" % client.transport._host, args[1]) + + +def test_list_database_roles_rest_flattened_error(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_database_roles( + spanner_database_admin.ListDatabaseRolesRequest(), + parent='parent_value', + ) + + +def test_list_database_roles_rest_pager(transport: str = 'rest'): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + #with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + ], + next_page_token='abc', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[], + next_page_token='def', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + ], + next_page_token='ghi', + ), + spanner_database_admin.ListDatabaseRolesResponse( + database_roles=[ + spanner_database_admin.DatabaseRole(), + spanner_database_admin.DatabaseRole(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(spanner_database_admin.ListDatabaseRolesResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode('UTF-8') + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {'parent': 'projects/sample1/instances/sample2/databases/sample3'} + + pager = client.list_database_roles(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, spanner_database_admin.DatabaseRole) + for i in results) + + pages = list(client.list_database_roles(request=sample_request).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.DatabaseAdminGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.DatabaseAdminGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DatabaseAdminClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.DatabaseAdminGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DatabaseAdminClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DatabaseAdminClient( + client_options=options, + credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.DatabaseAdminGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DatabaseAdminClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.DatabaseAdminGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = DatabaseAdminClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.DatabaseAdminGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.DatabaseAdminGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.DatabaseAdminGrpcTransport, + transports.DatabaseAdminGrpcAsyncIOTransport, + transports.DatabaseAdminRestTransport, +]) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "rest", +]) +def test_transport_kind(transport_name): + transport = DatabaseAdminClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.DatabaseAdminGrpcTransport, + ) + +def test_database_admin_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.DatabaseAdminTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_database_admin_base_transport(): + # Instantiate the base transport. + with mock.patch('google.cloud.spanner_admin_database_v1.services.database_admin.transports.DatabaseAdminTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.DatabaseAdminTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'list_databases', + 'create_database', + 'get_database', + 'update_database', + 'update_database_ddl', + 'drop_database', + 'get_database_ddl', + 'set_iam_policy', + 'get_iam_policy', + 'test_iam_permissions', + 'create_backup', + 'copy_backup', + 'get_backup', + 'update_backup', + 'delete_backup', + 'list_backups', + 'restore_database', + 'list_database_operations', + 'list_backup_operations', + 'list_database_roles', + 'get_operation', + 'cancel_operation', + 'delete_operation', + 'list_operations', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + # Catch all for all remaining methods and properties + remainder = [ + 'kind', + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_database_admin_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.spanner_admin_database_v1.services.database_admin.transports.DatabaseAdminTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.DatabaseAdminTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.admin', +), + quota_project_id="octopus", + ) + + +def test_database_admin_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.cloud.spanner_admin_database_v1.services.database_admin.transports.DatabaseAdminTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.DatabaseAdminTransport() + adc.assert_called_once() + + +def test_database_admin_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + DatabaseAdminClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.admin', +), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.DatabaseAdminGrpcTransport, + transports.DatabaseAdminGrpcAsyncIOTransport, + ], +) +def test_database_admin_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/spanner.admin',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.DatabaseAdminGrpcTransport, + transports.DatabaseAdminGrpcAsyncIOTransport, + transports.DatabaseAdminRestTransport, + ], +) +def test_database_admin_transport_auth_gdch_credentials(transport_class): + host = 'https://language.com' + api_audience_tests = [None, 'https://language2.com'] + api_audience_expect = [host, 'https://language2.com'] + for t, e in zip(api_audience_tests, api_audience_expect): + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + gdch_mock = mock.MagicMock() + type(gdch_mock).with_gdch_audience = mock.PropertyMock(return_value=gdch_mock) + adc.return_value = (gdch_mock, None) + transport_class(host=host, api_audience=t) + gdch_mock.with_gdch_audience.assert_called_once_with( + e + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.DatabaseAdminGrpcTransport, grpc_helpers), + (transports.DatabaseAdminGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_database_admin_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class( + quota_project_id="octopus", + scopes=["1", "2"] + ) + + create_channel.assert_called_with( + "spanner.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.admin', +), + scopes=["1", "2"], + default_host="spanner.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.DatabaseAdminGrpcTransport, transports.DatabaseAdminGrpcAsyncIOTransport]) +def test_database_admin_grpc_transport_client_cert_source_for_mtls( + transport_class +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, + private_key=expected_key + ) + +def test_database_admin_http_transport_client_cert_source_for_mtls(): + cred = ga_credentials.AnonymousCredentials() + with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel") as mock_configure_mtls_channel: + transports.DatabaseAdminRestTransport ( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) + + +def test_database_admin_rest_lro_client(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.AbstractOperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", + "rest", +]) +def test_database_admin_host_no_port(transport_name): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='spanner.googleapis.com'), + transport=transport_name, + ) + assert client.transport._host == ( + 'spanner.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://spanner.googleapis.com' + ) + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", + "rest", +]) +def test_database_admin_host_with_port(transport_name): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='spanner.googleapis.com:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + 'spanner.googleapis.com:8000' + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://spanner.googleapis.com:8000' + ) + +@pytest.mark.parametrize("transport_name", [ + "rest", +]) +def test_database_admin_client_transport_session_collision(transport_name): + creds1 = ga_credentials.AnonymousCredentials() + creds2 = ga_credentials.AnonymousCredentials() + client1 = DatabaseAdminClient( + credentials=creds1, + transport=transport_name, + ) + client2 = DatabaseAdminClient( + credentials=creds2, + transport=transport_name, + ) + session1 = client1.transport.list_databases._session + session2 = client2.transport.list_databases._session + assert session1 != session2 + session1 = client1.transport.create_database._session + session2 = client2.transport.create_database._session + assert session1 != session2 + session1 = client1.transport.get_database._session + session2 = client2.transport.get_database._session + assert session1 != session2 + session1 = client1.transport.update_database._session + session2 = client2.transport.update_database._session + assert session1 != session2 + session1 = client1.transport.update_database_ddl._session + session2 = client2.transport.update_database_ddl._session + assert session1 != session2 + session1 = client1.transport.drop_database._session + session2 = client2.transport.drop_database._session + assert session1 != session2 + session1 = client1.transport.get_database_ddl._session + session2 = client2.transport.get_database_ddl._session + assert session1 != session2 + session1 = client1.transport.set_iam_policy._session + session2 = client2.transport.set_iam_policy._session + assert session1 != session2 + session1 = client1.transport.get_iam_policy._session + session2 = client2.transport.get_iam_policy._session + assert session1 != session2 + session1 = client1.transport.test_iam_permissions._session + session2 = client2.transport.test_iam_permissions._session + assert session1 != session2 + session1 = client1.transport.create_backup._session + session2 = client2.transport.create_backup._session + assert session1 != session2 + session1 = client1.transport.copy_backup._session + session2 = client2.transport.copy_backup._session + assert session1 != session2 + session1 = client1.transport.get_backup._session + session2 = client2.transport.get_backup._session + assert session1 != session2 + session1 = client1.transport.update_backup._session + session2 = client2.transport.update_backup._session + assert session1 != session2 + session1 = client1.transport.delete_backup._session + session2 = client2.transport.delete_backup._session + assert session1 != session2 + session1 = client1.transport.list_backups._session + session2 = client2.transport.list_backups._session + assert session1 != session2 + session1 = client1.transport.restore_database._session + session2 = client2.transport.restore_database._session + assert session1 != session2 + session1 = client1.transport.list_database_operations._session + session2 = client2.transport.list_database_operations._session + assert session1 != session2 + session1 = client1.transport.list_backup_operations._session + session2 = client2.transport.list_backup_operations._session + assert session1 != session2 + session1 = client1.transport.list_database_roles._session + session2 = client2.transport.list_database_roles._session + assert session1 != session2 +def test_database_admin_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.DatabaseAdminGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_database_admin_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.DatabaseAdminGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.DatabaseAdminGrpcTransport, transports.DatabaseAdminGrpcAsyncIOTransport]) +def test_database_admin_transport_channel_mtls_with_client_cert_source( + transport_class +): + with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.DatabaseAdminGrpcTransport, transports.DatabaseAdminGrpcAsyncIOTransport]) +def test_database_admin_transport_channel_mtls_with_adc( + transport_class +): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_database_admin_grpc_lro_client(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_database_admin_grpc_lro_async_client(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc_asyncio', + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_backup_path(): + project = "squid" + instance = "clam" + backup = "whelk" + expected = "projects/{project}/instances/{instance}/backups/{backup}".format(project=project, instance=instance, backup=backup, ) + actual = DatabaseAdminClient.backup_path(project, instance, backup) + assert expected == actual + + +def test_parse_backup_path(): + expected = { + "project": "octopus", + "instance": "oyster", + "backup": "nudibranch", + } + path = DatabaseAdminClient.backup_path(**expected) + + # Check that the path construction is reversible. + actual = DatabaseAdminClient.parse_backup_path(path) + assert expected == actual + +def test_crypto_key_path(): + project = "cuttlefish" + location = "mussel" + key_ring = "winkle" + crypto_key = "nautilus" + expected = "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}".format(project=project, location=location, key_ring=key_ring, crypto_key=crypto_key, ) + actual = DatabaseAdminClient.crypto_key_path(project, location, key_ring, crypto_key) + assert expected == actual + + +def test_parse_crypto_key_path(): + expected = { + "project": "scallop", + "location": "abalone", + "key_ring": "squid", + "crypto_key": "clam", + } + path = DatabaseAdminClient.crypto_key_path(**expected) + + # Check that the path construction is reversible. + actual = DatabaseAdminClient.parse_crypto_key_path(path) + assert expected == actual + +def test_crypto_key_version_path(): + project = "whelk" + location = "octopus" + key_ring = "oyster" + crypto_key = "nudibranch" + crypto_key_version = "cuttlefish" + expected = "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version}".format(project=project, location=location, key_ring=key_ring, crypto_key=crypto_key, crypto_key_version=crypto_key_version, ) + actual = DatabaseAdminClient.crypto_key_version_path(project, location, key_ring, crypto_key, crypto_key_version) + assert expected == actual + + +def test_parse_crypto_key_version_path(): + expected = { + "project": "mussel", + "location": "winkle", + "key_ring": "nautilus", + "crypto_key": "scallop", + "crypto_key_version": "abalone", + } + path = DatabaseAdminClient.crypto_key_version_path(**expected) + + # Check that the path construction is reversible. + actual = DatabaseAdminClient.parse_crypto_key_version_path(path) + assert expected == actual + +def test_database_path(): + project = "squid" + instance = "clam" + database = "whelk" + expected = "projects/{project}/instances/{instance}/databases/{database}".format(project=project, instance=instance, database=database, ) + actual = DatabaseAdminClient.database_path(project, instance, database) + assert expected == actual + + +def test_parse_database_path(): + expected = { + "project": "octopus", + "instance": "oyster", + "database": "nudibranch", + } + path = DatabaseAdminClient.database_path(**expected) + + # Check that the path construction is reversible. + actual = DatabaseAdminClient.parse_database_path(path) + assert expected == actual + +def test_database_role_path(): + project = "cuttlefish" + instance = "mussel" + database = "winkle" + role = "nautilus" + expected = "projects/{project}/instances/{instance}/databases/{database}/databaseRoles/{role}".format(project=project, instance=instance, database=database, role=role, ) + actual = DatabaseAdminClient.database_role_path(project, instance, database, role) + assert expected == actual + + +def test_parse_database_role_path(): + expected = { + "project": "scallop", + "instance": "abalone", + "database": "squid", + "role": "clam", + } + path = DatabaseAdminClient.database_role_path(**expected) + + # Check that the path construction is reversible. + actual = DatabaseAdminClient.parse_database_role_path(path) + assert expected == actual + +def test_instance_path(): + project = "whelk" + instance = "octopus" + expected = "projects/{project}/instances/{instance}".format(project=project, instance=instance, ) + actual = DatabaseAdminClient.instance_path(project, instance) + assert expected == actual + + +def test_parse_instance_path(): + expected = { + "project": "oyster", + "instance": "nudibranch", + } + path = DatabaseAdminClient.instance_path(**expected) + + # Check that the path construction is reversible. + actual = DatabaseAdminClient.parse_instance_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "cuttlefish" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = DatabaseAdminClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "mussel", + } + path = DatabaseAdminClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = DatabaseAdminClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "winkle" + expected = "folders/{folder}".format(folder=folder, ) + actual = DatabaseAdminClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "nautilus", + } + path = DatabaseAdminClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = DatabaseAdminClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "scallop" + expected = "organizations/{organization}".format(organization=organization, ) + actual = DatabaseAdminClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "abalone", + } + path = DatabaseAdminClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = DatabaseAdminClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "squid" + expected = "projects/{project}".format(project=project, ) + actual = DatabaseAdminClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "clam", + } + path = DatabaseAdminClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = DatabaseAdminClient.parse_common_project_path(path) + assert expected == actual + +def test_common_location_path(): + project = "whelk" + location = "octopus" + expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + actual = DatabaseAdminClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + } + path = DatabaseAdminClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = DatabaseAdminClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object(transports.DatabaseAdminTransport, '_prep_wrapped_messages') as prep: + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.DatabaseAdminTransport, '_prep_wrapped_messages') as prep: + transport_class = DatabaseAdminClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_cancel_operation_rest_bad_request(transport: str = 'rest', request_type=operations_pb2.CancelOperationRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + request = request_type() + request = json_format.ParseDict({'name': 'projects/sample1/instances/sample2/databases/sample3/operations/sample4'}, request) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.cancel_operation(request) + +@pytest.mark.parametrize("request_type", [ + operations_pb2.CancelOperationRequest, + dict, +]) +def test_cancel_operation_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/operations/sample4'} + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '{}' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.cancel_operation(request) + + # Establish that the response is the type that we expect. + assert response is None + +def test_delete_operation_rest_bad_request(transport: str = 'rest', request_type=operations_pb2.DeleteOperationRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + request = request_type() + request = json_format.ParseDict({'name': 'projects/sample1/instances/sample2/databases/sample3/operations/sample4'}, request) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.delete_operation(request) + +@pytest.mark.parametrize("request_type", [ + operations_pb2.DeleteOperationRequest, + dict, +]) +def test_delete_operation_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/operations/sample4'} + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '{}' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.delete_operation(request) + + # Establish that the response is the type that we expect. + assert response is None + +def test_get_operation_rest_bad_request(transport: str = 'rest', request_type=operations_pb2.GetOperationRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + request = request_type() + request = json_format.ParseDict({'name': 'projects/sample1/instances/sample2/databases/sample3/operations/sample4'}, request) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.get_operation(request) + +@pytest.mark.parametrize("request_type", [ + operations_pb2.GetOperationRequest, + dict, +]) +def test_get_operation_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/operations/sample4'} + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation() + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.get_operation(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + +def test_list_operations_rest_bad_request(transport: str = 'rest', request_type=operations_pb2.ListOperationsRequest): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + request = request_type() + request = json_format.ParseDict({'name': 'projects/sample1/instances/sample2/databases/sample3/operations'}, request) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.list_operations(request) + +@pytest.mark.parametrize("request_type", [ + operations_pb2.ListOperationsRequest, + dict, +]) +def test_list_operations_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/operations'} + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.ListOperationsResponse() + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.list_operations(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_delete_operation(transport: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None +@pytest.mark.asyncio +async def test_delete_operation_async(transport: str = "grpc"): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + +def test_delete_operation_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=locations",) in kw["metadata"] +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=locations",) in kw["metadata"] + +def test_delete_operation_from_dict(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None +@pytest.mark.asyncio +async def test_cancel_operation_async(transport: str = "grpc"): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + +def test_cancel_operation_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=locations",) in kw["metadata"] +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=locations",) in kw["metadata"] + +def test_cancel_operation_from_dict(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) +@pytest.mark.asyncio +async def test_get_operation_async(transport: str = "grpc"): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + +def test_get_operation_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=locations",) in kw["metadata"] +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=locations",) in kw["metadata"] + +def test_get_operation_from_dict(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) +@pytest.mark.asyncio +async def test_list_operations_async(transport: str = "grpc"): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + +def test_list_operations_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=locations",) in kw["metadata"] +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "name=locations",) in kw["metadata"] + +def test_list_operations_from_dict(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "rest": "_session", + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + +def test_client_ctx(): + transports = [ + 'rest', + 'grpc', + ] + for transport in transports: + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + +@pytest.mark.parametrize("client_class,transport_class", [ + (DatabaseAdminClient, transports.DatabaseAdminGrpcTransport), + (DatabaseAdminAsyncClient, transports.DatabaseAdminGrpcAsyncIOTransport), +]) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) diff --git a/owl-bot-staging/spanner_admin_instance/v1/.coveragerc b/owl-bot-staging/spanner_admin_instance/v1/.coveragerc new file mode 100644 index 0000000000..040d100fc8 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/.coveragerc @@ -0,0 +1,13 @@ +[run] +branch = True + +[report] +show_missing = True +omit = + google/cloud/spanner_admin_instance/__init__.py + google/cloud/spanner_admin_instance/gapic_version.py +exclude_lines = + # Re-enable the standard pragma + pragma: NO COVER + # Ignore debug-only repr + def __repr__ diff --git a/owl-bot-staging/spanner_admin_instance/v1/.flake8 b/owl-bot-staging/spanner_admin_instance/v1/.flake8 new file mode 100644 index 0000000000..29227d4cf4 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/.flake8 @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Generated by synthtool. DO NOT EDIT! +[flake8] +ignore = E203, E266, E501, W503 +exclude = + # Exclude generated code. + **/proto/** + **/gapic/** + **/services/** + **/types/** + *_pb2.py + + # Standard linting exemptions. + **/.nox/** + __pycache__, + .git, + *.pyc, + conf.py diff --git a/owl-bot-staging/spanner_admin_instance/v1/MANIFEST.in b/owl-bot-staging/spanner_admin_instance/v1/MANIFEST.in new file mode 100644 index 0000000000..5af7430e8d --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include google/cloud/spanner_admin_instance *.py +recursive-include google/cloud/spanner_admin_instance_v1 *.py diff --git a/owl-bot-staging/spanner_admin_instance/v1/README.rst b/owl-bot-staging/spanner_admin_instance/v1/README.rst new file mode 100644 index 0000000000..94972f5b29 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/README.rst @@ -0,0 +1,49 @@ +Python Client for Google Cloud Spanner Admin Instance API +================================================= + +Quick Start +----------- + +In order to use this library, you first need to go through the following steps: + +1. `Select or create a Cloud Platform project.`_ +2. `Enable billing for your project.`_ +3. Enable the Google Cloud Spanner Admin Instance API. +4. `Setup Authentication.`_ + +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project +.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html + +Installation +~~~~~~~~~~~~ + +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to +create isolated Python environments. The basic problem it addresses is one of +dependencies and versions, and indirectly permissions. + +With `virtualenv`_, it's possible to install this library without needing system +install permissions, and without clashing with the installed system +dependencies. + +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ + + +Mac/Linux +^^^^^^^^^ + +.. code-block:: console + + python3 -m venv + source /bin/activate + /bin/pip install /path/to/library + + +Windows +^^^^^^^ + +.. code-block:: console + + python3 -m venv + \Scripts\activate + \Scripts\pip.exe install \path\to\library diff --git a/owl-bot-staging/spanner_admin_instance/v1/docs/conf.py b/owl-bot-staging/spanner_admin_instance/v1/docs/conf.py new file mode 100644 index 0000000000..74199e86f7 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/docs/conf.py @@ -0,0 +1,376 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +# google-cloud-spanner-admin-instance documentation build configuration file +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os +import shlex + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath("..")) + +__version__ = "0.1.0" + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +needs_sphinx = "4.0.1" + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.intersphinx", + "sphinx.ext.coverage", + "sphinx.ext.napoleon", + "sphinx.ext.todo", + "sphinx.ext.viewcode", +] + +# autodoc/autosummary flags +autoclass_content = "both" +autodoc_default_flags = ["members"] +autosummary_generate = True + + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# Allow markdown includes (so releases.md can include CHANGLEOG.md) +# http://www.sphinx-doc.org/en/master/markdown.html +source_parsers = {".md": "recommonmark.parser.CommonMarkParser"} + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +source_suffix = [".rst", ".md"] + +# The encoding of source files. +# source_encoding = 'utf-8-sig' + +# The root toctree document. +root_doc = "index" + +# General information about the project. +project = u"google-cloud-spanner-admin-instance" +copyright = u"2022, Google, LLC" +author = u"Google APIs" # TODO: autogenerate this bit + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The full version, including alpha/beta/rc tags. +release = __version__ +# The short X.Y version. +version = ".".join(release.split(".")[0:2]) + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +# today = '' +# Else, today_fmt is used as the format for a strftime call. +# today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ["_build"] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +# default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +# add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +# add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +# show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = "sphinx" + +# A list of ignored prefixes for module index sorting. +# modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +# keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = "alabaster" + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +html_theme_options = { + "description": "Google Cloud Client Libraries for Python", + "github_user": "googleapis", + "github_repo": "google-cloud-python", + "github_banner": True, + "font_family": "'Roboto', Georgia, sans", + "head_font_family": "'Roboto', Georgia, serif", + "code_font_family": "'Roboto Mono', 'Consolas', monospace", +} + +# Add any paths that contain custom themes here, relative to this directory. +# html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +# html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +# html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +# html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +# html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ["_static"] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +# html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +# html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +# html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +# html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +# html_additional_pages = {} + +# If false, no module index is generated. +# html_domain_indices = True + +# If false, no index is generated. +# html_use_index = True + +# If true, the index is split into individual pages for each letter. +# html_split_index = False + +# If true, links to the reST sources are added to the pages. +# html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +# html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +# html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +# html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +# html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' +# html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# Now only 'ja' uses this config value +# html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +# html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = "google-cloud-spanner-admin-instance-doc" + +# -- Options for warnings ------------------------------------------------------ + + +suppress_warnings = [ + # Temporarily suppress this to avoid "more than one target found for + # cross-reference" warning, which are intractable for us to avoid while in + # a mono-repo. + # See https://github.com/sphinx-doc/sphinx/blob + # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 + "ref.python" +] + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # 'preamble': '', + # Latex figure (float) alignment + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ( + root_doc, + "google-cloud-spanner-admin-instance.tex", + u"google-cloud-spanner-admin-instance Documentation", + author, + "manual", + ) +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +# latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +# latex_use_parts = False + +# If true, show page references after internal links. +# latex_show_pagerefs = False + +# If true, show URL addresses after external links. +# latex_show_urls = False + +# Documents to append as an appendix to all manuals. +# latex_appendices = [] + +# If false, no module index is generated. +# latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ( + root_doc, + "google-cloud-spanner-admin-instance", + u"Google Cloud Spanner Admin Instance Documentation", + [author], + 1, + ) +] + +# If true, show URL addresses after external links. +# man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ( + root_doc, + "google-cloud-spanner-admin-instance", + u"google-cloud-spanner-admin-instance Documentation", + author, + "google-cloud-spanner-admin-instance", + "GAPIC library for Google Cloud Spanner Admin Instance API", + "APIs", + ) +] + +# Documents to append as an appendix to all manuals. +# texinfo_appendices = [] + +# If false, no module index is generated. +# texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +# texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +# texinfo_no_detailmenu = False + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = { + "python": ("http://python.readthedocs.org/en/latest/", None), + "gax": ("https://gax-python.readthedocs.org/en/latest/", None), + "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), + "google-gax": ("https://gax-python.readthedocs.io/en/latest/", None), + "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None), + "grpc": ("https://grpc.io/grpc/python/", None), + "requests": ("http://requests.kennethreitz.org/en/stable/", None), + "proto": ("https://proto-plus-python.readthedocs.io/en/stable", None), + "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), +} + + +# Napoleon settings +napoleon_google_docstring = True +napoleon_numpy_docstring = True +napoleon_include_private_with_doc = False +napoleon_include_special_with_doc = True +napoleon_use_admonition_for_examples = False +napoleon_use_admonition_for_notes = False +napoleon_use_admonition_for_references = False +napoleon_use_ivar = False +napoleon_use_param = True +napoleon_use_rtype = True diff --git a/owl-bot-staging/spanner_admin_instance/v1/docs/index.rst b/owl-bot-staging/spanner_admin_instance/v1/docs/index.rst new file mode 100644 index 0000000000..bc65940f95 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/docs/index.rst @@ -0,0 +1,7 @@ +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + spanner_admin_instance_v1/services + spanner_admin_instance_v1/types diff --git a/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/instance_admin.rst b/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/instance_admin.rst new file mode 100644 index 0000000000..fe820b3fad --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/instance_admin.rst @@ -0,0 +1,10 @@ +InstanceAdmin +------------------------------- + +.. automodule:: google.cloud.spanner_admin_instance_v1.services.instance_admin + :members: + :inherited-members: + +.. automodule:: google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers + :members: + :inherited-members: diff --git a/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/services.rst b/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/services.rst new file mode 100644 index 0000000000..407d44cc34 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/services.rst @@ -0,0 +1,6 @@ +Services for Google Cloud Spanner Admin Instance v1 API +======================================================= +.. toctree:: + :maxdepth: 2 + + instance_admin diff --git a/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/types.rst b/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/types.rst new file mode 100644 index 0000000000..250cf6bf9b --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/types.rst @@ -0,0 +1,6 @@ +Types for Google Cloud Spanner Admin Instance v1 API +==================================================== + +.. automodule:: google.cloud.spanner_admin_instance_v1.types + :members: + :show-inheritance: diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/__init__.py new file mode 100644 index 0000000000..402b48d265 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/__init__.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from google.cloud.spanner_admin_instance import gapic_version as package_version + +__version__ = package_version.__version__ + + +from google.cloud.spanner_admin_instance_v1.services.instance_admin.client import InstanceAdminClient +from google.cloud.spanner_admin_instance_v1.services.instance_admin.async_client import InstanceAdminAsyncClient + +from google.cloud.spanner_admin_instance_v1.types.common import OperationProgress +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import CreateInstanceConfigMetadata +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import CreateInstanceConfigRequest +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import CreateInstanceMetadata +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import CreateInstanceRequest +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import DeleteInstanceConfigRequest +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import DeleteInstanceRequest +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import GetInstanceConfigRequest +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import GetInstanceRequest +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import Instance +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import InstanceConfig +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import ListInstanceConfigOperationsRequest +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import ListInstanceConfigOperationsResponse +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import ListInstanceConfigsRequest +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import ListInstanceConfigsResponse +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import ListInstancesRequest +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import ListInstancesResponse +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import ReplicaInfo +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import UpdateInstanceConfigMetadata +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import UpdateInstanceConfigRequest +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import UpdateInstanceMetadata +from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import UpdateInstanceRequest + +__all__ = ('InstanceAdminClient', + 'InstanceAdminAsyncClient', + 'OperationProgress', + 'CreateInstanceConfigMetadata', + 'CreateInstanceConfigRequest', + 'CreateInstanceMetadata', + 'CreateInstanceRequest', + 'DeleteInstanceConfigRequest', + 'DeleteInstanceRequest', + 'GetInstanceConfigRequest', + 'GetInstanceRequest', + 'Instance', + 'InstanceConfig', + 'ListInstanceConfigOperationsRequest', + 'ListInstanceConfigOperationsResponse', + 'ListInstanceConfigsRequest', + 'ListInstanceConfigsResponse', + 'ListInstancesRequest', + 'ListInstancesResponse', + 'ReplicaInfo', + 'UpdateInstanceConfigMetadata', + 'UpdateInstanceConfigRequest', + 'UpdateInstanceMetadata', + 'UpdateInstanceRequest', +) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/gapic_version.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/gapic_version.py new file mode 100644 index 0000000000..405b1cebcf --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +__version__ = "0.1.0" # {x-release-please-version} diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/py.typed b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/py.typed new file mode 100644 index 0000000000..915a8e55e3 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-spanner-admin-instance package uses inline types. diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/__init__.py new file mode 100644 index 0000000000..b4e39ea47e --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/__init__.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from google.cloud.spanner_admin_instance_v1 import gapic_version as package_version + +__version__ = package_version.__version__ + + +from .services.instance_admin import InstanceAdminClient +from .services.instance_admin import InstanceAdminAsyncClient + +from .types.common import OperationProgress +from .types.spanner_instance_admin import CreateInstanceConfigMetadata +from .types.spanner_instance_admin import CreateInstanceConfigRequest +from .types.spanner_instance_admin import CreateInstanceMetadata +from .types.spanner_instance_admin import CreateInstanceRequest +from .types.spanner_instance_admin import DeleteInstanceConfigRequest +from .types.spanner_instance_admin import DeleteInstanceRequest +from .types.spanner_instance_admin import GetInstanceConfigRequest +from .types.spanner_instance_admin import GetInstanceRequest +from .types.spanner_instance_admin import Instance +from .types.spanner_instance_admin import InstanceConfig +from .types.spanner_instance_admin import ListInstanceConfigOperationsRequest +from .types.spanner_instance_admin import ListInstanceConfigOperationsResponse +from .types.spanner_instance_admin import ListInstanceConfigsRequest +from .types.spanner_instance_admin import ListInstanceConfigsResponse +from .types.spanner_instance_admin import ListInstancesRequest +from .types.spanner_instance_admin import ListInstancesResponse +from .types.spanner_instance_admin import ReplicaInfo +from .types.spanner_instance_admin import UpdateInstanceConfigMetadata +from .types.spanner_instance_admin import UpdateInstanceConfigRequest +from .types.spanner_instance_admin import UpdateInstanceMetadata +from .types.spanner_instance_admin import UpdateInstanceRequest + +__all__ = ( + 'InstanceAdminAsyncClient', +'CreateInstanceConfigMetadata', +'CreateInstanceConfigRequest', +'CreateInstanceMetadata', +'CreateInstanceRequest', +'DeleteInstanceConfigRequest', +'DeleteInstanceRequest', +'GetInstanceConfigRequest', +'GetInstanceRequest', +'Instance', +'InstanceAdminClient', +'InstanceConfig', +'ListInstanceConfigOperationsRequest', +'ListInstanceConfigOperationsResponse', +'ListInstanceConfigsRequest', +'ListInstanceConfigsResponse', +'ListInstancesRequest', +'ListInstancesResponse', +'OperationProgress', +'ReplicaInfo', +'UpdateInstanceConfigMetadata', +'UpdateInstanceConfigRequest', +'UpdateInstanceMetadata', +'UpdateInstanceRequest', +) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_metadata.json b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_metadata.json new file mode 100644 index 0000000000..a3ee34c069 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_metadata.json @@ -0,0 +1,238 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.spanner_admin_instance_v1", + "protoPackage": "google.spanner.admin.instance.v1", + "schema": "1.0", + "services": { + "InstanceAdmin": { + "clients": { + "grpc": { + "libraryClient": "InstanceAdminClient", + "rpcs": { + "CreateInstance": { + "methods": [ + "create_instance" + ] + }, + "CreateInstanceConfig": { + "methods": [ + "create_instance_config" + ] + }, + "DeleteInstance": { + "methods": [ + "delete_instance" + ] + }, + "DeleteInstanceConfig": { + "methods": [ + "delete_instance_config" + ] + }, + "GetIamPolicy": { + "methods": [ + "get_iam_policy" + ] + }, + "GetInstance": { + "methods": [ + "get_instance" + ] + }, + "GetInstanceConfig": { + "methods": [ + "get_instance_config" + ] + }, + "ListInstanceConfigOperations": { + "methods": [ + "list_instance_config_operations" + ] + }, + "ListInstanceConfigs": { + "methods": [ + "list_instance_configs" + ] + }, + "ListInstances": { + "methods": [ + "list_instances" + ] + }, + "SetIamPolicy": { + "methods": [ + "set_iam_policy" + ] + }, + "TestIamPermissions": { + "methods": [ + "test_iam_permissions" + ] + }, + "UpdateInstance": { + "methods": [ + "update_instance" + ] + }, + "UpdateInstanceConfig": { + "methods": [ + "update_instance_config" + ] + } + } + }, + "grpc-async": { + "libraryClient": "InstanceAdminAsyncClient", + "rpcs": { + "CreateInstance": { + "methods": [ + "create_instance" + ] + }, + "CreateInstanceConfig": { + "methods": [ + "create_instance_config" + ] + }, + "DeleteInstance": { + "methods": [ + "delete_instance" + ] + }, + "DeleteInstanceConfig": { + "methods": [ + "delete_instance_config" + ] + }, + "GetIamPolicy": { + "methods": [ + "get_iam_policy" + ] + }, + "GetInstance": { + "methods": [ + "get_instance" + ] + }, + "GetInstanceConfig": { + "methods": [ + "get_instance_config" + ] + }, + "ListInstanceConfigOperations": { + "methods": [ + "list_instance_config_operations" + ] + }, + "ListInstanceConfigs": { + "methods": [ + "list_instance_configs" + ] + }, + "ListInstances": { + "methods": [ + "list_instances" + ] + }, + "SetIamPolicy": { + "methods": [ + "set_iam_policy" + ] + }, + "TestIamPermissions": { + "methods": [ + "test_iam_permissions" + ] + }, + "UpdateInstance": { + "methods": [ + "update_instance" + ] + }, + "UpdateInstanceConfig": { + "methods": [ + "update_instance_config" + ] + } + } + }, + "rest": { + "libraryClient": "InstanceAdminClient", + "rpcs": { + "CreateInstance": { + "methods": [ + "create_instance" + ] + }, + "CreateInstanceConfig": { + "methods": [ + "create_instance_config" + ] + }, + "DeleteInstance": { + "methods": [ + "delete_instance" + ] + }, + "DeleteInstanceConfig": { + "methods": [ + "delete_instance_config" + ] + }, + "GetIamPolicy": { + "methods": [ + "get_iam_policy" + ] + }, + "GetInstance": { + "methods": [ + "get_instance" + ] + }, + "GetInstanceConfig": { + "methods": [ + "get_instance_config" + ] + }, + "ListInstanceConfigOperations": { + "methods": [ + "list_instance_config_operations" + ] + }, + "ListInstanceConfigs": { + "methods": [ + "list_instance_configs" + ] + }, + "ListInstances": { + "methods": [ + "list_instances" + ] + }, + "SetIamPolicy": { + "methods": [ + "set_iam_policy" + ] + }, + "TestIamPermissions": { + "methods": [ + "test_iam_permissions" + ] + }, + "UpdateInstance": { + "methods": [ + "update_instance" + ] + }, + "UpdateInstanceConfig": { + "methods": [ + "update_instance_config" + ] + } + } + } + } + } + } +} diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_version.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_version.py new file mode 100644 index 0000000000..405b1cebcf --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +__version__ = "0.1.0" # {x-release-please-version} diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/py.typed b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/py.typed new file mode 100644 index 0000000000..915a8e55e3 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-spanner-admin-instance package uses inline types. diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/__init__.py new file mode 100644 index 0000000000..e8e1c3845d --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py new file mode 100644 index 0000000000..4935f1dbc6 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .client import InstanceAdminClient +from .async_client import InstanceAdminAsyncClient + +__all__ = ( + 'InstanceAdminClient', + 'InstanceAdminAsyncClient', +) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py new file mode 100644 index 0000000000..016f8fe122 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py @@ -0,0 +1,2221 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +import functools +import re +from typing import Dict, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union + +from google.cloud.spanner_admin_instance_v1 import gapic_version as package_version + +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.spanner_admin_instance_v1.services.instance_admin import pagers +from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import InstanceAdminTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import InstanceAdminGrpcAsyncIOTransport +from .client import InstanceAdminClient + + +class InstanceAdminAsyncClient: + """Cloud Spanner Instance Admin API + The Cloud Spanner Instance Admin API can be used to create, + delete, modify and list instances. Instances are dedicated Cloud + Spanner serving and storage resources to be used by Cloud + Spanner databases. + Each instance has a "configuration", which dictates where the + serving resources for the Cloud Spanner instance are located + (e.g., US-central, Europe). Configurations are created by Google + based on resource availability. + + Cloud Spanner billing is based on the instances that exist and + their sizes. After an instance exists, there are no additional + per-database or per-operation charges for use of the instance + (though there may be additional network bandwidth charges). + Instances offer isolation: problems with databases in one + instance will not affect other instances. However, within an + instance databases can affect each other. For example, if one + database in an instance receives a lot of requests and consumes + most of the instance resources, fewer resources are available + for other databases in that instance, and their performance may + suffer. + """ + + _client: InstanceAdminClient + + DEFAULT_ENDPOINT = InstanceAdminClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = InstanceAdminClient.DEFAULT_MTLS_ENDPOINT + + instance_path = staticmethod(InstanceAdminClient.instance_path) + parse_instance_path = staticmethod(InstanceAdminClient.parse_instance_path) + instance_config_path = staticmethod(InstanceAdminClient.instance_config_path) + parse_instance_config_path = staticmethod(InstanceAdminClient.parse_instance_config_path) + common_billing_account_path = staticmethod(InstanceAdminClient.common_billing_account_path) + parse_common_billing_account_path = staticmethod(InstanceAdminClient.parse_common_billing_account_path) + common_folder_path = staticmethod(InstanceAdminClient.common_folder_path) + parse_common_folder_path = staticmethod(InstanceAdminClient.parse_common_folder_path) + common_organization_path = staticmethod(InstanceAdminClient.common_organization_path) + parse_common_organization_path = staticmethod(InstanceAdminClient.parse_common_organization_path) + common_project_path = staticmethod(InstanceAdminClient.common_project_path) + parse_common_project_path = staticmethod(InstanceAdminClient.parse_common_project_path) + common_location_path = staticmethod(InstanceAdminClient.common_location_path) + parse_common_location_path = staticmethod(InstanceAdminClient.parse_common_location_path) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + InstanceAdminAsyncClient: The constructed client. + """ + return InstanceAdminClient.from_service_account_info.__func__(InstanceAdminAsyncClient, info, *args, **kwargs) # type: ignore + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + InstanceAdminAsyncClient: The constructed client. + """ + return InstanceAdminClient.from_service_account_file.__func__(InstanceAdminAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @classmethod + def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[ClientOptions] = None): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variable is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return InstanceAdminClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> InstanceAdminTransport: + """Returns the transport used by the client instance. + + Returns: + InstanceAdminTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial(type(InstanceAdminClient).get_transport_class, type(InstanceAdminClient)) + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Union[str, InstanceAdminTransport] = "grpc_asyncio", + client_options: Optional[ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the instance admin client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, ~.InstanceAdminTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (ClientOptions): Custom options for the client. It + won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + """ + self._client = InstanceAdminClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + + ) + + async def list_instance_configs(self, + request: Optional[Union[spanner_instance_admin.ListInstanceConfigsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListInstanceConfigsAsyncPager: + r"""Lists the supported instance configurations for a + given project. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + async def sample_list_instance_configs(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_configs(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest, dict]]): + The request object. The request for + [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. + parent (:class:`str`): + Required. The name of the project for which a list of + supported instance configurations is requested. Values + are of the form ``projects/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigsAsyncPager: + The response for + [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_instance_admin.ListInstanceConfigsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_instance_configs, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListInstanceConfigsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_instance_config(self, + request: Optional[Union[spanner_instance_admin.GetInstanceConfigRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner_instance_admin.InstanceConfig: + r"""Gets information about a particular instance + configuration. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + async def sample_get_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceConfigRequest( + name="name_value", + ) + + # Make the request + response = await client.get_instance_config(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest, dict]]): + The request object. The request for + [GetInstanceConfigRequest][google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig]. + name (:class:`str`): + Required. The name of the requested instance + configuration. Values are of the form + ``projects//instanceConfigs/``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_instance_v1.types.InstanceConfig: + A possible configuration for a Cloud + Spanner instance. Configurations define + the geographic placement of nodes and + their replication. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_instance_admin.GetInstanceConfigRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_instance_config, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def create_instance_config(self, + request: Optional[Union[spanner_instance_admin.CreateInstanceConfigRequest, dict]] = None, + *, + parent: Optional[str] = None, + instance_config: Optional[spanner_instance_admin.InstanceConfig] = None, + instance_config_id: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Creates an instance config and begins preparing it to be used. + The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of preparing the new instance config. The instance + config name is assigned by the caller. If the named instance + config already exists, ``CreateInstanceConfig`` returns + ``ALREADY_EXISTS``. + + Immediately after the request returns: + + - The instance config is readable via the API, with all + requested attributes. The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. Its state is ``CREATING``. + + While the operation is pending: + + - Cancelling the operation renders the instance config + immediately unreadable via the API. + - Except for deleting the creating resource, all other attempts + to modify the instance config are rejected. + + Upon completion of the returned operation: + + - Instances can be created using the instance configuration. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. Its state becomes ``READY``. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track creation of the instance config. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.create`` + permission on the resource + [parent][google.spanner.admin.instance.v1.CreateInstanceConfigRequest.parent]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + async def sample_create_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.CreateInstanceConfigRequest( + parent="parent_value", + instance_config_id="instance_config_id_value", + ) + + # Make the request + operation = client.create_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.CreateInstanceConfigRequest, dict]]): + The request object. The request for + [CreateInstanceConfigRequest][InstanceAdmin.CreateInstanceConfigRequest]. + parent (:class:`str`): + Required. The name of the project in which to create the + instance config. Values are of the form + ``projects/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + instance_config (:class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig`): + Required. The InstanceConfig proto of the configuration + to create. instance_config.name must be + ``/instanceConfigs/``. + instance_config.base_config must be a Google managed + configuration name, e.g. /instanceConfigs/us-east1, + /instanceConfigs/nam3. + + This corresponds to the ``instance_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + instance_config_id (:class:`str`): + Required. The ID of the instance config to create. Valid + identifiers are of the form + ``custom-[-a-z0-9]*[a-z0-9]`` and must be between 2 and + 64 characters in length. The ``custom-`` prefix is + required to avoid name conflicts with Google managed + configurations. + + This corresponds to the ``instance_config_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig` A possible configuration for a Cloud Spanner instance. Configurations + define the geographic placement of nodes and their + replication. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, instance_config, instance_config_id]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_instance_admin.CreateInstanceConfigRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if instance_config is not None: + request.instance_config = instance_config + if instance_config_id is not None: + request.instance_config_id = instance_config_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.create_instance_config, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + spanner_instance_admin.InstanceConfig, + metadata_type=spanner_instance_admin.CreateInstanceConfigMetadata, + ) + + # Done; return the response. + return response + + async def update_instance_config(self, + request: Optional[Union[spanner_instance_admin.UpdateInstanceConfigRequest, dict]] = None, + *, + instance_config: Optional[spanner_instance_admin.InstanceConfig] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Updates an instance config. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the instance. If the named instance + config does not exist, returns ``NOT_FOUND``. + + Only user managed configurations can be updated. + + Immediately after the request returns: + + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. + + While the operation is pending: + + - Cancelling the operation sets its metadata's + [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata.cancel_time]. + The operation is guaranteed to succeed at undoing all + changes, after which point it terminates with a ``CANCELLED`` + status. + - All other attempts to modify the instance config are + rejected. + - Reading the instance config via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - Creating instances using the instance configuration uses the + new values. + - The instance config's new values are readable via the API. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track the instance config modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateInstanceConfigMetadata][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.update`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + async def sample_update_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.UpdateInstanceConfigRequest( + ) + + # Make the request + operation = client.update_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstanceConfigRequest, dict]]): + The request object. The request for + [UpdateInstanceConfigRequest][InstanceAdmin.UpdateInstanceConfigRequest]. + instance_config (:class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig`): + Required. The user instance config to update, which must + always include the instance config name. Otherwise, only + fields mentioned in + [update_mask][google.spanner.admin.instance.v1.UpdateInstanceConfigRequest.update_mask] + need be included. To prevent conflicts of concurrent + updates, + [etag][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + can be used. + + This corresponds to the ``instance_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. A mask specifying which fields in + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] + should be updated. The field mask must always be + specified; this prevents any future fields in + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] + from being erased accidentally by clients that do not + know about them. Only display_name and labels can be + updated. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig` A possible configuration for a Cloud Spanner instance. Configurations + define the geographic placement of nodes and their + replication. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([instance_config, update_mask]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_instance_admin.UpdateInstanceConfigRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if instance_config is not None: + request.instance_config = instance_config + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_instance_config, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("instance_config.name", request.instance_config.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + spanner_instance_admin.InstanceConfig, + metadata_type=spanner_instance_admin.UpdateInstanceConfigMetadata, + ) + + # Done; return the response. + return response + + async def delete_instance_config(self, + request: Optional[Union[spanner_instance_admin.DeleteInstanceConfigRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes the instance config. Deletion is only allowed when no + instances are using the configuration. If any instances are + using the config, returns ``FAILED_PRECONDITION``. + + Only user managed configurations can be deleted. + + Authorization requires ``spanner.instanceConfigs.delete`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + async def sample_delete_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceConfigRequest( + name="name_value", + ) + + # Make the request + await client.delete_instance_config(request=request) + + Args: + request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstanceConfigRequest, dict]]): + The request object. The request for + [DeleteInstanceConfigRequest][InstanceAdmin.DeleteInstanceConfigRequest]. + name (:class:`str`): + Required. The name of the instance configuration to be + deleted. Values are of the form + ``projects//instanceConfigs/`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_instance_admin.DeleteInstanceConfigRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.delete_instance_config, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def list_instance_config_operations(self, + request: Optional[Union[spanner_instance_admin.ListInstanceConfigOperationsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListInstanceConfigOperationsAsyncPager: + r"""Lists the user-managed instance config [long-running + operations][google.longrunning.Operation] in the given project. + An instance config operation has a name of the form + ``projects//instanceConfigs//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. Operations returned are ordered by + ``operation.metadata.value.start_time`` in descending order + starting from the most recently started operation. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + async def sample_list_instance_config_operations(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_config_operations(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest, dict]]): + The request object. The request for + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. + parent (:class:`str`): + Required. The project of the instance config operations. + Values are of the form ``projects/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigOperationsAsyncPager: + The response for + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_instance_admin.ListInstanceConfigOperationsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_instance_config_operations, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListInstanceConfigOperationsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_instances(self, + request: Optional[Union[spanner_instance_admin.ListInstancesRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListInstancesAsyncPager: + r"""Lists all instances in the given project. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + async def sample_list_instances(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstancesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instances(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest, dict]]): + The request object. The request for + [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. + parent (:class:`str`): + Required. The name of the project for which a list of + instances is requested. Values are of the form + ``projects/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancesAsyncPager: + The response for + [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_instance_admin.ListInstancesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_instances, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListInstancesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_instance(self, + request: Optional[Union[spanner_instance_admin.GetInstanceRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner_instance_admin.Instance: + r"""Gets information about a particular instance. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + async def sample_get_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceRequest( + name="name_value", + ) + + # Make the request + response = await client.get_instance(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest, dict]]): + The request object. The request for + [GetInstance][google.spanner.admin.instance.v1.InstanceAdmin.GetInstance]. + name (:class:`str`): + Required. The name of the requested instance. Values are + of the form ``projects//instances/``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_instance_v1.types.Instance: + An isolated set of Cloud Spanner + resources on which databases can be + hosted. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_instance_admin.GetInstanceRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_instance, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def create_instance(self, + request: Optional[Union[spanner_instance_admin.CreateInstanceRequest, dict]] = None, + *, + parent: Optional[str] = None, + instance_id: Optional[str] = None, + instance: Optional[spanner_instance_admin.Instance] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Creates an instance and begins preparing it to begin serving. + The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of preparing the new instance. The instance name is + assigned by the caller. If the named instance already exists, + ``CreateInstance`` returns ``ALREADY_EXISTS``. + + Immediately upon completion of this request: + + - The instance is readable via the API, with all requested + attributes but no allocated resources. Its state is + ``CREATING``. + + Until completion of the returned operation: + + - Cancelling the operation renders the instance immediately + unreadable via the API. + - The instance can be deleted. + - All other attempts to modify the instance are rejected. + + Upon completion of the returned operation: + + - Billing for all successfully-allocated resources begins (some + types may have lower than the requested levels). + - Databases can be created in the instance. + - The instance's allocated resource levels are readable via the + API. + - The instance's state becomes ``READY``. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and can be + used to track creation of the instance. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateInstanceMetadata][google.spanner.admin.instance.v1.CreateInstanceMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Instance][google.spanner.admin.instance.v1.Instance], if + successful. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + async def sample_create_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.CreateInstanceRequest( + parent="parent_value", + instance_id="instance_id_value", + instance=instance, + ) + + # Make the request + operation = client.create_instance(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.CreateInstanceRequest, dict]]): + The request object. The request for + [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance]. + parent (:class:`str`): + Required. The name of the project in which to create the + instance. Values are of the form ``projects/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + instance_id (:class:`str`): + Required. The ID of the instance to create. Valid + identifiers are of the form ``[a-z][-a-z0-9]*[a-z0-9]`` + and must be between 2 and 64 characters in length. + + This corresponds to the ``instance_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + instance (:class:`google.cloud.spanner_admin_instance_v1.types.Instance`): + Required. The instance to create. The name may be + omitted, but if specified must be + ``/instances/``. + + This corresponds to the ``instance`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_instance_v1.types.Instance` + An isolated set of Cloud Spanner resources on which + databases can be hosted. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, instance_id, instance]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_instance_admin.CreateInstanceRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if instance_id is not None: + request.instance_id = instance_id + if instance is not None: + request.instance = instance + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.create_instance, + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + spanner_instance_admin.Instance, + metadata_type=spanner_instance_admin.CreateInstanceMetadata, + ) + + # Done; return the response. + return response + + async def update_instance(self, + request: Optional[Union[spanner_instance_admin.UpdateInstanceRequest, dict]] = None, + *, + instance: Optional[spanner_instance_admin.Instance] = None, + field_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Updates an instance, and begins allocating or releasing + resources as requested. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the instance. If the named instance + does not exist, returns ``NOT_FOUND``. + + Immediately upon completion of this request: + + - For resource types for which a decrease in the instance's + allocation has been requested, billing is based on the + newly-requested level. + + Until completion of the returned operation: + + - Cancelling the operation sets its metadata's + [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceMetadata.cancel_time], + and begins restoring resources to their pre-request values. + The operation is guaranteed to succeed at undoing all + resource changes, after which point it terminates with a + ``CANCELLED`` status. + - All other attempts to modify the instance are rejected. + - Reading the instance via the API continues to give the + pre-request resource levels. + + Upon completion of the returned operation: + + - Billing begins for all successfully-allocated resources (some + types may have lower than the requested levels). + - All newly-reserved resources are available for serving the + instance's tables. + - The instance's new resource levels are readable via the API. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and can be + used to track the instance modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateInstanceMetadata][google.spanner.admin.instance.v1.UpdateInstanceMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Instance][google.spanner.admin.instance.v1.Instance], if + successful. + + Authorization requires ``spanner.instances.update`` permission + on the resource + [name][google.spanner.admin.instance.v1.Instance.name]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + async def sample_update_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.UpdateInstanceRequest( + instance=instance, + ) + + # Make the request + operation = client.update_instance(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstanceRequest, dict]]): + The request object. The request for + [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance]. + instance (:class:`google.cloud.spanner_admin_instance_v1.types.Instance`): + Required. The instance to update, which must always + include the instance name. Otherwise, only fields + mentioned in + [field_mask][google.spanner.admin.instance.v1.UpdateInstanceRequest.field_mask] + need be included. + + This corresponds to the ``instance`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + field_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. A mask specifying which fields in + [Instance][google.spanner.admin.instance.v1.Instance] + should be updated. The field mask must always be + specified; this prevents any future fields in + [Instance][google.spanner.admin.instance.v1.Instance] + from being erased accidentally by clients that do not + know about them. + + This corresponds to the ``field_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_instance_v1.types.Instance` + An isolated set of Cloud Spanner resources on which + databases can be hosted. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([instance, field_mask]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_instance_admin.UpdateInstanceRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if instance is not None: + request.instance = instance + if field_mask is not None: + request.field_mask = field_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_instance, + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("instance.name", request.instance.name), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + spanner_instance_admin.Instance, + metadata_type=spanner_instance_admin.UpdateInstanceMetadata, + ) + + # Done; return the response. + return response + + async def delete_instance(self, + request: Optional[Union[spanner_instance_admin.DeleteInstanceRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes an instance. + + Immediately upon completion of the request: + + - Billing ceases for all of the instance's reserved resources. + + Soon afterward: + + - The instance and *all of its databases* immediately and + irrevocably disappear from the API. All data in the databases + is permanently deleted. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + async def sample_delete_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceRequest( + name="name_value", + ) + + # Make the request + await client.delete_instance(request=request) + + Args: + request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstanceRequest, dict]]): + The request object. The request for + [DeleteInstance][google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance]. + name (:class:`str`): + Required. The name of the instance to be deleted. Values + are of the form + ``projects//instances/`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + request = spanner_instance_admin.DeleteInstanceRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.delete_instance, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def set_iam_policy(self, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, + *, + resource: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the access control policy on an instance resource. Replaces + any existing policy. + + Authorization requires ``spanner.instances.setIamPolicy`` on + [resource][google.iam.v1.SetIamPolicyRequest.resource]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + async def sample_set_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = await client.set_iam_policy(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]]): + The request object. Request message for ``SetIamPolicy`` method. + resource (:class:`str`): + REQUIRED: The resource for which the + policy is being specified. See the + operation documentation for the + appropriate value for this field. + + This corresponds to the ``resource`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.iam.v1.policy_pb2.Policy: + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. + + A Policy is a collection of bindings. A binding binds + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": [ "user:eve@example.com" ], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ], "etag": "BwWWja0YfJA=", "version": 3 + + } + + **YAML example:** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 + + For a description of IAM and its features, see the + [IAM + documentation](\ https://cloud.google.com/iam/docs/). + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([resource]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + elif not request: + request = iam_policy_pb2.SetIamPolicyRequest(resource=resource, ) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy(self, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, + *, + resource: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the access control policy for an instance resource. Returns + an empty policy if an instance exists but does not have a policy + set. + + Authorization requires ``spanner.instances.getIamPolicy`` on + [resource][google.iam.v1.GetIamPolicyRequest.resource]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + async def sample_get_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = await client.get_iam_policy(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]]): + The request object. Request message for ``GetIamPolicy`` method. + resource (:class:`str`): + REQUIRED: The resource for which the + policy is being requested. See the + operation documentation for the + appropriate value for this field. + + This corresponds to the ``resource`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.iam.v1.policy_pb2.Policy: + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. + + A Policy is a collection of bindings. A binding binds + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": [ "user:eve@example.com" ], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ], "etag": "BwWWja0YfJA=", "version": 3 + + } + + **YAML example:** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 + + For a description of IAM and its features, see the + [IAM + documentation](\ https://cloud.google.com/iam/docs/). + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([resource]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + elif not request: + request = iam_policy_pb2.GetIamPolicyRequest(resource=resource, ) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_iam_policy, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions(self, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, + *, + resource: Optional[str] = None, + permissions: Optional[MutableSequence[str]] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Returns permissions that the caller has on the specified + instance resource. + + Attempting this RPC on a non-existent Cloud Spanner instance + resource will result in a NOT_FOUND error if the user has + ``spanner.instances.list`` permission on the containing Google + Cloud Project. Otherwise returns an empty set of permissions. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + async def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value1', 'permissions_value2'], + ) + + # Make the request + response = await client.test_iam_permissions(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]]): + The request object. Request message for ``TestIamPermissions`` method. + resource (:class:`str`): + REQUIRED: The resource for which the + policy detail is being requested. See + the operation documentation for the + appropriate value for this field. + + This corresponds to the ``resource`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + permissions (:class:`MutableSequence[str]`): + The set of permissions to check for the ``resource``. + Permissions with wildcards (such as '*' or 'storage.*') + are not allowed. For more information see `IAM + Overview `__. + + This corresponds to the ``permissions`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: + Response message for TestIamPermissions method. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([resource, permissions]) + if request is not None and has_flattened_params: + raise ValueError("If the `request` argument is set, then none of " + "the individual field arguments should be set.") + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + elif not request: + request = iam_policy_pb2.TestIamPermissionsRequest(resource=resource, permissions=permissions, ) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=30.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource), + )), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + + +__all__ = ( + "InstanceAdminAsyncClient", +) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py new file mode 100644 index 0000000000..098e55469d --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py @@ -0,0 +1,2391 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +import os +import re +from typing import Dict, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast + +from google.cloud.spanner_admin_instance_v1 import gapic_version as package_version + +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.spanner_admin_instance_v1.services.instance_admin import pagers +from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import InstanceAdminTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import InstanceAdminGrpcTransport +from .transports.grpc_asyncio import InstanceAdminGrpcAsyncIOTransport +from .transports.rest import InstanceAdminRestTransport + + +class InstanceAdminClientMeta(type): + """Metaclass for the InstanceAdmin client. + + This provides class-level methods for building and retrieving + support objects (e.g. transport) without polluting the client instance + objects. + """ + _transport_registry = OrderedDict() # type: Dict[str, Type[InstanceAdminTransport]] + _transport_registry["grpc"] = InstanceAdminGrpcTransport + _transport_registry["grpc_asyncio"] = InstanceAdminGrpcAsyncIOTransport + _transport_registry["rest"] = InstanceAdminRestTransport + + def get_transport_class(cls, + label: Optional[str] = None, + ) -> Type[InstanceAdminTransport]: + """Returns an appropriate transport class. + + Args: + label: The name of the desired transport. If none is + provided, then the first transport in the registry is used. + + Returns: + The transport class to use. + """ + # If a specific transport is requested, return that one. + if label: + return cls._transport_registry[label] + + # No transport is requested; return the default (that is, the first one + # in the dictionary). + return next(iter(cls._transport_registry.values())) + + +class InstanceAdminClient(metaclass=InstanceAdminClientMeta): + """Cloud Spanner Instance Admin API + The Cloud Spanner Instance Admin API can be used to create, + delete, modify and list instances. Instances are dedicated Cloud + Spanner serving and storage resources to be used by Cloud + Spanner databases. + Each instance has a "configuration", which dictates where the + serving resources for the Cloud Spanner instance are located + (e.g., US-central, Europe). Configurations are created by Google + based on resource availability. + + Cloud Spanner billing is based on the instances that exist and + their sizes. After an instance exists, there are no additional + per-database or per-operation charges for use of the instance + (though there may be additional network bandwidth charges). + Instances offer isolation: problems with databases in one + instance will not affect other instances. However, within an + instance databases can affect each other. For example, if one + database in an instance receives a lot of requests and consumes + most of the instance resources, fewer resources are available + for other databases in that instance, and their performance may + suffer. + """ + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + str: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + DEFAULT_ENDPOINT = "spanner.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + InstanceAdminClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + InstanceAdminClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file( + filename) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> InstanceAdminTransport: + """Returns the transport used by the client instance. + + Returns: + InstanceAdminTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def instance_path(project: str,instance: str,) -> str: + """Returns a fully-qualified instance string.""" + return "projects/{project}/instances/{instance}".format(project=project, instance=instance, ) + + @staticmethod + def parse_instance_path(path: str) -> Dict[str,str]: + """Parses a instance path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def instance_config_path(project: str,instance_config: str,) -> str: + """Returns a fully-qualified instance_config string.""" + return "projects/{project}/instanceConfigs/{instance_config}".format(project=project, instance_config=instance_config, ) + + @staticmethod + def parse_instance_config_path(path: str) -> Dict[str,str]: + """Parses a instance_config path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/instanceConfigs/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path(billing_account: str, ) -> str: + """Returns a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str,str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str, ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder, ) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str,str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str, ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization, ) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str,str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str, ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format(project=project, ) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str,str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str, ) -> str: + """Returns a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format(project=project, location=location, ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str,str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @classmethod + def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_options_lib.ClientOptions] = None): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variable is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + + def __init__(self, *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Optional[Union[str, InstanceAdminTransport]] = None, + client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the instance admin client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, InstanceAdminTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the + client. It won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + """ + if isinstance(client_options, dict): + client_options = client_options_lib.from_dict(client_options) + if client_options is None: + client_options = client_options_lib.ClientOptions() + client_options = cast(client_options_lib.ClientOptions, client_options) + + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source(client_options) + + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError("client_options.api_key and credentials are mutually exclusive") + + # Save or instantiate the transport. + # Ordinarily, we provide the transport, but allowing a custom transport + # instance provides an extensibility point for unusual situations. + if isinstance(transport, InstanceAdminTransport): + # transport is a InstanceAdminTransport instance. + if credentials or client_options.credentials_file or api_key_value: + raise ValueError("When providing a transport instance, " + "provide its credentials directly.") + if client_options.scopes: + raise ValueError( + "When providing a transport instance, provide its scopes " + "directly." + ) + self._transport = transport + else: + import google.auth._default # type: ignore + + if api_key_value and hasattr(google.auth._default, "get_api_key_credentials"): + credentials = google.auth._default.get_api_key_credentials(api_key_value) + + Transport = type(self).get_transport_class(transport) + self._transport = Transport( + credentials=credentials, + credentials_file=client_options.credentials_file, + host=api_endpoint, + scopes=client_options.scopes, + client_cert_source_for_mtls=client_cert_source_func, + quota_project_id=client_options.quota_project_id, + client_info=client_info, + always_use_jwt_access=True, + api_audience=client_options.api_audience, + ) + + def list_instance_configs(self, + request: Optional[Union[spanner_instance_admin.ListInstanceConfigsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListInstanceConfigsPager: + r"""Lists the supported instance configurations for a + given project. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + def sample_list_instance_configs(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_configs(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest, dict]): + The request object. The request for + [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. + parent (str): + Required. The name of the project for which a list of + supported instance configurations is requested. Values + are of the form ``projects/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigsPager: + The response for + [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_instance_admin.ListInstanceConfigsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_instance_admin.ListInstanceConfigsRequest): + request = spanner_instance_admin.ListInstanceConfigsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_instance_configs] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListInstanceConfigsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_instance_config(self, + request: Optional[Union[spanner_instance_admin.GetInstanceConfigRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner_instance_admin.InstanceConfig: + r"""Gets information about a particular instance + configuration. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + def sample_get_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceConfigRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance_config(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest, dict]): + The request object. The request for + [GetInstanceConfigRequest][google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig]. + name (str): + Required. The name of the requested instance + configuration. Values are of the form + ``projects//instanceConfigs/``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_instance_v1.types.InstanceConfig: + A possible configuration for a Cloud + Spanner instance. Configurations define + the geographic placement of nodes and + their replication. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_instance_admin.GetInstanceConfigRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_instance_admin.GetInstanceConfigRequest): + request = spanner_instance_admin.GetInstanceConfigRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_instance_config] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def create_instance_config(self, + request: Optional[Union[spanner_instance_admin.CreateInstanceConfigRequest, dict]] = None, + *, + parent: Optional[str] = None, + instance_config: Optional[spanner_instance_admin.InstanceConfig] = None, + instance_config_id: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Creates an instance config and begins preparing it to be used. + The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of preparing the new instance config. The instance + config name is assigned by the caller. If the named instance + config already exists, ``CreateInstanceConfig`` returns + ``ALREADY_EXISTS``. + + Immediately after the request returns: + + - The instance config is readable via the API, with all + requested attributes. The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. Its state is ``CREATING``. + + While the operation is pending: + + - Cancelling the operation renders the instance config + immediately unreadable via the API. + - Except for deleting the creating resource, all other attempts + to modify the instance config are rejected. + + Upon completion of the returned operation: + + - Instances can be created using the instance configuration. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. Its state becomes ``READY``. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track creation of the instance config. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.create`` + permission on the resource + [parent][google.spanner.admin.instance.v1.CreateInstanceConfigRequest.parent]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + def sample_create_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.CreateInstanceConfigRequest( + parent="parent_value", + instance_config_id="instance_config_id_value", + ) + + # Make the request + operation = client.create_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.CreateInstanceConfigRequest, dict]): + The request object. The request for + [CreateInstanceConfigRequest][InstanceAdmin.CreateInstanceConfigRequest]. + parent (str): + Required. The name of the project in which to create the + instance config. Values are of the form + ``projects/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): + Required. The InstanceConfig proto of the configuration + to create. instance_config.name must be + ``/instanceConfigs/``. + instance_config.base_config must be a Google managed + configuration name, e.g. /instanceConfigs/us-east1, + /instanceConfigs/nam3. + + This corresponds to the ``instance_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + instance_config_id (str): + Required. The ID of the instance config to create. Valid + identifiers are of the form + ``custom-[-a-z0-9]*[a-z0-9]`` and must be between 2 and + 64 characters in length. The ``custom-`` prefix is + required to avoid name conflicts with Google managed + configurations. + + This corresponds to the ``instance_config_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig` A possible configuration for a Cloud Spanner instance. Configurations + define the geographic placement of nodes and their + replication. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, instance_config, instance_config_id]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_instance_admin.CreateInstanceConfigRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_instance_admin.CreateInstanceConfigRequest): + request = spanner_instance_admin.CreateInstanceConfigRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if instance_config is not None: + request.instance_config = instance_config + if instance_config_id is not None: + request.instance_config_id = instance_config_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_instance_config] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + spanner_instance_admin.InstanceConfig, + metadata_type=spanner_instance_admin.CreateInstanceConfigMetadata, + ) + + # Done; return the response. + return response + + def update_instance_config(self, + request: Optional[Union[spanner_instance_admin.UpdateInstanceConfigRequest, dict]] = None, + *, + instance_config: Optional[spanner_instance_admin.InstanceConfig] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Updates an instance config. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the instance. If the named instance + config does not exist, returns ``NOT_FOUND``. + + Only user managed configurations can be updated. + + Immediately after the request returns: + + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. + + While the operation is pending: + + - Cancelling the operation sets its metadata's + [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata.cancel_time]. + The operation is guaranteed to succeed at undoing all + changes, after which point it terminates with a ``CANCELLED`` + status. + - All other attempts to modify the instance config are + rejected. + - Reading the instance config via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - Creating instances using the instance configuration uses the + new values. + - The instance config's new values are readable via the API. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track the instance config modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateInstanceConfigMetadata][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.update`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + def sample_update_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.UpdateInstanceConfigRequest( + ) + + # Make the request + operation = client.update_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstanceConfigRequest, dict]): + The request object. The request for + [UpdateInstanceConfigRequest][InstanceAdmin.UpdateInstanceConfigRequest]. + instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): + Required. The user instance config to update, which must + always include the instance config name. Otherwise, only + fields mentioned in + [update_mask][google.spanner.admin.instance.v1.UpdateInstanceConfigRequest.update_mask] + need be included. To prevent conflicts of concurrent + updates, + [etag][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + can be used. + + This corresponds to the ``instance_config`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. A mask specifying which fields in + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] + should be updated. The field mask must always be + specified; this prevents any future fields in + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] + from being erased accidentally by clients that do not + know about them. Only display_name and labels can be + updated. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig` A possible configuration for a Cloud Spanner instance. Configurations + define the geographic placement of nodes and their + replication. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([instance_config, update_mask]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_instance_admin.UpdateInstanceConfigRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_instance_admin.UpdateInstanceConfigRequest): + request = spanner_instance_admin.UpdateInstanceConfigRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if instance_config is not None: + request.instance_config = instance_config + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_instance_config] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("instance_config.name", request.instance_config.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + spanner_instance_admin.InstanceConfig, + metadata_type=spanner_instance_admin.UpdateInstanceConfigMetadata, + ) + + # Done; return the response. + return response + + def delete_instance_config(self, + request: Optional[Union[spanner_instance_admin.DeleteInstanceConfigRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes the instance config. Deletion is only allowed when no + instances are using the configuration. If any instances are + using the config, returns ``FAILED_PRECONDITION``. + + Only user managed configurations can be deleted. + + Authorization requires ``spanner.instanceConfigs.delete`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + def sample_delete_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceConfigRequest( + name="name_value", + ) + + # Make the request + client.delete_instance_config(request=request) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstanceConfigRequest, dict]): + The request object. The request for + [DeleteInstanceConfigRequest][InstanceAdmin.DeleteInstanceConfigRequest]. + name (str): + Required. The name of the instance configuration to be + deleted. Values are of the form + ``projects//instanceConfigs/`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_instance_admin.DeleteInstanceConfigRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_instance_admin.DeleteInstanceConfigRequest): + request = spanner_instance_admin.DeleteInstanceConfigRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.delete_instance_config] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def list_instance_config_operations(self, + request: Optional[Union[spanner_instance_admin.ListInstanceConfigOperationsRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListInstanceConfigOperationsPager: + r"""Lists the user-managed instance config [long-running + operations][google.longrunning.Operation] in the given project. + An instance config operation has a name of the form + ``projects//instanceConfigs//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. Operations returned are ordered by + ``operation.metadata.value.start_time`` in descending order + starting from the most recently started operation. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + def sample_list_instance_config_operations(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_config_operations(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest, dict]): + The request object. The request for + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. + parent (str): + Required. The project of the instance config operations. + Values are of the form ``projects/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigOperationsPager: + The response for + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_instance_admin.ListInstanceConfigOperationsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_instance_admin.ListInstanceConfigOperationsRequest): + request = spanner_instance_admin.ListInstanceConfigOperationsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_instance_config_operations] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListInstanceConfigOperationsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_instances(self, + request: Optional[Union[spanner_instance_admin.ListInstancesRequest, dict]] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListInstancesPager: + r"""Lists all instances in the given project. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + def sample_list_instances(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstancesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instances(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest, dict]): + The request object. The request for + [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. + parent (str): + Required. The name of the project for which a list of + instances is requested. Values are of the form + ``projects/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancesPager: + The response for + [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_instance_admin.ListInstancesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_instance_admin.ListInstancesRequest): + request = spanner_instance_admin.ListInstancesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_instances] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListInstancesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_instance(self, + request: Optional[Union[spanner_instance_admin.GetInstanceRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> spanner_instance_admin.Instance: + r"""Gets information about a particular instance. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + def sample_get_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest, dict]): + The request object. The request for + [GetInstance][google.spanner.admin.instance.v1.InstanceAdmin.GetInstance]. + name (str): + Required. The name of the requested instance. Values are + of the form ``projects//instances/``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.spanner_admin_instance_v1.types.Instance: + An isolated set of Cloud Spanner + resources on which databases can be + hosted. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_instance_admin.GetInstanceRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_instance_admin.GetInstanceRequest): + request = spanner_instance_admin.GetInstanceRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_instance] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def create_instance(self, + request: Optional[Union[spanner_instance_admin.CreateInstanceRequest, dict]] = None, + *, + parent: Optional[str] = None, + instance_id: Optional[str] = None, + instance: Optional[spanner_instance_admin.Instance] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Creates an instance and begins preparing it to begin serving. + The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of preparing the new instance. The instance name is + assigned by the caller. If the named instance already exists, + ``CreateInstance`` returns ``ALREADY_EXISTS``. + + Immediately upon completion of this request: + + - The instance is readable via the API, with all requested + attributes but no allocated resources. Its state is + ``CREATING``. + + Until completion of the returned operation: + + - Cancelling the operation renders the instance immediately + unreadable via the API. + - The instance can be deleted. + - All other attempts to modify the instance are rejected. + + Upon completion of the returned operation: + + - Billing for all successfully-allocated resources begins (some + types may have lower than the requested levels). + - Databases can be created in the instance. + - The instance's allocated resource levels are readable via the + API. + - The instance's state becomes ``READY``. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and can be + used to track creation of the instance. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateInstanceMetadata][google.spanner.admin.instance.v1.CreateInstanceMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Instance][google.spanner.admin.instance.v1.Instance], if + successful. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + def sample_create_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.CreateInstanceRequest( + parent="parent_value", + instance_id="instance_id_value", + instance=instance, + ) + + # Make the request + operation = client.create_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.CreateInstanceRequest, dict]): + The request object. The request for + [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance]. + parent (str): + Required. The name of the project in which to create the + instance. Values are of the form ``projects/``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + instance_id (str): + Required. The ID of the instance to create. Valid + identifiers are of the form ``[a-z][-a-z0-9]*[a-z0-9]`` + and must be between 2 and 64 characters in length. + + This corresponds to the ``instance_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + instance (google.cloud.spanner_admin_instance_v1.types.Instance): + Required. The instance to create. The name may be + omitted, but if specified must be + ``/instances/``. + + This corresponds to the ``instance`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_instance_v1.types.Instance` + An isolated set of Cloud Spanner resources on which + databases can be hosted. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, instance_id, instance]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_instance_admin.CreateInstanceRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_instance_admin.CreateInstanceRequest): + request = spanner_instance_admin.CreateInstanceRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if instance_id is not None: + request.instance_id = instance_id + if instance is not None: + request.instance = instance + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_instance] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("parent", request.parent), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + spanner_instance_admin.Instance, + metadata_type=spanner_instance_admin.CreateInstanceMetadata, + ) + + # Done; return the response. + return response + + def update_instance(self, + request: Optional[Union[spanner_instance_admin.UpdateInstanceRequest, dict]] = None, + *, + instance: Optional[spanner_instance_admin.Instance] = None, + field_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Updates an instance, and begins allocating or releasing + resources as requested. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the instance. If the named instance + does not exist, returns ``NOT_FOUND``. + + Immediately upon completion of this request: + + - For resource types for which a decrease in the instance's + allocation has been requested, billing is based on the + newly-requested level. + + Until completion of the returned operation: + + - Cancelling the operation sets its metadata's + [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceMetadata.cancel_time], + and begins restoring resources to their pre-request values. + The operation is guaranteed to succeed at undoing all + resource changes, after which point it terminates with a + ``CANCELLED`` status. + - All other attempts to modify the instance are rejected. + - Reading the instance via the API continues to give the + pre-request resource levels. + + Upon completion of the returned operation: + + - Billing begins for all successfully-allocated resources (some + types may have lower than the requested levels). + - All newly-reserved resources are available for serving the + instance's tables. + - The instance's new resource levels are readable via the API. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and can be + used to track the instance modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateInstanceMetadata][google.spanner.admin.instance.v1.UpdateInstanceMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Instance][google.spanner.admin.instance.v1.Instance], if + successful. + + Authorization requires ``spanner.instances.update`` permission + on the resource + [name][google.spanner.admin.instance.v1.Instance.name]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + def sample_update_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.UpdateInstanceRequest( + instance=instance, + ) + + # Make the request + operation = client.update_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstanceRequest, dict]): + The request object. The request for + [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance]. + instance (google.cloud.spanner_admin_instance_v1.types.Instance): + Required. The instance to update, which must always + include the instance name. Otherwise, only fields + mentioned in + [field_mask][google.spanner.admin.instance.v1.UpdateInstanceRequest.field_mask] + need be included. + + This corresponds to the ``instance`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + field_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. A mask specifying which fields in + [Instance][google.spanner.admin.instance.v1.Instance] + should be updated. The field mask must always be + specified; this prevents any future fields in + [Instance][google.spanner.admin.instance.v1.Instance] + from being erased accidentally by clients that do not + know about them. + + This corresponds to the ``field_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_instance_v1.types.Instance` + An isolated set of Cloud Spanner resources on which + databases can be hosted. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([instance, field_mask]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_instance_admin.UpdateInstanceRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_instance_admin.UpdateInstanceRequest): + request = spanner_instance_admin.UpdateInstanceRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if instance is not None: + request.instance = instance + if field_mask is not None: + request.field_mask = field_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_instance] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("instance.name", request.instance.name), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + spanner_instance_admin.Instance, + metadata_type=spanner_instance_admin.UpdateInstanceMetadata, + ) + + # Done; return the response. + return response + + def delete_instance(self, + request: Optional[Union[spanner_instance_admin.DeleteInstanceRequest, dict]] = None, + *, + name: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes an instance. + + Immediately upon completion of the request: + + - Billing ceases for all of the instance's reserved resources. + + Soon afterward: + + - The instance and *all of its databases* immediately and + irrevocably disappear from the API. All data in the databases + is permanently deleted. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + + def sample_delete_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceRequest( + name="name_value", + ) + + # Make the request + client.delete_instance(request=request) + + Args: + request (Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstanceRequest, dict]): + The request object. The request for + [DeleteInstance][google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance]. + name (str): + Required. The name of the instance to be deleted. Values + are of the form + ``projects//instances/`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_instance_admin.DeleteInstanceRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_instance_admin.DeleteInstanceRequest): + request = spanner_instance_admin.DeleteInstanceRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.delete_instance] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("name", request.name), + )), + ) + + # Send the request. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def set_iam_policy(self, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, + *, + resource: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the access control policy on an instance resource. Replaces + any existing policy. + + Authorization requires ``spanner.instances.setIamPolicy`` on + [resource][google.iam.v1.SetIamPolicyRequest.resource]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_set_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.set_iam_policy(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]): + The request object. Request message for ``SetIamPolicy`` method. + resource (str): + REQUIRED: The resource for which the + policy is being specified. See the + operation documentation for the + appropriate value for this field. + + This corresponds to the ``resource`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.iam.v1.policy_pb2.Policy: + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. + + A Policy is a collection of bindings. A binding binds + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": [ "user:eve@example.com" ], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ], "etag": "BwWWja0YfJA=", "version": 3 + + } + + **YAML example:** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 + + For a description of IAM and its features, see the + [IAM + documentation](\ https://cloud.google.com/iam/docs/). + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([resource]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + request = iam_policy_pb2.SetIamPolicyRequest(**request) + elif not request: + # Null request, just make one. + request = iam_policy_pb2.SetIamPolicyRequest() + if resource is not None: + request.resource = resource + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.set_iam_policy] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy(self, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, + *, + resource: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the access control policy for an instance resource. Returns + an empty policy if an instance exists but does not have a policy + set. + + Authorization requires ``spanner.instances.getIamPolicy`` on + [resource][google.iam.v1.GetIamPolicyRequest.resource]. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_get_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.get_iam_policy(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]): + The request object. Request message for ``GetIamPolicy`` method. + resource (str): + REQUIRED: The resource for which the + policy is being requested. See the + operation documentation for the + appropriate value for this field. + + This corresponds to the ``resource`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.iam.v1.policy_pb2.Policy: + An Identity and Access Management (IAM) policy, which specifies access + controls for Google Cloud resources. + + A Policy is a collection of bindings. A binding binds + one or more members, or principals, to a single role. + Principals can be user accounts, service accounts, + Google groups, and domains (such as G Suite). A role + is a named list of permissions; each role can be an + IAM predefined role or a user-created custom role. + + For some types of Google Cloud resources, a binding + can also specify a condition, which is a logical + expression that allows access to a resource only if + the expression evaluates to true. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the [IAM + documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). + + **JSON example:** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": [ "user:eve@example.com" ], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ], "etag": "BwWWja0YfJA=", "version": 3 + + } + + **YAML example:** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') etag: + BwWWja0YfJA= version: 3 + + For a description of IAM and its features, see the + [IAM + documentation](\ https://cloud.google.com/iam/docs/). + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([resource]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + request = iam_policy_pb2.GetIamPolicyRequest(**request) + elif not request: + # Null request, just make one. + request = iam_policy_pb2.GetIamPolicyRequest() + if resource is not None: + request.resource = resource + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_iam_policy] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions(self, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, + *, + resource: Optional[str] = None, + permissions: Optional[MutableSequence[str]] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Returns permissions that the caller has on the specified + instance resource. + + Attempting this RPC on a non-existent Cloud Spanner instance + resource will result in a NOT_FOUND error if the user has + ``spanner.instances.list`` permission on the containing Google + Cloud Project. Otherwise returns an empty set of permissions. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_instance_v1 + from google.iam.v1 import iam_policy_pb2 # type: ignore + + def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value1', 'permissions_value2'], + ) + + # Make the request + response = client.test_iam_permissions(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]): + The request object. Request message for ``TestIamPermissions`` method. + resource (str): + REQUIRED: The resource for which the + policy detail is being requested. See + the operation documentation for the + appropriate value for this field. + + This corresponds to the ``resource`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + permissions (MutableSequence[str]): + The set of permissions to check for the ``resource``. + Permissions with wildcards (such as '*' or 'storage.*') + are not allowed. For more information see `IAM + Overview `__. + + This corresponds to the ``permissions`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: + Response message for TestIamPermissions method. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([resource, permissions]) + if request is not None and has_flattened_params: + raise ValueError('If the `request` argument is set, then none of ' + 'the individual field arguments should be set.') + + if isinstance(request, dict): + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + elif not request: + # Null request, just make one. + request = iam_policy_pb2.TestIamPermissionsRequest() + if resource is not None: + request.resource = resource + if permissions: + request.permissions.extend(permissions) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ("resource", request.resource), + )), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self) -> "InstanceAdminClient": + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + + + + + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + + +__all__ = ( + "InstanceAdminClient", +) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py new file mode 100644 index 0000000000..747e91af6b --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py @@ -0,0 +1,382 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from typing import Any, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator + +from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin +from google.longrunning import operations_pb2 # type: ignore + + +class ListInstanceConfigsPager: + """A pager for iterating through ``list_instance_configs`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``instance_configs`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListInstanceConfigs`` requests and continue to iterate + through the ``instance_configs`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., spanner_instance_admin.ListInstanceConfigsResponse], + request: spanner_instance_admin.ListInstanceConfigsRequest, + response: spanner_instance_admin.ListInstanceConfigsResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest): + The initial request object. + response (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner_instance_admin.ListInstanceConfigsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[spanner_instance_admin.ListInstanceConfigsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[spanner_instance_admin.InstanceConfig]: + for page in self.pages: + yield from page.instance_configs + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListInstanceConfigsAsyncPager: + """A pager for iterating through ``list_instance_configs`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``instance_configs`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListInstanceConfigs`` requests and continue to iterate + through the ``instance_configs`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., Awaitable[spanner_instance_admin.ListInstanceConfigsResponse]], + request: spanner_instance_admin.ListInstanceConfigsRequest, + response: spanner_instance_admin.ListInstanceConfigsResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest): + The initial request object. + response (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner_instance_admin.ListInstanceConfigsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[spanner_instance_admin.ListInstanceConfigsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + def __aiter__(self) -> AsyncIterator[spanner_instance_admin.InstanceConfig]: + async def async_generator(): + async for page in self.pages: + for response in page.instance_configs: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListInstanceConfigOperationsPager: + """A pager for iterating through ``list_instance_config_operations`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``operations`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListInstanceConfigOperations`` requests and continue to iterate + through the ``operations`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., spanner_instance_admin.ListInstanceConfigOperationsResponse], + request: spanner_instance_admin.ListInstanceConfigOperationsRequest, + response: spanner_instance_admin.ListInstanceConfigOperationsResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest): + The initial request object. + response (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner_instance_admin.ListInstanceConfigOperationsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[spanner_instance_admin.ListInstanceConfigOperationsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[operations_pb2.Operation]: + for page in self.pages: + yield from page.operations + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListInstanceConfigOperationsAsyncPager: + """A pager for iterating through ``list_instance_config_operations`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``operations`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListInstanceConfigOperations`` requests and continue to iterate + through the ``operations`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., Awaitable[spanner_instance_admin.ListInstanceConfigOperationsResponse]], + request: spanner_instance_admin.ListInstanceConfigOperationsRequest, + response: spanner_instance_admin.ListInstanceConfigOperationsResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest): + The initial request object. + response (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner_instance_admin.ListInstanceConfigOperationsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[spanner_instance_admin.ListInstanceConfigOperationsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + def __aiter__(self) -> AsyncIterator[operations_pb2.Operation]: + async def async_generator(): + async for page in self.pages: + for response in page.operations: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListInstancesPager: + """A pager for iterating through ``list_instances`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_instance_v1.types.ListInstancesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``instances`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListInstances`` requests and continue to iterate + through the ``instances`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_instance_v1.types.ListInstancesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., spanner_instance_admin.ListInstancesResponse], + request: spanner_instance_admin.ListInstancesRequest, + response: spanner_instance_admin.ListInstancesResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest): + The initial request object. + response (google.cloud.spanner_admin_instance_v1.types.ListInstancesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner_instance_admin.ListInstancesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[spanner_instance_admin.ListInstancesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[spanner_instance_admin.Instance]: + for page in self.pages: + yield from page.instances + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) + + +class ListInstancesAsyncPager: + """A pager for iterating through ``list_instances`` requests. + + This class thinly wraps an initial + :class:`google.cloud.spanner_admin_instance_v1.types.ListInstancesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``instances`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListInstances`` requests and continue to iterate + through the ``instances`` field on the + corresponding responses. + + All the usual :class:`google.cloud.spanner_admin_instance_v1.types.ListInstancesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + def __init__(self, + method: Callable[..., Awaitable[spanner_instance_admin.ListInstancesResponse]], + request: spanner_instance_admin.ListInstancesRequest, + response: spanner_instance_admin.ListInstancesResponse, + *, + metadata: Sequence[Tuple[str, str]] = ()): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest): + The initial request object. + response (google.cloud.spanner_admin_instance_v1.types.ListInstancesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = spanner_instance_admin.ListInstancesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[spanner_instance_admin.ListInstancesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + def __aiter__(self) -> AsyncIterator[spanner_instance_admin.Instance]: + async def async_generator(): + async for page in self.pages: + for response in page.instances: + yield response + + return async_generator() + + def __repr__(self) -> str: + return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py new file mode 100644 index 0000000000..14ec3ceb61 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from collections import OrderedDict +from typing import Dict, Type + +from .base import InstanceAdminTransport +from .grpc import InstanceAdminGrpcTransport +from .grpc_asyncio import InstanceAdminGrpcAsyncIOTransport +from .rest import InstanceAdminRestTransport +from .rest import InstanceAdminRestInterceptor + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[InstanceAdminTransport]] +_transport_registry['grpc'] = InstanceAdminGrpcTransport +_transport_registry['grpc_asyncio'] = InstanceAdminGrpcAsyncIOTransport +_transport_registry['rest'] = InstanceAdminRestTransport + +__all__ = ( + 'InstanceAdminTransport', + 'InstanceAdminGrpcTransport', + 'InstanceAdminGrpcAsyncIOTransport', + 'InstanceAdminRestTransport', + 'InstanceAdminRestInterceptor', +) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py new file mode 100644 index 0000000000..d37e40fb4c --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py @@ -0,0 +1,383 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union + +from google.cloud.spanner_admin_instance_v1 import gapic_version as package_version + +import google.auth # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) + + +class InstanceAdminTransport(abc.ABC): + """Abstract transport class for InstanceAdmin.""" + + AUTH_SCOPES = ( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.admin', + ) + + DEFAULT_HOST: str = 'spanner.googleapis.com' + def __init__( + self, *, + host: str = DEFAULT_HOST, + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} + + # Save the scopes. + self._scopes = scopes + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, + **scopes_kwargs, + quota_project_id=quota_project_id + ) + elif credentials is None: + credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) + # Don't apply audience if the credentials file passed from user. + if hasattr(credentials, "with_gdch_audience"): + credentials = credentials.with_gdch_audience(api_audience if api_audience else host) + + # If the credentials are service account credentials, then always try to use self signed JWT. + if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ':' not in host: + host += ':443' + self._host = host + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.list_instance_configs: gapic_v1.method.wrap_method( + self.list_instance_configs, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.get_instance_config: gapic_v1.method.wrap_method( + self.get_instance_config, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.create_instance_config: gapic_v1.method.wrap_method( + self.create_instance_config, + default_timeout=None, + client_info=client_info, + ), + self.update_instance_config: gapic_v1.method.wrap_method( + self.update_instance_config, + default_timeout=None, + client_info=client_info, + ), + self.delete_instance_config: gapic_v1.method.wrap_method( + self.delete_instance_config, + default_timeout=None, + client_info=client_info, + ), + self.list_instance_config_operations: gapic_v1.method.wrap_method( + self.list_instance_config_operations, + default_timeout=None, + client_info=client_info, + ), + self.list_instances: gapic_v1.method.wrap_method( + self.list_instances, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.get_instance: gapic_v1.method.wrap_method( + self.get_instance, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.create_instance: gapic_v1.method.wrap_method( + self.create_instance, + default_timeout=3600.0, + client_info=client_info, + ), + self.update_instance: gapic_v1.method.wrap_method( + self.update_instance, + default_timeout=3600.0, + client_info=client_info, + ), + self.delete_instance: gapic_v1.method.wrap_method( + self.delete_instance, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), + self.set_iam_policy: gapic_v1.method.wrap_method( + self.set_iam_policy, + default_timeout=30.0, + client_info=client_info, + ), + self.get_iam_policy: gapic_v1.method.wrap_method( + self.get_iam_policy, + default_retry=retries.Retry( +initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=30.0, + ), + default_timeout=30.0, + client_info=client_info, + ), + self.test_iam_permissions: gapic_v1.method.wrap_method( + self.test_iam_permissions, + default_timeout=30.0, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self): + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def list_instance_configs(self) -> Callable[ + [spanner_instance_admin.ListInstanceConfigsRequest], + Union[ + spanner_instance_admin.ListInstanceConfigsResponse, + Awaitable[spanner_instance_admin.ListInstanceConfigsResponse] + ]]: + raise NotImplementedError() + + @property + def get_instance_config(self) -> Callable[ + [spanner_instance_admin.GetInstanceConfigRequest], + Union[ + spanner_instance_admin.InstanceConfig, + Awaitable[spanner_instance_admin.InstanceConfig] + ]]: + raise NotImplementedError() + + @property + def create_instance_config(self) -> Callable[ + [spanner_instance_admin.CreateInstanceConfigRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def update_instance_config(self) -> Callable[ + [spanner_instance_admin.UpdateInstanceConfigRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def delete_instance_config(self) -> Callable[ + [spanner_instance_admin.DeleteInstanceConfigRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def list_instance_config_operations(self) -> Callable[ + [spanner_instance_admin.ListInstanceConfigOperationsRequest], + Union[ + spanner_instance_admin.ListInstanceConfigOperationsResponse, + Awaitable[spanner_instance_admin.ListInstanceConfigOperationsResponse] + ]]: + raise NotImplementedError() + + @property + def list_instances(self) -> Callable[ + [spanner_instance_admin.ListInstancesRequest], + Union[ + spanner_instance_admin.ListInstancesResponse, + Awaitable[spanner_instance_admin.ListInstancesResponse] + ]]: + raise NotImplementedError() + + @property + def get_instance(self) -> Callable[ + [spanner_instance_admin.GetInstanceRequest], + Union[ + spanner_instance_admin.Instance, + Awaitable[spanner_instance_admin.Instance] + ]]: + raise NotImplementedError() + + @property + def create_instance(self) -> Callable[ + [spanner_instance_admin.CreateInstanceRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def update_instance(self) -> Callable[ + [spanner_instance_admin.UpdateInstanceRequest], + Union[ + operations_pb2.Operation, + Awaitable[operations_pb2.Operation] + ]]: + raise NotImplementedError() + + @property + def delete_instance(self) -> Callable[ + [spanner_instance_admin.DeleteInstanceRequest], + Union[ + empty_pb2.Empty, + Awaitable[empty_pb2.Empty] + ]]: + raise NotImplementedError() + + @property + def set_iam_policy(self) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[ + policy_pb2.Policy, + Awaitable[policy_pb2.Policy] + ]]: + raise NotImplementedError() + + @property + def get_iam_policy(self) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[ + policy_pb2.Policy, + Awaitable[policy_pb2.Policy] + ]]: + raise NotImplementedError() + + @property + def test_iam_permissions(self) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse] + ]]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + + +__all__ = ( + 'InstanceAdminTransport', +) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py new file mode 100644 index 0000000000..38b21a589f --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py @@ -0,0 +1,861 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore + +from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from .base import InstanceAdminTransport, DEFAULT_CLIENT_INFO + + +class InstanceAdminGrpcTransport(InstanceAdminTransport): + """gRPC backend transport for InstanceAdmin. + + Cloud Spanner Instance Admin API + The Cloud Spanner Instance Admin API can be used to create, + delete, modify and list instances. Instances are dedicated Cloud + Spanner serving and storage resources to be used by Cloud + Spanner databases. + Each instance has a "configuration", which dictates where the + serving resources for the Cloud Spanner instance are located + (e.g., US-central, Europe). Configurations are created by Google + based on resource availability. + + Cloud Spanner billing is based on the instances that exist and + their sizes. After an instance exists, there are no additional + per-database or per-operation charges for use of the instance + (though there may be additional network bandwidth charges). + Instances offer isolation: problems with databases in one + instance will not affect other instances. However, within an + instance databases can affect each other. For example, if one + database in an instance receives a lot of requests and consumes + most of the instance resources, fewer resources are available + for other databases in that instance, and their performance may + suffer. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + _stubs: Dict[str, Callable] + + def __init__(self, *, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[grpc.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel(cls, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service. + """ + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def list_instance_configs(self) -> Callable[ + [spanner_instance_admin.ListInstanceConfigsRequest], + spanner_instance_admin.ListInstanceConfigsResponse]: + r"""Return a callable for the list instance configs method over gRPC. + + Lists the supported instance configurations for a + given project. + + Returns: + Callable[[~.ListInstanceConfigsRequest], + ~.ListInstanceConfigsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_instance_configs' not in self._stubs: + self._stubs['list_instance_configs'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/ListInstanceConfigs', + request_serializer=spanner_instance_admin.ListInstanceConfigsRequest.serialize, + response_deserializer=spanner_instance_admin.ListInstanceConfigsResponse.deserialize, + ) + return self._stubs['list_instance_configs'] + + @property + def get_instance_config(self) -> Callable[ + [spanner_instance_admin.GetInstanceConfigRequest], + spanner_instance_admin.InstanceConfig]: + r"""Return a callable for the get instance config method over gRPC. + + Gets information about a particular instance + configuration. + + Returns: + Callable[[~.GetInstanceConfigRequest], + ~.InstanceConfig]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_instance_config' not in self._stubs: + self._stubs['get_instance_config'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/GetInstanceConfig', + request_serializer=spanner_instance_admin.GetInstanceConfigRequest.serialize, + response_deserializer=spanner_instance_admin.InstanceConfig.deserialize, + ) + return self._stubs['get_instance_config'] + + @property + def create_instance_config(self) -> Callable[ + [spanner_instance_admin.CreateInstanceConfigRequest], + operations_pb2.Operation]: + r"""Return a callable for the create instance config method over gRPC. + + Creates an instance config and begins preparing it to be used. + The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of preparing the new instance config. The instance + config name is assigned by the caller. If the named instance + config already exists, ``CreateInstanceConfig`` returns + ``ALREADY_EXISTS``. + + Immediately after the request returns: + + - The instance config is readable via the API, with all + requested attributes. The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. Its state is ``CREATING``. + + While the operation is pending: + + - Cancelling the operation renders the instance config + immediately unreadable via the API. + - Except for deleting the creating resource, all other attempts + to modify the instance config are rejected. + + Upon completion of the returned operation: + + - Instances can be created using the instance configuration. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. Its state becomes ``READY``. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track creation of the instance config. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.create`` + permission on the resource + [parent][google.spanner.admin.instance.v1.CreateInstanceConfigRequest.parent]. + + Returns: + Callable[[~.CreateInstanceConfigRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'create_instance_config' not in self._stubs: + self._stubs['create_instance_config'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/CreateInstanceConfig', + request_serializer=spanner_instance_admin.CreateInstanceConfigRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['create_instance_config'] + + @property + def update_instance_config(self) -> Callable[ + [spanner_instance_admin.UpdateInstanceConfigRequest], + operations_pb2.Operation]: + r"""Return a callable for the update instance config method over gRPC. + + Updates an instance config. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the instance. If the named instance + config does not exist, returns ``NOT_FOUND``. + + Only user managed configurations can be updated. + + Immediately after the request returns: + + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. + + While the operation is pending: + + - Cancelling the operation sets its metadata's + [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata.cancel_time]. + The operation is guaranteed to succeed at undoing all + changes, after which point it terminates with a ``CANCELLED`` + status. + - All other attempts to modify the instance config are + rejected. + - Reading the instance config via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - Creating instances using the instance configuration uses the + new values. + - The instance config's new values are readable via the API. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track the instance config modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateInstanceConfigMetadata][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.update`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + Returns: + Callable[[~.UpdateInstanceConfigRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'update_instance_config' not in self._stubs: + self._stubs['update_instance_config'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/UpdateInstanceConfig', + request_serializer=spanner_instance_admin.UpdateInstanceConfigRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['update_instance_config'] + + @property + def delete_instance_config(self) -> Callable[ + [spanner_instance_admin.DeleteInstanceConfigRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete instance config method over gRPC. + + Deletes the instance config. Deletion is only allowed when no + instances are using the configuration. If any instances are + using the config, returns ``FAILED_PRECONDITION``. + + Only user managed configurations can be deleted. + + Authorization requires ``spanner.instanceConfigs.delete`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + Returns: + Callable[[~.DeleteInstanceConfigRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'delete_instance_config' not in self._stubs: + self._stubs['delete_instance_config'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/DeleteInstanceConfig', + request_serializer=spanner_instance_admin.DeleteInstanceConfigRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_instance_config'] + + @property + def list_instance_config_operations(self) -> Callable[ + [spanner_instance_admin.ListInstanceConfigOperationsRequest], + spanner_instance_admin.ListInstanceConfigOperationsResponse]: + r"""Return a callable for the list instance config + operations method over gRPC. + + Lists the user-managed instance config [long-running + operations][google.longrunning.Operation] in the given project. + An instance config operation has a name of the form + ``projects//instanceConfigs//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. Operations returned are ordered by + ``operation.metadata.value.start_time`` in descending order + starting from the most recently started operation. + + Returns: + Callable[[~.ListInstanceConfigOperationsRequest], + ~.ListInstanceConfigOperationsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_instance_config_operations' not in self._stubs: + self._stubs['list_instance_config_operations'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/ListInstanceConfigOperations', + request_serializer=spanner_instance_admin.ListInstanceConfigOperationsRequest.serialize, + response_deserializer=spanner_instance_admin.ListInstanceConfigOperationsResponse.deserialize, + ) + return self._stubs['list_instance_config_operations'] + + @property + def list_instances(self) -> Callable[ + [spanner_instance_admin.ListInstancesRequest], + spanner_instance_admin.ListInstancesResponse]: + r"""Return a callable for the list instances method over gRPC. + + Lists all instances in the given project. + + Returns: + Callable[[~.ListInstancesRequest], + ~.ListInstancesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_instances' not in self._stubs: + self._stubs['list_instances'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/ListInstances', + request_serializer=spanner_instance_admin.ListInstancesRequest.serialize, + response_deserializer=spanner_instance_admin.ListInstancesResponse.deserialize, + ) + return self._stubs['list_instances'] + + @property + def get_instance(self) -> Callable[ + [spanner_instance_admin.GetInstanceRequest], + spanner_instance_admin.Instance]: + r"""Return a callable for the get instance method over gRPC. + + Gets information about a particular instance. + + Returns: + Callable[[~.GetInstanceRequest], + ~.Instance]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_instance' not in self._stubs: + self._stubs['get_instance'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/GetInstance', + request_serializer=spanner_instance_admin.GetInstanceRequest.serialize, + response_deserializer=spanner_instance_admin.Instance.deserialize, + ) + return self._stubs['get_instance'] + + @property + def create_instance(self) -> Callable[ + [spanner_instance_admin.CreateInstanceRequest], + operations_pb2.Operation]: + r"""Return a callable for the create instance method over gRPC. + + Creates an instance and begins preparing it to begin serving. + The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of preparing the new instance. The instance name is + assigned by the caller. If the named instance already exists, + ``CreateInstance`` returns ``ALREADY_EXISTS``. + + Immediately upon completion of this request: + + - The instance is readable via the API, with all requested + attributes but no allocated resources. Its state is + ``CREATING``. + + Until completion of the returned operation: + + - Cancelling the operation renders the instance immediately + unreadable via the API. + - The instance can be deleted. + - All other attempts to modify the instance are rejected. + + Upon completion of the returned operation: + + - Billing for all successfully-allocated resources begins (some + types may have lower than the requested levels). + - Databases can be created in the instance. + - The instance's allocated resource levels are readable via the + API. + - The instance's state becomes ``READY``. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and can be + used to track creation of the instance. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateInstanceMetadata][google.spanner.admin.instance.v1.CreateInstanceMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Instance][google.spanner.admin.instance.v1.Instance], if + successful. + + Returns: + Callable[[~.CreateInstanceRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'create_instance' not in self._stubs: + self._stubs['create_instance'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/CreateInstance', + request_serializer=spanner_instance_admin.CreateInstanceRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['create_instance'] + + @property + def update_instance(self) -> Callable[ + [spanner_instance_admin.UpdateInstanceRequest], + operations_pb2.Operation]: + r"""Return a callable for the update instance method over gRPC. + + Updates an instance, and begins allocating or releasing + resources as requested. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the instance. If the named instance + does not exist, returns ``NOT_FOUND``. + + Immediately upon completion of this request: + + - For resource types for which a decrease in the instance's + allocation has been requested, billing is based on the + newly-requested level. + + Until completion of the returned operation: + + - Cancelling the operation sets its metadata's + [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceMetadata.cancel_time], + and begins restoring resources to their pre-request values. + The operation is guaranteed to succeed at undoing all + resource changes, after which point it terminates with a + ``CANCELLED`` status. + - All other attempts to modify the instance are rejected. + - Reading the instance via the API continues to give the + pre-request resource levels. + + Upon completion of the returned operation: + + - Billing begins for all successfully-allocated resources (some + types may have lower than the requested levels). + - All newly-reserved resources are available for serving the + instance's tables. + - The instance's new resource levels are readable via the API. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and can be + used to track the instance modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateInstanceMetadata][google.spanner.admin.instance.v1.UpdateInstanceMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Instance][google.spanner.admin.instance.v1.Instance], if + successful. + + Authorization requires ``spanner.instances.update`` permission + on the resource + [name][google.spanner.admin.instance.v1.Instance.name]. + + Returns: + Callable[[~.UpdateInstanceRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'update_instance' not in self._stubs: + self._stubs['update_instance'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/UpdateInstance', + request_serializer=spanner_instance_admin.UpdateInstanceRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['update_instance'] + + @property + def delete_instance(self) -> Callable[ + [spanner_instance_admin.DeleteInstanceRequest], + empty_pb2.Empty]: + r"""Return a callable for the delete instance method over gRPC. + + Deletes an instance. + + Immediately upon completion of the request: + + - Billing ceases for all of the instance's reserved resources. + + Soon afterward: + + - The instance and *all of its databases* immediately and + irrevocably disappear from the API. All data in the databases + is permanently deleted. + + Returns: + Callable[[~.DeleteInstanceRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'delete_instance' not in self._stubs: + self._stubs['delete_instance'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/DeleteInstance', + request_serializer=spanner_instance_admin.DeleteInstanceRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_instance'] + + @property + def set_iam_policy(self) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + + Sets the access control policy on an instance resource. Replaces + any existing policy. + + Authorization requires ``spanner.instances.setIamPolicy`` on + [resource][google.iam.v1.SetIamPolicyRequest.resource]. + + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'set_iam_policy' not in self._stubs: + self._stubs['set_iam_policy'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/SetIamPolicy', + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs['set_iam_policy'] + + @property + def get_iam_policy(self) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + + Gets the access control policy for an instance resource. Returns + an empty policy if an instance exists but does not have a policy + set. + + Authorization requires ``spanner.instances.getIamPolicy`` on + [resource][google.iam.v1.GetIamPolicyRequest.resource]. + + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_iam_policy' not in self._stubs: + self._stubs['get_iam_policy'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/GetIamPolicy', + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs['get_iam_policy'] + + @property + def test_iam_permissions(self) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse]: + r"""Return a callable for the test iam permissions method over gRPC. + + Returns permissions that the caller has on the specified + instance resource. + + Attempting this RPC on a non-existent Cloud Spanner instance + resource will result in a NOT_FOUND error if the user has + ``spanner.instances.list`` permission on the containing Google + Cloud Project. Otherwise returns an empty set of permissions. + + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'test_iam_permissions' not in self._stubs: + self._stubs['test_iam_permissions'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/TestIamPermissions', + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs['test_iam_permissions'] + + def close(self): + self.grpc_channel.close() + + @property + def kind(self) -> str: + return "grpc" + + +__all__ = ( + 'InstanceAdminGrpcTransport', +) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py new file mode 100644 index 0000000000..dd08641298 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py @@ -0,0 +1,860 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from .base import InstanceAdminTransport, DEFAULT_CLIENT_INFO +from .grpc import InstanceAdminGrpcTransport + + +class InstanceAdminGrpcAsyncIOTransport(InstanceAdminTransport): + """gRPC AsyncIO backend transport for InstanceAdmin. + + Cloud Spanner Instance Admin API + The Cloud Spanner Instance Admin API can be used to create, + delete, modify and list instances. Instances are dedicated Cloud + Spanner serving and storage resources to be used by Cloud + Spanner databases. + Each instance has a "configuration", which dictates where the + serving resources for the Cloud Spanner instance are located + (e.g., US-central, Europe). Configurations are created by Google + based on resource availability. + + Cloud Spanner billing is based on the instances that exist and + their sizes. After an instance exists, there are no additional + per-database or per-operation charges for use of the instance + (though there may be additional network bandwidth charges). + Instances offer isolation: problems with databases in one + instance will not affect other instances. However, within an + instance databases can affect each other. For example, if one + database in an instance receives a lot of requests and consumes + most of the instance resources, fewer resources are available + for other databases in that instance, and their performance may + suffer. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel(cls, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs + ) + + def __init__(self, *, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: Optional[aio.Channel] = None, + api_mtls_endpoint: Optional[str] = None, + client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, + client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsAsyncClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def list_instance_configs(self) -> Callable[ + [spanner_instance_admin.ListInstanceConfigsRequest], + Awaitable[spanner_instance_admin.ListInstanceConfigsResponse]]: + r"""Return a callable for the list instance configs method over gRPC. + + Lists the supported instance configurations for a + given project. + + Returns: + Callable[[~.ListInstanceConfigsRequest], + Awaitable[~.ListInstanceConfigsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_instance_configs' not in self._stubs: + self._stubs['list_instance_configs'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/ListInstanceConfigs', + request_serializer=spanner_instance_admin.ListInstanceConfigsRequest.serialize, + response_deserializer=spanner_instance_admin.ListInstanceConfigsResponse.deserialize, + ) + return self._stubs['list_instance_configs'] + + @property + def get_instance_config(self) -> Callable[ + [spanner_instance_admin.GetInstanceConfigRequest], + Awaitable[spanner_instance_admin.InstanceConfig]]: + r"""Return a callable for the get instance config method over gRPC. + + Gets information about a particular instance + configuration. + + Returns: + Callable[[~.GetInstanceConfigRequest], + Awaitable[~.InstanceConfig]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_instance_config' not in self._stubs: + self._stubs['get_instance_config'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/GetInstanceConfig', + request_serializer=spanner_instance_admin.GetInstanceConfigRequest.serialize, + response_deserializer=spanner_instance_admin.InstanceConfig.deserialize, + ) + return self._stubs['get_instance_config'] + + @property + def create_instance_config(self) -> Callable[ + [spanner_instance_admin.CreateInstanceConfigRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the create instance config method over gRPC. + + Creates an instance config and begins preparing it to be used. + The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of preparing the new instance config. The instance + config name is assigned by the caller. If the named instance + config already exists, ``CreateInstanceConfig`` returns + ``ALREADY_EXISTS``. + + Immediately after the request returns: + + - The instance config is readable via the API, with all + requested attributes. The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. Its state is ``CREATING``. + + While the operation is pending: + + - Cancelling the operation renders the instance config + immediately unreadable via the API. + - Except for deleting the creating resource, all other attempts + to modify the instance config are rejected. + + Upon completion of the returned operation: + + - Instances can be created using the instance configuration. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. Its state becomes ``READY``. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track creation of the instance config. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.create`` + permission on the resource + [parent][google.spanner.admin.instance.v1.CreateInstanceConfigRequest.parent]. + + Returns: + Callable[[~.CreateInstanceConfigRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'create_instance_config' not in self._stubs: + self._stubs['create_instance_config'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/CreateInstanceConfig', + request_serializer=spanner_instance_admin.CreateInstanceConfigRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['create_instance_config'] + + @property + def update_instance_config(self) -> Callable[ + [spanner_instance_admin.UpdateInstanceConfigRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the update instance config method over gRPC. + + Updates an instance config. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the instance. If the named instance + config does not exist, returns ``NOT_FOUND``. + + Only user managed configurations can be updated. + + Immediately after the request returns: + + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field is set to true. + + While the operation is pending: + + - Cancelling the operation sets its metadata's + [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata.cancel_time]. + The operation is guaranteed to succeed at undoing all + changes, after which point it terminates with a ``CANCELLED`` + status. + - All other attempts to modify the instance config are + rejected. + - Reading the instance config via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - Creating instances using the instance configuration uses the + new values. + - The instance config's new values are readable via the API. + - The instance config's + [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and + can be used to track the instance config modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateInstanceConfigMetadata][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata]. + The [response][google.longrunning.Operation.response] field type + is + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], + if successful. + + Authorization requires ``spanner.instanceConfigs.update`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + Returns: + Callable[[~.UpdateInstanceConfigRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'update_instance_config' not in self._stubs: + self._stubs['update_instance_config'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/UpdateInstanceConfig', + request_serializer=spanner_instance_admin.UpdateInstanceConfigRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['update_instance_config'] + + @property + def delete_instance_config(self) -> Callable[ + [spanner_instance_admin.DeleteInstanceConfigRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete instance config method over gRPC. + + Deletes the instance config. Deletion is only allowed when no + instances are using the configuration. If any instances are + using the config, returns ``FAILED_PRECONDITION``. + + Only user managed configurations can be deleted. + + Authorization requires ``spanner.instanceConfigs.delete`` + permission on the resource + [name][google.spanner.admin.instance.v1.InstanceConfig.name]. + + Returns: + Callable[[~.DeleteInstanceConfigRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'delete_instance_config' not in self._stubs: + self._stubs['delete_instance_config'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/DeleteInstanceConfig', + request_serializer=spanner_instance_admin.DeleteInstanceConfigRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_instance_config'] + + @property + def list_instance_config_operations(self) -> Callable[ + [spanner_instance_admin.ListInstanceConfigOperationsRequest], + Awaitable[spanner_instance_admin.ListInstanceConfigOperationsResponse]]: + r"""Return a callable for the list instance config + operations method over gRPC. + + Lists the user-managed instance config [long-running + operations][google.longrunning.Operation] in the given project. + An instance config operation has a name of the form + ``projects//instanceConfigs//operations/``. + The long-running operation + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + Operations returned include those that have + completed/failed/canceled within the last 7 days, and pending + operations. Operations returned are ordered by + ``operation.metadata.value.start_time`` in descending order + starting from the most recently started operation. + + Returns: + Callable[[~.ListInstanceConfigOperationsRequest], + Awaitable[~.ListInstanceConfigOperationsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_instance_config_operations' not in self._stubs: + self._stubs['list_instance_config_operations'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/ListInstanceConfigOperations', + request_serializer=spanner_instance_admin.ListInstanceConfigOperationsRequest.serialize, + response_deserializer=spanner_instance_admin.ListInstanceConfigOperationsResponse.deserialize, + ) + return self._stubs['list_instance_config_operations'] + + @property + def list_instances(self) -> Callable[ + [spanner_instance_admin.ListInstancesRequest], + Awaitable[spanner_instance_admin.ListInstancesResponse]]: + r"""Return a callable for the list instances method over gRPC. + + Lists all instances in the given project. + + Returns: + Callable[[~.ListInstancesRequest], + Awaitable[~.ListInstancesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'list_instances' not in self._stubs: + self._stubs['list_instances'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/ListInstances', + request_serializer=spanner_instance_admin.ListInstancesRequest.serialize, + response_deserializer=spanner_instance_admin.ListInstancesResponse.deserialize, + ) + return self._stubs['list_instances'] + + @property + def get_instance(self) -> Callable[ + [spanner_instance_admin.GetInstanceRequest], + Awaitable[spanner_instance_admin.Instance]]: + r"""Return a callable for the get instance method over gRPC. + + Gets information about a particular instance. + + Returns: + Callable[[~.GetInstanceRequest], + Awaitable[~.Instance]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_instance' not in self._stubs: + self._stubs['get_instance'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/GetInstance', + request_serializer=spanner_instance_admin.GetInstanceRequest.serialize, + response_deserializer=spanner_instance_admin.Instance.deserialize, + ) + return self._stubs['get_instance'] + + @property + def create_instance(self) -> Callable[ + [spanner_instance_admin.CreateInstanceRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the create instance method over gRPC. + + Creates an instance and begins preparing it to begin serving. + The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of preparing the new instance. The instance name is + assigned by the caller. If the named instance already exists, + ``CreateInstance`` returns ``ALREADY_EXISTS``. + + Immediately upon completion of this request: + + - The instance is readable via the API, with all requested + attributes but no allocated resources. Its state is + ``CREATING``. + + Until completion of the returned operation: + + - Cancelling the operation renders the instance immediately + unreadable via the API. + - The instance can be deleted. + - All other attempts to modify the instance are rejected. + + Upon completion of the returned operation: + + - Billing for all successfully-allocated resources begins (some + types may have lower than the requested levels). + - Databases can be created in the instance. + - The instance's allocated resource levels are readable via the + API. + - The instance's state becomes ``READY``. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and can be + used to track creation of the instance. The + [metadata][google.longrunning.Operation.metadata] field type is + [CreateInstanceMetadata][google.spanner.admin.instance.v1.CreateInstanceMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Instance][google.spanner.admin.instance.v1.Instance], if + successful. + + Returns: + Callable[[~.CreateInstanceRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'create_instance' not in self._stubs: + self._stubs['create_instance'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/CreateInstance', + request_serializer=spanner_instance_admin.CreateInstanceRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['create_instance'] + + @property + def update_instance(self) -> Callable[ + [spanner_instance_admin.UpdateInstanceRequest], + Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the update instance method over gRPC. + + Updates an instance, and begins allocating or releasing + resources as requested. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the instance. If the named instance + does not exist, returns ``NOT_FOUND``. + + Immediately upon completion of this request: + + - For resource types for which a decrease in the instance's + allocation has been requested, billing is based on the + newly-requested level. + + Until completion of the returned operation: + + - Cancelling the operation sets its metadata's + [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceMetadata.cancel_time], + and begins restoring resources to their pre-request values. + The operation is guaranteed to succeed at undoing all + resource changes, after which point it terminates with a + ``CANCELLED`` status. + - All other attempts to modify the instance are rejected. + - Reading the instance via the API continues to give the + pre-request resource levels. + + Upon completion of the returned operation: + + - Billing begins for all successfully-allocated resources (some + types may have lower than the requested levels). + - All newly-reserved resources are available for serving the + instance's tables. + - The instance's new resource levels are readable via the API. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format ``/operations/`` and can be + used to track the instance modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateInstanceMetadata][google.spanner.admin.instance.v1.UpdateInstanceMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Instance][google.spanner.admin.instance.v1.Instance], if + successful. + + Authorization requires ``spanner.instances.update`` permission + on the resource + [name][google.spanner.admin.instance.v1.Instance.name]. + + Returns: + Callable[[~.UpdateInstanceRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'update_instance' not in self._stubs: + self._stubs['update_instance'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/UpdateInstance', + request_serializer=spanner_instance_admin.UpdateInstanceRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs['update_instance'] + + @property + def delete_instance(self) -> Callable[ + [spanner_instance_admin.DeleteInstanceRequest], + Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete instance method over gRPC. + + Deletes an instance. + + Immediately upon completion of the request: + + - Billing ceases for all of the instance's reserved resources. + + Soon afterward: + + - The instance and *all of its databases* immediately and + irrevocably disappear from the API. All data in the databases + is permanently deleted. + + Returns: + Callable[[~.DeleteInstanceRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'delete_instance' not in self._stubs: + self._stubs['delete_instance'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/DeleteInstance', + request_serializer=spanner_instance_admin.DeleteInstanceRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs['delete_instance'] + + @property + def set_iam_policy(self) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Awaitable[policy_pb2.Policy]]: + r"""Return a callable for the set iam policy method over gRPC. + + Sets the access control policy on an instance resource. Replaces + any existing policy. + + Authorization requires ``spanner.instances.setIamPolicy`` on + [resource][google.iam.v1.SetIamPolicyRequest.resource]. + + Returns: + Callable[[~.SetIamPolicyRequest], + Awaitable[~.Policy]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'set_iam_policy' not in self._stubs: + self._stubs['set_iam_policy'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/SetIamPolicy', + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs['set_iam_policy'] + + @property + def get_iam_policy(self) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Awaitable[policy_pb2.Policy]]: + r"""Return a callable for the get iam policy method over gRPC. + + Gets the access control policy for an instance resource. Returns + an empty policy if an instance exists but does not have a policy + set. + + Authorization requires ``spanner.instances.getIamPolicy`` on + [resource][google.iam.v1.GetIamPolicyRequest.resource]. + + Returns: + Callable[[~.GetIamPolicyRequest], + Awaitable[~.Policy]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'get_iam_policy' not in self._stubs: + self._stubs['get_iam_policy'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/GetIamPolicy', + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs['get_iam_policy'] + + @property + def test_iam_permissions(self) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Awaitable[iam_policy_pb2.TestIamPermissionsResponse]]: + r"""Return a callable for the test iam permissions method over gRPC. + + Returns permissions that the caller has on the specified + instance resource. + + Attempting this RPC on a non-existent Cloud Spanner instance + resource will result in a NOT_FOUND error if the user has + ``spanner.instances.list`` permission on the containing Google + Cloud Project. Otherwise returns an empty set of permissions. + + Returns: + Callable[[~.TestIamPermissionsRequest], + Awaitable[~.TestIamPermissionsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if 'test_iam_permissions' not in self._stubs: + self._stubs['test_iam_permissions'] = self.grpc_channel.unary_unary( + '/google.spanner.admin.instance.v1.InstanceAdmin/TestIamPermissions', + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs['test_iam_permissions'] + + def close(self): + return self.grpc_channel.close() + + +__all__ = ( + 'InstanceAdminGrpcAsyncIOTransport', +) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest.py new file mode 100644 index 0000000000..689055a758 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest.py @@ -0,0 +1,2003 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from google.auth.transport.requests import AuthorizedSession # type: ignore +import json # type: ignore +import grpc # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.api_core import exceptions as core_exceptions +from google.api_core import retry as retries +from google.api_core import rest_helpers +from google.api_core import rest_streaming +from google.api_core import path_template +from google.api_core import gapic_v1 + +from google.protobuf import json_format +from google.api_core import operations_v1 +from requests import __version__ as requests_version +import dataclasses +import re +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +import warnings + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + + +from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore + +from .base import InstanceAdminTransport, DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO + + +DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, + grpc_version=None, + rest_version=requests_version, +) + + +class InstanceAdminRestInterceptor: + """Interceptor for InstanceAdmin. + + Interceptors are used to manipulate requests, request metadata, and responses + in arbitrary ways. + Example use cases include: + * Logging + * Verifying requests according to service or custom semantics + * Stripping extraneous information from responses + + These use cases and more can be enabled by injecting an + instance of a custom subclass when constructing the InstanceAdminRestTransport. + + .. code-block:: python + class MyCustomInstanceAdminInterceptor(InstanceAdminRestInterceptor): + def pre_create_instance(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_create_instance(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_create_instance_config(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_create_instance_config(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_delete_instance(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def pre_delete_instance_config(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def pre_get_iam_policy(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_iam_policy(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_get_instance(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_instance(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_get_instance_config(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_instance_config(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_list_instance_config_operations(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_instance_config_operations(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_list_instance_configs(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_instance_configs(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_list_instances(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_instances(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_set_iam_policy(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_set_iam_policy(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_test_iam_permissions(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_test_iam_permissions(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_update_instance(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_update_instance(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_update_instance_config(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_update_instance_config(self, response): + logging.log(f"Received response: {response}") + return response + + transport = InstanceAdminRestTransport(interceptor=MyCustomInstanceAdminInterceptor()) + client = InstanceAdminClient(transport=transport) + + + """ + def pre_create_instance(self, request: spanner_instance_admin.CreateInstanceRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.CreateInstanceRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for create_instance + + Override in a subclass to manipulate the request or metadata + before they are sent to the InstanceAdmin server. + """ + return request, metadata + + def post_create_instance(self, response: operations_pb2.Operation) -> operations_pb2.Operation: + """Post-rpc interceptor for create_instance + + Override in a subclass to manipulate the response + after it is returned by the InstanceAdmin server but before + it is returned to user code. + """ + return response + def pre_create_instance_config(self, request: spanner_instance_admin.CreateInstanceConfigRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.CreateInstanceConfigRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for create_instance_config + + Override in a subclass to manipulate the request or metadata + before they are sent to the InstanceAdmin server. + """ + return request, metadata + + def post_create_instance_config(self, response: operations_pb2.Operation) -> operations_pb2.Operation: + """Post-rpc interceptor for create_instance_config + + Override in a subclass to manipulate the response + after it is returned by the InstanceAdmin server but before + it is returned to user code. + """ + return response + def pre_delete_instance(self, request: spanner_instance_admin.DeleteInstanceRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.DeleteInstanceRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for delete_instance + + Override in a subclass to manipulate the request or metadata + before they are sent to the InstanceAdmin server. + """ + return request, metadata + + def pre_delete_instance_config(self, request: spanner_instance_admin.DeleteInstanceConfigRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.DeleteInstanceConfigRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for delete_instance_config + + Override in a subclass to manipulate the request or metadata + before they are sent to the InstanceAdmin server. + """ + return request, metadata + + def pre_get_iam_policy(self, request: iam_policy_pb2.GetIamPolicyRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for get_iam_policy + + Override in a subclass to manipulate the request or metadata + before they are sent to the InstanceAdmin server. + """ + return request, metadata + + def post_get_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: + """Post-rpc interceptor for get_iam_policy + + Override in a subclass to manipulate the response + after it is returned by the InstanceAdmin server but before + it is returned to user code. + """ + return response + def pre_get_instance(self, request: spanner_instance_admin.GetInstanceRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.GetInstanceRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for get_instance + + Override in a subclass to manipulate the request or metadata + before they are sent to the InstanceAdmin server. + """ + return request, metadata + + def post_get_instance(self, response: spanner_instance_admin.Instance) -> spanner_instance_admin.Instance: + """Post-rpc interceptor for get_instance + + Override in a subclass to manipulate the response + after it is returned by the InstanceAdmin server but before + it is returned to user code. + """ + return response + def pre_get_instance_config(self, request: spanner_instance_admin.GetInstanceConfigRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.GetInstanceConfigRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for get_instance_config + + Override in a subclass to manipulate the request or metadata + before they are sent to the InstanceAdmin server. + """ + return request, metadata + + def post_get_instance_config(self, response: spanner_instance_admin.InstanceConfig) -> spanner_instance_admin.InstanceConfig: + """Post-rpc interceptor for get_instance_config + + Override in a subclass to manipulate the response + after it is returned by the InstanceAdmin server but before + it is returned to user code. + """ + return response + def pre_list_instance_config_operations(self, request: spanner_instance_admin.ListInstanceConfigOperationsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.ListInstanceConfigOperationsRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for list_instance_config_operations + + Override in a subclass to manipulate the request or metadata + before they are sent to the InstanceAdmin server. + """ + return request, metadata + + def post_list_instance_config_operations(self, response: spanner_instance_admin.ListInstanceConfigOperationsResponse) -> spanner_instance_admin.ListInstanceConfigOperationsResponse: + """Post-rpc interceptor for list_instance_config_operations + + Override in a subclass to manipulate the response + after it is returned by the InstanceAdmin server but before + it is returned to user code. + """ + return response + def pre_list_instance_configs(self, request: spanner_instance_admin.ListInstanceConfigsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.ListInstanceConfigsRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for list_instance_configs + + Override in a subclass to manipulate the request or metadata + before they are sent to the InstanceAdmin server. + """ + return request, metadata + + def post_list_instance_configs(self, response: spanner_instance_admin.ListInstanceConfigsResponse) -> spanner_instance_admin.ListInstanceConfigsResponse: + """Post-rpc interceptor for list_instance_configs + + Override in a subclass to manipulate the response + after it is returned by the InstanceAdmin server but before + it is returned to user code. + """ + return response + def pre_list_instances(self, request: spanner_instance_admin.ListInstancesRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.ListInstancesRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for list_instances + + Override in a subclass to manipulate the request or metadata + before they are sent to the InstanceAdmin server. + """ + return request, metadata + + def post_list_instances(self, response: spanner_instance_admin.ListInstancesResponse) -> spanner_instance_admin.ListInstancesResponse: + """Post-rpc interceptor for list_instances + + Override in a subclass to manipulate the response + after it is returned by the InstanceAdmin server but before + it is returned to user code. + """ + return response + def pre_set_iam_policy(self, request: iam_policy_pb2.SetIamPolicyRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for set_iam_policy + + Override in a subclass to manipulate the request or metadata + before they are sent to the InstanceAdmin server. + """ + return request, metadata + + def post_set_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: + """Post-rpc interceptor for set_iam_policy + + Override in a subclass to manipulate the response + after it is returned by the InstanceAdmin server but before + it is returned to user code. + """ + return response + def pre_test_iam_permissions(self, request: iam_policy_pb2.TestIamPermissionsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[iam_policy_pb2.TestIamPermissionsRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for test_iam_permissions + + Override in a subclass to manipulate the request or metadata + before they are sent to the InstanceAdmin server. + """ + return request, metadata + + def post_test_iam_permissions(self, response: iam_policy_pb2.TestIamPermissionsResponse) -> iam_policy_pb2.TestIamPermissionsResponse: + """Post-rpc interceptor for test_iam_permissions + + Override in a subclass to manipulate the response + after it is returned by the InstanceAdmin server but before + it is returned to user code. + """ + return response + def pre_update_instance(self, request: spanner_instance_admin.UpdateInstanceRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.UpdateInstanceRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for update_instance + + Override in a subclass to manipulate the request or metadata + before they are sent to the InstanceAdmin server. + """ + return request, metadata + + def post_update_instance(self, response: operations_pb2.Operation) -> operations_pb2.Operation: + """Post-rpc interceptor for update_instance + + Override in a subclass to manipulate the response + after it is returned by the InstanceAdmin server but before + it is returned to user code. + """ + return response + def pre_update_instance_config(self, request: spanner_instance_admin.UpdateInstanceConfigRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.UpdateInstanceConfigRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for update_instance_config + + Override in a subclass to manipulate the request or metadata + before they are sent to the InstanceAdmin server. + """ + return request, metadata + + def post_update_instance_config(self, response: operations_pb2.Operation) -> operations_pb2.Operation: + """Post-rpc interceptor for update_instance_config + + Override in a subclass to manipulate the response + after it is returned by the InstanceAdmin server but before + it is returned to user code. + """ + return response + + +@dataclasses.dataclass +class InstanceAdminRestStub: + _session: AuthorizedSession + _host: str + _interceptor: InstanceAdminRestInterceptor + + +class InstanceAdminRestTransport(InstanceAdminTransport): + """REST backend transport for InstanceAdmin. + + Cloud Spanner Instance Admin API + The Cloud Spanner Instance Admin API can be used to create, + delete, modify and list instances. Instances are dedicated Cloud + Spanner serving and storage resources to be used by Cloud + Spanner databases. + Each instance has a "configuration", which dictates where the + serving resources for the Cloud Spanner instance are located + (e.g., US-central, Europe). Configurations are created by Google + based on resource availability. + + Cloud Spanner billing is based on the instances that exist and + their sizes. After an instance exists, there are no additional + per-database or per-operation charges for use of the instance + (though there may be additional network bandwidth charges). + Instances offer isolation: problems with databases in one + instance will not affect other instances. However, within an + instance databases can affect each other. For example, if one + database in an instance receives a lot of requests and consumes + most of the instance resources, fewer resources are available + for other databases in that instance, and their performance may + suffer. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends JSON representations of protocol buffers over HTTP/1.1 + + """ + + def __init__(self, *, + host: str = 'spanner.googleapis.com', + credentials: Optional[ga_credentials.Credentials] = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + client_cert_source_for_mtls: Optional[Callable[[ + ], Tuple[bytes, bytes]]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = 'https', + interceptor: Optional[InstanceAdminRestInterceptor] = None, + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client + certificate to configure mutual TLS HTTP channel. It is ignored + if ``channel`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you are developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + url_scheme: the protocol scheme for the API endpoint. Normally + "https", but for testing or local servers, + "http" can be specified. + """ + # Run the base constructor + # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. + # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the + # credentials object + maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) + if maybe_url_match is None: + raise ValueError(f"Unexpected hostname structure: {host}") # pragma: NO COVER + + url_match_items = maybe_url_match.groupdict() + + host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host + + super().__init__( + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience + ) + self._session = AuthorizedSession( + self._credentials, default_host=self.DEFAULT_HOST) + self._operations_client: Optional[operations_v1.AbstractOperationsClient] = None + if client_cert_source_for_mtls: + self._session.configure_mtls_channel(client_cert_source_for_mtls) + self._interceptor = interceptor or InstanceAdminRestInterceptor() + self._prep_wrapped_messages(client_info) + + @property + def operations_client(self) -> operations_v1.AbstractOperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Only create a new client if we do not already have one. + if self._operations_client is None: + http_options: Dict[str, List[Dict[str, str]]] = { + 'google.longrunning.Operations.GetOperation': [ + { + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}', + }, + { + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/operations/*}', + }, + ], + 'google.longrunning.Operations.ListOperations': [ + { + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations}', + }, + { + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*/operations}', + }, + ], + 'google.longrunning.Operations.CancelOperation': [ + { + 'method': 'post', + 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}:cancel', + }, + { + 'method': 'post', + 'uri': '/v1/{name=projects/*/instances/*/operations/*}:cancel', + }, + ], + 'google.longrunning.Operations.DeleteOperation': [ + { + 'method': 'delete', + 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}', + }, + { + 'method': 'delete', + 'uri': '/v1/{name=projects/*/instances/*/operations/*}', + }, + ], + } + + rest_transport = operations_v1.OperationsRestTransport( + host=self._host, + # use the credentials which are saved + credentials=self._credentials, + scopes=self._scopes, + http_options=http_options, + path_prefix="v1") + + self._operations_client = operations_v1.AbstractOperationsClient(transport=rest_transport) + + # Return the client from cache. + return self._operations_client + + class _CreateInstance(InstanceAdminRestStub): + def __hash__(self): + return hash("CreateInstance") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_instance_admin.CreateInstanceRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> operations_pb2.Operation: + r"""Call the create instance method over HTTP. + + Args: + request (~.spanner_instance_admin.CreateInstanceRequest): + The request object. The request for + [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{parent=projects/*}/instances', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_create_instance(request, metadata) + pb_request = spanner_instance_admin.CreateInstanceRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_instance(resp) + return resp + + class _CreateInstanceConfig(InstanceAdminRestStub): + def __hash__(self): + return hash("CreateInstanceConfig") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_instance_admin.CreateInstanceConfigRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> operations_pb2.Operation: + r"""Call the create instance config method over HTTP. + + Args: + request (~.spanner_instance_admin.CreateInstanceConfigRequest): + The request object. The request for + [CreateInstanceConfigRequest][InstanceAdmin.CreateInstanceConfigRequest]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{parent=projects/*}/instanceConfigs', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_create_instance_config(request, metadata) + pb_request = spanner_instance_admin.CreateInstanceConfigRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_create_instance_config(resp) + return resp + + class _DeleteInstance(InstanceAdminRestStub): + def __hash__(self): + return hash("DeleteInstance") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_instance_admin.DeleteInstanceRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ): + r"""Call the delete instance method over HTTP. + + Args: + request (~.spanner_instance_admin.DeleteInstanceRequest): + The request object. The request for + [DeleteInstance][google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'delete', + 'uri': '/v1/{name=projects/*/instances/*}', + }, + ] + request, metadata = self._interceptor.pre_delete_instance(request, metadata) + pb_request = spanner_instance_admin.DeleteInstanceRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + class _DeleteInstanceConfig(InstanceAdminRestStub): + def __hash__(self): + return hash("DeleteInstanceConfig") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_instance_admin.DeleteInstanceConfigRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ): + r"""Call the delete instance config method over HTTP. + + Args: + request (~.spanner_instance_admin.DeleteInstanceConfigRequest): + The request object. The request for + [DeleteInstanceConfigRequest][InstanceAdmin.DeleteInstanceConfigRequest]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'delete', + 'uri': '/v1/{name=projects/*/instanceConfigs/*}', + }, + ] + request, metadata = self._interceptor.pre_delete_instance_config(request, metadata) + pb_request = spanner_instance_admin.DeleteInstanceConfigRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + class _GetIamPolicy(InstanceAdminRestStub): + def __hash__(self): + return hash("GetIamPolicy") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: iam_policy_pb2.GetIamPolicyRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> policy_pb2.Policy: + r"""Call the get iam policy method over HTTP. + + Args: + request (~.iam_policy_pb2.GetIamPolicyRequest): + The request object. Request message for ``GetIamPolicy`` method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.policy_pb2.Policy: + An Identity and Access Management (IAM) policy, which + specifies access controls for Google Cloud resources. + + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members``, or + principals, to a single ``role``. Principals can be user + accounts, service accounts, Google groups, and domains + (such as G Suite). A ``role`` is a named list of + permissions; each ``role`` can be an IAM predefined role + or a user-created custom role. + + For some types of Google Cloud resources, a ``binding`` + can also specify a ``condition``, which is a logical + expression that allows access to a resource only if the + expression evaluates to ``true``. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the `IAM + documentation `__. + + **JSON example:** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": [ + "user:eve@example.com" + ], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ], + "etag": "BwWWja0YfJA=", + "version": 3 + } + + **YAML example:** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + etag: BwWWja0YfJA= + version: 3 + + For a description of IAM and its features, see the `IAM + documentation `__. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{resource=projects/*/instances/*}:getIamPolicy', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_get_iam_policy(request, metadata) + pb_request = request + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = policy_pb2.Policy() + pb_resp = resp + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_iam_policy(resp) + return resp + + class _GetInstance(InstanceAdminRestStub): + def __hash__(self): + return hash("GetInstance") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_instance_admin.GetInstanceRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner_instance_admin.Instance: + r"""Call the get instance method over HTTP. + + Args: + request (~.spanner_instance_admin.GetInstanceRequest): + The request object. The request for + [GetInstance][google.spanner.admin.instance.v1.InstanceAdmin.GetInstance]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner_instance_admin.Instance: + An isolated set of Cloud Spanner + resources on which databases can be + hosted. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{name=projects/*/instances/*}', + }, + ] + request, metadata = self._interceptor.pre_get_instance(request, metadata) + pb_request = spanner_instance_admin.GetInstanceRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner_instance_admin.Instance() + pb_resp = spanner_instance_admin.Instance.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_instance(resp) + return resp + + class _GetInstanceConfig(InstanceAdminRestStub): + def __hash__(self): + return hash("GetInstanceConfig") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_instance_admin.GetInstanceConfigRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner_instance_admin.InstanceConfig: + r"""Call the get instance config method over HTTP. + + Args: + request (~.spanner_instance_admin.GetInstanceConfigRequest): + The request object. The request for + [GetInstanceConfigRequest][google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner_instance_admin.InstanceConfig: + A possible configuration for a Cloud + Spanner instance. Configurations define + the geographic placement of nodes and + their replication. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{name=projects/*/instanceConfigs/*}', + }, + ] + request, metadata = self._interceptor.pre_get_instance_config(request, metadata) + pb_request = spanner_instance_admin.GetInstanceConfigRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner_instance_admin.InstanceConfig() + pb_resp = spanner_instance_admin.InstanceConfig.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_get_instance_config(resp) + return resp + + class _ListInstanceConfigOperations(InstanceAdminRestStub): + def __hash__(self): + return hash("ListInstanceConfigOperations") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_instance_admin.ListInstanceConfigOperationsRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner_instance_admin.ListInstanceConfigOperationsResponse: + r"""Call the list instance config + operations method over HTTP. + + Args: + request (~.spanner_instance_admin.ListInstanceConfigOperationsRequest): + The request object. The request for + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner_instance_admin.ListInstanceConfigOperationsResponse: + The response for + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{parent=projects/*}/instanceConfigOperations', + }, + ] + request, metadata = self._interceptor.pre_list_instance_config_operations(request, metadata) + pb_request = spanner_instance_admin.ListInstanceConfigOperationsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner_instance_admin.ListInstanceConfigOperationsResponse() + pb_resp = spanner_instance_admin.ListInstanceConfigOperationsResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_instance_config_operations(resp) + return resp + + class _ListInstanceConfigs(InstanceAdminRestStub): + def __hash__(self): + return hash("ListInstanceConfigs") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_instance_admin.ListInstanceConfigsRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner_instance_admin.ListInstanceConfigsResponse: + r"""Call the list instance configs method over HTTP. + + Args: + request (~.spanner_instance_admin.ListInstanceConfigsRequest): + The request object. The request for + [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner_instance_admin.ListInstanceConfigsResponse: + The response for + [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{parent=projects/*}/instanceConfigs', + }, + ] + request, metadata = self._interceptor.pre_list_instance_configs(request, metadata) + pb_request = spanner_instance_admin.ListInstanceConfigsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner_instance_admin.ListInstanceConfigsResponse() + pb_resp = spanner_instance_admin.ListInstanceConfigsResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_instance_configs(resp) + return resp + + class _ListInstances(InstanceAdminRestStub): + def __hash__(self): + return hash("ListInstances") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_instance_admin.ListInstancesRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> spanner_instance_admin.ListInstancesResponse: + r"""Call the list instances method over HTTP. + + Args: + request (~.spanner_instance_admin.ListInstancesRequest): + The request object. The request for + [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.spanner_instance_admin.ListInstancesResponse: + The response for + [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'get', + 'uri': '/v1/{parent=projects/*}/instances', + }, + ] + request, metadata = self._interceptor.pre_list_instances(request, metadata) + pb_request = spanner_instance_admin.ListInstancesRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = spanner_instance_admin.ListInstancesResponse() + pb_resp = spanner_instance_admin.ListInstancesResponse.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_list_instances(resp) + return resp + + class _SetIamPolicy(InstanceAdminRestStub): + def __hash__(self): + return hash("SetIamPolicy") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: iam_policy_pb2.SetIamPolicyRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> policy_pb2.Policy: + r"""Call the set iam policy method over HTTP. + + Args: + request (~.iam_policy_pb2.SetIamPolicyRequest): + The request object. Request message for ``SetIamPolicy`` method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.policy_pb2.Policy: + An Identity and Access Management (IAM) policy, which + specifies access controls for Google Cloud resources. + + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members``, or + principals, to a single ``role``. Principals can be user + accounts, service accounts, Google groups, and domains + (such as G Suite). A ``role`` is a named list of + permissions; each ``role`` can be an IAM predefined role + or a user-created custom role. + + For some types of Google Cloud resources, a ``binding`` + can also specify a ``condition``, which is a logical + expression that allows access to a resource only if the + expression evaluates to ``true``. A condition can add + constraints based on attributes of the request, the + resource, or both. To learn which resources support + conditions in their IAM policies, see the `IAM + documentation `__. + + **JSON example:** + + :: + + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": [ + "user:eve@example.com" + ], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ], + "etag": "BwWWja0YfJA=", + "version": 3 + } + + **YAML example:** + + :: + + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + etag: BwWWja0YfJA= + version: 3 + + For a description of IAM and its features, see the `IAM + documentation `__. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{resource=projects/*/instances/*}:setIamPolicy', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_set_iam_policy(request, metadata) + pb_request = request + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = policy_pb2.Policy() + pb_resp = resp + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_set_iam_policy(resp) + return resp + + class _TestIamPermissions(InstanceAdminRestStub): + def __hash__(self): + return hash("TestIamPermissions") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: iam_policy_pb2.TestIamPermissionsRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Call the test iam permissions method over HTTP. + + Args: + request (~.iam_policy_pb2.TestIamPermissionsRequest): + The request object. Request message for ``TestIamPermissions`` method. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'post', + 'uri': '/v1/{resource=projects/*/instances/*}:testIamPermissions', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_test_iam_permissions(request, metadata) + pb_request = request + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = iam_policy_pb2.TestIamPermissionsResponse() + pb_resp = resp + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + resp = self._interceptor.post_test_iam_permissions(resp) + return resp + + class _UpdateInstance(InstanceAdminRestStub): + def __hash__(self): + return hash("UpdateInstance") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_instance_admin.UpdateInstanceRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> operations_pb2.Operation: + r"""Call the update instance method over HTTP. + + Args: + request (~.spanner_instance_admin.UpdateInstanceRequest): + The request object. The request for + [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'patch', + 'uri': '/v1/{instance.name=projects/*/instances/*}', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_update_instance(request, metadata) + pb_request = spanner_instance_admin.UpdateInstanceRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_instance(resp) + return resp + + class _UpdateInstanceConfig(InstanceAdminRestStub): + def __hash__(self): + return hash("UpdateInstanceConfig") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} + + def __call__(self, + request: spanner_instance_admin.UpdateInstanceConfigRequest, *, + retry: OptionalRetry=gapic_v1.method.DEFAULT, + timeout: Optional[float]=None, + metadata: Sequence[Tuple[str, str]]=(), + ) -> operations_pb2.Operation: + r"""Call the update instance config method over HTTP. + + Args: + request (~.spanner_instance_admin.UpdateInstanceConfigRequest): + The request object. The request for + [UpdateInstanceConfigRequest][InstanceAdmin.UpdateInstanceConfigRequest]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options: List[Dict[str, str]] = [{ + 'method': 'patch', + 'uri': '/v1/{instance_config.name=projects/*/instanceConfigs/*}', + 'body': '*', + }, + ] + request, metadata = self._interceptor.pre_update_instance_config(request, metadata) + pb_request = spanner_instance_admin.UpdateInstanceConfigRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request['body'], + including_default_value_fields=False, + use_integers_for_enums=True + ) + uri = transcoded_request['uri'] + method = transcoded_request['method'] + + # Jsonify the query params + query_params = json.loads(json_format.MessageToJson( + transcoded_request['query_params'], + including_default_value_fields=False, + use_integers_for_enums=True, + )) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers['Content-Type'] = 'application/json' + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_instance_config(resp) + return resp + + @property + def create_instance(self) -> Callable[ + [spanner_instance_admin.CreateInstanceRequest], + operations_pb2.Operation]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._CreateInstance(self._session, self._host, self._interceptor) # type: ignore + + @property + def create_instance_config(self) -> Callable[ + [spanner_instance_admin.CreateInstanceConfigRequest], + operations_pb2.Operation]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._CreateInstanceConfig(self._session, self._host, self._interceptor) # type: ignore + + @property + def delete_instance(self) -> Callable[ + [spanner_instance_admin.DeleteInstanceRequest], + empty_pb2.Empty]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._DeleteInstance(self._session, self._host, self._interceptor) # type: ignore + + @property + def delete_instance_config(self) -> Callable[ + [spanner_instance_admin.DeleteInstanceConfigRequest], + empty_pb2.Empty]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._DeleteInstanceConfig(self._session, self._host, self._interceptor) # type: ignore + + @property + def get_iam_policy(self) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + policy_pb2.Policy]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetIamPolicy(self._session, self._host, self._interceptor) # type: ignore + + @property + def get_instance(self) -> Callable[ + [spanner_instance_admin.GetInstanceRequest], + spanner_instance_admin.Instance]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetInstance(self._session, self._host, self._interceptor) # type: ignore + + @property + def get_instance_config(self) -> Callable[ + [spanner_instance_admin.GetInstanceConfigRequest], + spanner_instance_admin.InstanceConfig]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetInstanceConfig(self._session, self._host, self._interceptor) # type: ignore + + @property + def list_instance_config_operations(self) -> Callable[ + [spanner_instance_admin.ListInstanceConfigOperationsRequest], + spanner_instance_admin.ListInstanceConfigOperationsResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListInstanceConfigOperations(self._session, self._host, self._interceptor) # type: ignore + + @property + def list_instance_configs(self) -> Callable[ + [spanner_instance_admin.ListInstanceConfigsRequest], + spanner_instance_admin.ListInstanceConfigsResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListInstanceConfigs(self._session, self._host, self._interceptor) # type: ignore + + @property + def list_instances(self) -> Callable[ + [spanner_instance_admin.ListInstancesRequest], + spanner_instance_admin.ListInstancesResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListInstances(self._session, self._host, self._interceptor) # type: ignore + + @property + def set_iam_policy(self) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + policy_pb2.Policy]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._SetIamPolicy(self._session, self._host, self._interceptor) # type: ignore + + @property + def test_iam_permissions(self) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._TestIamPermissions(self._session, self._host, self._interceptor) # type: ignore + + @property + def update_instance(self) -> Callable[ + [spanner_instance_admin.UpdateInstanceRequest], + operations_pb2.Operation]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._UpdateInstance(self._session, self._host, self._interceptor) # type: ignore + + @property + def update_instance_config(self) -> Callable[ + [spanner_instance_admin.UpdateInstanceConfigRequest], + operations_pb2.Operation]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._UpdateInstanceConfig(self._session, self._host, self._interceptor) # type: ignore + + @property + def kind(self) -> str: + return "rest" + + def close(self): + self._session.close() + + +__all__=( + 'InstanceAdminRestTransport', +) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/__init__.py new file mode 100644 index 0000000000..5631a2a2ca --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/__init__.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .common import ( + OperationProgress, +) +from .spanner_instance_admin import ( + CreateInstanceConfigMetadata, + CreateInstanceConfigRequest, + CreateInstanceMetadata, + CreateInstanceRequest, + DeleteInstanceConfigRequest, + DeleteInstanceRequest, + GetInstanceConfigRequest, + GetInstanceRequest, + Instance, + InstanceConfig, + ListInstanceConfigOperationsRequest, + ListInstanceConfigOperationsResponse, + ListInstanceConfigsRequest, + ListInstanceConfigsResponse, + ListInstancesRequest, + ListInstancesResponse, + ReplicaInfo, + UpdateInstanceConfigMetadata, + UpdateInstanceConfigRequest, + UpdateInstanceMetadata, + UpdateInstanceRequest, +) + +__all__ = ( + 'OperationProgress', + 'CreateInstanceConfigMetadata', + 'CreateInstanceConfigRequest', + 'CreateInstanceMetadata', + 'CreateInstanceRequest', + 'DeleteInstanceConfigRequest', + 'DeleteInstanceRequest', + 'GetInstanceConfigRequest', + 'GetInstanceRequest', + 'Instance', + 'InstanceConfig', + 'ListInstanceConfigOperationsRequest', + 'ListInstanceConfigOperationsResponse', + 'ListInstanceConfigsRequest', + 'ListInstanceConfigsResponse', + 'ListInstancesRequest', + 'ListInstancesResponse', + 'ReplicaInfo', + 'UpdateInstanceConfigMetadata', + 'UpdateInstanceConfigRequest', + 'UpdateInstanceMetadata', + 'UpdateInstanceRequest', +) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/common.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/common.py new file mode 100644 index 0000000000..d354cfffea --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/common.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.spanner.admin.instance.v1', + manifest={ + 'OperationProgress', + }, +) + + +class OperationProgress(proto.Message): + r"""Encapsulates progress related information for a Cloud Spanner + long running instance operations. + + Attributes: + progress_percent (int): + Percent completion of the operation. + Values are between 0 and 100 inclusive. + start_time (google.protobuf.timestamp_pb2.Timestamp): + Time the request was received. + end_time (google.protobuf.timestamp_pb2.Timestamp): + If set, the time at which this operation + failed or was completed successfully. + """ + + progress_percent: int = proto.Field( + proto.INT32, + number=1, + ) + start_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + end_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py new file mode 100644 index 0000000000..55e620e172 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py @@ -0,0 +1,1128 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.cloud.spanner_admin_instance_v1.types import common +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package='google.spanner.admin.instance.v1', + manifest={ + 'ReplicaInfo', + 'InstanceConfig', + 'Instance', + 'ListInstanceConfigsRequest', + 'ListInstanceConfigsResponse', + 'GetInstanceConfigRequest', + 'CreateInstanceConfigRequest', + 'UpdateInstanceConfigRequest', + 'DeleteInstanceConfigRequest', + 'ListInstanceConfigOperationsRequest', + 'ListInstanceConfigOperationsResponse', + 'GetInstanceRequest', + 'CreateInstanceRequest', + 'ListInstancesRequest', + 'ListInstancesResponse', + 'UpdateInstanceRequest', + 'DeleteInstanceRequest', + 'CreateInstanceMetadata', + 'UpdateInstanceMetadata', + 'CreateInstanceConfigMetadata', + 'UpdateInstanceConfigMetadata', + }, +) + + +class ReplicaInfo(proto.Message): + r""" + + Attributes: + location (str): + The location of the serving resources, e.g. + "us-central1". + type_ (google.cloud.spanner_admin_instance_v1.types.ReplicaInfo.ReplicaType): + The type of replica. + default_leader_location (bool): + If true, this location is designated as the default leader + location where leader replicas are placed. See the `region + types + documentation `__ + for more details. + """ + class ReplicaType(proto.Enum): + r"""Indicates the type of replica. See the `replica types + documentation `__ + for more details. + + Values: + TYPE_UNSPECIFIED (0): + Not specified. + READ_WRITE (1): + Read-write replicas support both reads and writes. These + replicas: + + - Maintain a full copy of your data. + - Serve reads. + - Can vote whether to commit a write. + - Participate in leadership election. + - Are eligible to become a leader. + READ_ONLY (2): + Read-only replicas only support reads (not writes). + Read-only replicas: + + - Maintain a full copy of your data. + - Serve reads. + - Do not participate in voting to commit writes. + - Are not eligible to become a leader. + WITNESS (3): + Witness replicas don't support reads but do participate in + voting to commit writes. Witness replicas: + + - Do not maintain a full copy of data. + - Do not serve reads. + - Vote whether to commit writes. + - Participate in leader election but are not eligible to + become leader. + """ + TYPE_UNSPECIFIED = 0 + READ_WRITE = 1 + READ_ONLY = 2 + WITNESS = 3 + + location: str = proto.Field( + proto.STRING, + number=1, + ) + type_: ReplicaType = proto.Field( + proto.ENUM, + number=2, + enum=ReplicaType, + ) + default_leader_location: bool = proto.Field( + proto.BOOL, + number=3, + ) + + +class InstanceConfig(proto.Message): + r"""A possible configuration for a Cloud Spanner instance. + Configurations define the geographic placement of nodes and + their replication. + + Attributes: + name (str): + A unique identifier for the instance configuration. Values + are of the form + ``projects//instanceConfigs/[a-z][-a-z0-9]*``. + display_name (str): + The name of this instance configuration as it + appears in UIs. + config_type (google.cloud.spanner_admin_instance_v1.types.InstanceConfig.Type): + Output only. Whether this instance config is + a Google or User Managed Configuration. + replicas (MutableSequence[google.cloud.spanner_admin_instance_v1.types.ReplicaInfo]): + The geographic placement of nodes in this + instance configuration and their replication + properties. + optional_replicas (MutableSequence[google.cloud.spanner_admin_instance_v1.types.ReplicaInfo]): + Output only. The available optional replicas + to choose from for user managed configurations. + Populated for Google managed configurations. + base_config (str): + Base configuration name, e.g. + projects//instanceConfigs/nam3, based on which + this configuration is created. Only set for user managed + configurations. ``base_config`` must refer to a + configuration of type GOOGLE_MANAGED in the same project as + this configuration. + labels (MutableMapping[str, str]): + Cloud Labels are a flexible and lightweight mechanism for + organizing cloud resources into groups that reflect a + customer's organizational needs and deployment strategies. + Cloud Labels can be used to filter collections of resources. + They can be used to control how resource metrics are + aggregated. And they can be used as arguments to policy + management rules (e.g. route, firewall, load balancing, + etc.). + + - Label keys must be between 1 and 63 characters long and + must conform to the following regular expression: + ``[a-z][a-z0-9_-]{0,62}``. + - Label values must be between 0 and 63 characters long and + must conform to the regular expression + ``[a-z0-9_-]{0,63}``. + - No more than 64 labels can be associated with a given + resource. + + See https://goo.gl/xmQnxf for more information on and + examples of labels. + + If you plan to use labels in your own code, please note that + additional characters may be allowed in the future. + Therefore, you are advised to use an internal label + representation, such as JSON, which doesn't rely upon + specific characters being disallowed. For example, + representing labels as the string: name + "*" + value would + prove problematic if we were to allow "*" in a future + release. + etag (str): + etag is used for optimistic concurrency + control as a way to help prevent simultaneous + updates of a instance config from overwriting + each other. It is strongly suggested that + systems make use of the etag in the + read-modify-write cycle to perform instance + config updates in order to avoid race + conditions: An etag is returned in the response + which contains instance configs, and systems are + expected to put that etag in the request to + update instance config to ensure that their + change will be applied to the same version of + the instance config. + If no etag is provided in the call to update + instance config, then the existing instance + config is overwritten blindly. + leader_options (MutableSequence[str]): + Allowed values of the "default_leader" schema option for + databases in instances that use this instance configuration. + reconciling (bool): + Output only. If true, the instance config is + being created or updated. If false, there are no + ongoing operations for the instance config. + state (google.cloud.spanner_admin_instance_v1.types.InstanceConfig.State): + Output only. The current instance config + state. + """ + class Type(proto.Enum): + r"""The type of this configuration. + + Values: + TYPE_UNSPECIFIED (0): + Unspecified. + GOOGLE_MANAGED (1): + Google managed configuration. + USER_MANAGED (2): + User managed configuration. + """ + TYPE_UNSPECIFIED = 0 + GOOGLE_MANAGED = 1 + USER_MANAGED = 2 + + class State(proto.Enum): + r"""Indicates the current state of the instance config. + + Values: + STATE_UNSPECIFIED (0): + Not specified. + CREATING (1): + The instance config is still being created. + READY (2): + The instance config is fully created and + ready to be used to create instances. + """ + STATE_UNSPECIFIED = 0 + CREATING = 1 + READY = 2 + + name: str = proto.Field( + proto.STRING, + number=1, + ) + display_name: str = proto.Field( + proto.STRING, + number=2, + ) + config_type: Type = proto.Field( + proto.ENUM, + number=5, + enum=Type, + ) + replicas: MutableSequence['ReplicaInfo'] = proto.RepeatedField( + proto.MESSAGE, + number=3, + message='ReplicaInfo', + ) + optional_replicas: MutableSequence['ReplicaInfo'] = proto.RepeatedField( + proto.MESSAGE, + number=6, + message='ReplicaInfo', + ) + base_config: str = proto.Field( + proto.STRING, + number=7, + ) + labels: MutableMapping[str, str] = proto.MapField( + proto.STRING, + proto.STRING, + number=8, + ) + etag: str = proto.Field( + proto.STRING, + number=9, + ) + leader_options: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=4, + ) + reconciling: bool = proto.Field( + proto.BOOL, + number=10, + ) + state: State = proto.Field( + proto.ENUM, + number=11, + enum=State, + ) + + +class Instance(proto.Message): + r"""An isolated set of Cloud Spanner resources on which databases + can be hosted. + + Attributes: + name (str): + Required. A unique identifier for the instance, which cannot + be changed after the instance is created. Values are of the + form + ``projects//instances/[a-z][-a-z0-9]*[a-z0-9]``. + The final segment of the name must be between 2 and 64 + characters in length. + config (str): + Required. The name of the instance's configuration. Values + are of the form + ``projects//instanceConfigs/``. See + also + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] + and + [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. + display_name (str): + Required. The descriptive name for this + instance as it appears in UIs. Must be unique + per project and between 4 and 30 characters in + length. + node_count (int): + The number of nodes allocated to this instance. At most one + of either node_count or processing_units should be present + in the message. This may be zero in API responses for + instances that are not yet in state ``READY``. + + See `the + documentation `__ + for more information about nodes and processing units. + processing_units (int): + The number of processing units allocated to this instance. + At most one of processing_units or node_count should be + present in the message. This may be zero in API responses + for instances that are not yet in state ``READY``. + + See `the + documentation `__ + for more information about nodes and processing units. + state (google.cloud.spanner_admin_instance_v1.types.Instance.State): + Output only. The current instance state. For + [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance], + the state must be either omitted or set to ``CREATING``. For + [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance], + the state must be either omitted or set to ``READY``. + labels (MutableMapping[str, str]): + Cloud Labels are a flexible and lightweight mechanism for + organizing cloud resources into groups that reflect a + customer's organizational needs and deployment strategies. + Cloud Labels can be used to filter collections of resources. + They can be used to control how resource metrics are + aggregated. And they can be used as arguments to policy + management rules (e.g. route, firewall, load balancing, + etc.). + + - Label keys must be between 1 and 63 characters long and + must conform to the following regular expression: + ``[a-z][a-z0-9_-]{0,62}``. + - Label values must be between 0 and 63 characters long and + must conform to the regular expression + ``[a-z0-9_-]{0,63}``. + - No more than 64 labels can be associated with a given + resource. + + See https://goo.gl/xmQnxf for more information on and + examples of labels. + + If you plan to use labels in your own code, please note that + additional characters may be allowed in the future. And so + you are advised to use an internal label representation, + such as JSON, which doesn't rely upon specific characters + being disallowed. For example, representing labels as the + string: name + "*" + value would prove problematic if we + were to allow "*" in a future release. + endpoint_uris (MutableSequence[str]): + Deprecated. This field is not populated. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time at which the instance + was created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time at which the instance + was most recently updated. + """ + class State(proto.Enum): + r"""Indicates the current state of the instance. + + Values: + STATE_UNSPECIFIED (0): + Not specified. + CREATING (1): + The instance is still being created. + Resources may not be available yet, and + operations such as database creation may not + work. + READY (2): + The instance is fully created and ready to do + work such as creating databases. + """ + STATE_UNSPECIFIED = 0 + CREATING = 1 + READY = 2 + + name: str = proto.Field( + proto.STRING, + number=1, + ) + config: str = proto.Field( + proto.STRING, + number=2, + ) + display_name: str = proto.Field( + proto.STRING, + number=3, + ) + node_count: int = proto.Field( + proto.INT32, + number=5, + ) + processing_units: int = proto.Field( + proto.INT32, + number=9, + ) + state: State = proto.Field( + proto.ENUM, + number=6, + enum=State, + ) + labels: MutableMapping[str, str] = proto.MapField( + proto.STRING, + proto.STRING, + number=7, + ) + endpoint_uris: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=8, + ) + create_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=11, + message=timestamp_pb2.Timestamp, + ) + update_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=12, + message=timestamp_pb2.Timestamp, + ) + + +class ListInstanceConfigsRequest(proto.Message): + r"""The request for + [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. + + Attributes: + parent (str): + Required. The name of the project for which a list of + supported instance configurations is requested. Values are + of the form ``projects/``. + page_size (int): + Number of instance configurations to be + returned in the response. If 0 or less, defaults + to the server's maximum allowed page size. + page_token (str): + If non-empty, ``page_token`` should contain a + [next_page_token][google.spanner.admin.instance.v1.ListInstanceConfigsResponse.next_page_token] + from a previous + [ListInstanceConfigsResponse][google.spanner.admin.instance.v1.ListInstanceConfigsResponse]. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + page_size: int = proto.Field( + proto.INT32, + number=2, + ) + page_token: str = proto.Field( + proto.STRING, + number=3, + ) + + +class ListInstanceConfigsResponse(proto.Message): + r"""The response for + [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. + + Attributes: + instance_configs (MutableSequence[google.cloud.spanner_admin_instance_v1.types.InstanceConfig]): + The list of requested instance + configurations. + next_page_token (str): + ``next_page_token`` can be sent in a subsequent + [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs] + call to fetch more of the matching instance configurations. + """ + + @property + def raw_page(self): + return self + + instance_configs: MutableSequence['InstanceConfig'] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='InstanceConfig', + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + +class GetInstanceConfigRequest(proto.Message): + r"""The request for + [GetInstanceConfigRequest][google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig]. + + Attributes: + name (str): + Required. The name of the requested instance configuration. + Values are of the form + ``projects//instanceConfigs/``. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateInstanceConfigRequest(proto.Message): + r"""The request for + [CreateInstanceConfigRequest][InstanceAdmin.CreateInstanceConfigRequest]. + + Attributes: + parent (str): + Required. The name of the project in which to create the + instance config. Values are of the form + ``projects/``. + instance_config_id (str): + Required. The ID of the instance config to create. Valid + identifiers are of the form ``custom-[-a-z0-9]*[a-z0-9]`` + and must be between 2 and 64 characters in length. The + ``custom-`` prefix is required to avoid name conflicts with + Google managed configurations. + instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): + Required. The InstanceConfig proto of the configuration to + create. instance_config.name must be + ``/instanceConfigs/``. + instance_config.base_config must be a Google managed + configuration name, e.g. /instanceConfigs/us-east1, + /instanceConfigs/nam3. + validate_only (bool): + An option to validate, but not actually + execute, a request, and provide the same + response. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + instance_config_id: str = proto.Field( + proto.STRING, + number=2, + ) + instance_config: 'InstanceConfig' = proto.Field( + proto.MESSAGE, + number=3, + message='InstanceConfig', + ) + validate_only: bool = proto.Field( + proto.BOOL, + number=4, + ) + + +class UpdateInstanceConfigRequest(proto.Message): + r"""The request for + [UpdateInstanceConfigRequest][InstanceAdmin.UpdateInstanceConfigRequest]. + + Attributes: + instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): + Required. The user instance config to update, which must + always include the instance config name. Otherwise, only + fields mentioned in + [update_mask][google.spanner.admin.instance.v1.UpdateInstanceConfigRequest.update_mask] + need be included. To prevent conflicts of concurrent + updates, + [etag][google.spanner.admin.instance.v1.InstanceConfig.reconciling] + can be used. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. A mask specifying which fields in + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] + should be updated. The field mask must always be specified; + this prevents any future fields in + [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] + from being erased accidentally by clients that do not know + about them. Only display_name and labels can be updated. + validate_only (bool): + An option to validate, but not actually + execute, a request, and provide the same + response. + """ + + instance_config: 'InstanceConfig' = proto.Field( + proto.MESSAGE, + number=1, + message='InstanceConfig', + ) + update_mask: field_mask_pb2.FieldMask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + validate_only: bool = proto.Field( + proto.BOOL, + number=3, + ) + + +class DeleteInstanceConfigRequest(proto.Message): + r"""The request for + [DeleteInstanceConfigRequest][InstanceAdmin.DeleteInstanceConfigRequest]. + + Attributes: + name (str): + Required. The name of the instance configuration to be + deleted. Values are of the form + ``projects//instanceConfigs/`` + etag (str): + Used for optimistic concurrency control as a + way to help prevent simultaneous deletes of an + instance config from overwriting each other. If + not empty, the API + only deletes the instance config when the etag + provided matches the current status of the + requested instance config. Otherwise, deletes + the instance config without checking the current + status of the requested instance config. + validate_only (bool): + An option to validate, but not actually + execute, a request, and provide the same + response. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + etag: str = proto.Field( + proto.STRING, + number=2, + ) + validate_only: bool = proto.Field( + proto.BOOL, + number=3, + ) + + +class ListInstanceConfigOperationsRequest(proto.Message): + r"""The request for + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. + + Attributes: + parent (str): + Required. The project of the instance config operations. + Values are of the form ``projects/``. + filter (str): + An expression that filters the list of returned operations. + + A filter expression consists of a field name, a comparison + operator, and a value for filtering. The value must be a + string, a number, or a boolean. The comparison operator must + be one of: ``<``, ``>``, ``<=``, ``>=``, ``!=``, ``=``, or + ``:``. Colon ``:`` is the contains operator. Filter rules + are not case sensitive. + + The following fields in the + [Operation][google.longrunning.Operation] are eligible for + filtering: + + - ``name`` - The name of the long-running operation + - ``done`` - False if the operation is in progress, else + true. + - ``metadata.@type`` - the type of metadata. For example, + the type string for + [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata] + is + ``type.googleapis.com/google.spanner.admin.instance.v1.CreateInstanceConfigMetadata``. + - ``metadata.`` - any field in metadata.value. + ``metadata.@type`` must be specified first, if filtering + on metadata fields. + - ``error`` - Error associated with the long-running + operation. + - ``response.@type`` - the type of response. + - ``response.`` - any field in response.value. + + You can combine multiple expressions by enclosing each + expression in parentheses. By default, expressions are + combined with AND logic. However, you can specify AND, OR, + and NOT logic explicitly. + + Here are a few examples: + + - ``done:true`` - The operation is complete. + - ``(metadata.@type=`` + ``type.googleapis.com/google.spanner.admin.instance.v1.CreateInstanceConfigMetadata) AND`` + ``(metadata.instance_config.name:custom-config) AND`` + ``(metadata.progress.start_time < \"2021-03-28T14:50:00Z\") AND`` + ``(error:*)`` - Return operations where: + + - The operation's metadata type is + [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. + - The instance config name contains "custom-config". + - The operation started before 2021-03-28T14:50:00Z. + - The operation resulted in an error. + page_size (int): + Number of operations to be returned in the + response. If 0 or less, defaults to the server's + maximum allowed page size. + page_token (str): + If non-empty, ``page_token`` should contain a + [next_page_token][google.spanner.admin.instance.v1.ListInstanceConfigOperationsResponse.next_page_token] + from a previous + [ListInstanceConfigOperationsResponse][google.spanner.admin.instance.v1.ListInstanceConfigOperationsResponse] + to the same ``parent`` and with the same ``filter``. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + filter: str = proto.Field( + proto.STRING, + number=2, + ) + page_size: int = proto.Field( + proto.INT32, + number=3, + ) + page_token: str = proto.Field( + proto.STRING, + number=4, + ) + + +class ListInstanceConfigOperationsResponse(proto.Message): + r"""The response for + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. + + Attributes: + operations (MutableSequence[google.longrunning.operations_pb2.Operation]): + The list of matching instance config [long-running + operations][google.longrunning.Operation]. Each operation's + name will be prefixed by the instance config's name. The + operation's + [metadata][google.longrunning.Operation.metadata] field type + ``metadata.type_url`` describes the type of the metadata. + next_page_token (str): + ``next_page_token`` can be sent in a subsequent + [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations] + call to fetch more of the matching metadata. + """ + + @property + def raw_page(self): + return self + + operations: MutableSequence[operations_pb2.Operation] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=operations_pb2.Operation, + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + +class GetInstanceRequest(proto.Message): + r"""The request for + [GetInstance][google.spanner.admin.instance.v1.InstanceAdmin.GetInstance]. + + Attributes: + name (str): + Required. The name of the requested instance. Values are of + the form ``projects//instances/``. + field_mask (google.protobuf.field_mask_pb2.FieldMask): + If field_mask is present, specifies the subset of + [Instance][google.spanner.admin.instance.v1.Instance] fields + that should be returned. If absent, all + [Instance][google.spanner.admin.instance.v1.Instance] fields + are returned. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + field_mask: field_mask_pb2.FieldMask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class CreateInstanceRequest(proto.Message): + r"""The request for + [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance]. + + Attributes: + parent (str): + Required. The name of the project in which to create the + instance. Values are of the form ``projects/``. + instance_id (str): + Required. The ID of the instance to create. Valid + identifiers are of the form ``[a-z][-a-z0-9]*[a-z0-9]`` and + must be between 2 and 64 characters in length. + instance (google.cloud.spanner_admin_instance_v1.types.Instance): + Required. The instance to create. The name may be omitted, + but if specified must be + ``/instances/``. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + instance_id: str = proto.Field( + proto.STRING, + number=2, + ) + instance: 'Instance' = proto.Field( + proto.MESSAGE, + number=3, + message='Instance', + ) + + +class ListInstancesRequest(proto.Message): + r"""The request for + [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. + + Attributes: + parent (str): + Required. The name of the project for which a list of + instances is requested. Values are of the form + ``projects/``. + page_size (int): + Number of instances to be returned in the + response. If 0 or less, defaults to the server's + maximum allowed page size. + page_token (str): + If non-empty, ``page_token`` should contain a + [next_page_token][google.spanner.admin.instance.v1.ListInstancesResponse.next_page_token] + from a previous + [ListInstancesResponse][google.spanner.admin.instance.v1.ListInstancesResponse]. + filter (str): + An expression for filtering the results of the request. + Filter rules are case insensitive. The fields eligible for + filtering are: + + - ``name`` + - ``display_name`` + - ``labels.key`` where key is the name of a label + + Some examples of using filters are: + + - ``name:*`` --> The instance has a name. + - ``name:Howl`` --> The instance's name contains the string + "howl". + - ``name:HOWL`` --> Equivalent to above. + - ``NAME:howl`` --> Equivalent to above. + - ``labels.env:*`` --> The instance has the label "env". + - ``labels.env:dev`` --> The instance has the label "env" + and the value of the label contains the string "dev". + - ``name:howl labels.env:dev`` --> The instance's name + contains "howl" and it has the label "env" with its value + containing "dev". + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + page_size: int = proto.Field( + proto.INT32, + number=2, + ) + page_token: str = proto.Field( + proto.STRING, + number=3, + ) + filter: str = proto.Field( + proto.STRING, + number=4, + ) + + +class ListInstancesResponse(proto.Message): + r"""The response for + [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. + + Attributes: + instances (MutableSequence[google.cloud.spanner_admin_instance_v1.types.Instance]): + The list of requested instances. + next_page_token (str): + ``next_page_token`` can be sent in a subsequent + [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances] + call to fetch more of the matching instances. + """ + + @property + def raw_page(self): + return self + + instances: MutableSequence['Instance'] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message='Instance', + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + +class UpdateInstanceRequest(proto.Message): + r"""The request for + [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance]. + + Attributes: + instance (google.cloud.spanner_admin_instance_v1.types.Instance): + Required. The instance to update, which must always include + the instance name. Otherwise, only fields mentioned in + [field_mask][google.spanner.admin.instance.v1.UpdateInstanceRequest.field_mask] + need be included. + field_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. A mask specifying which fields in + [Instance][google.spanner.admin.instance.v1.Instance] should + be updated. The field mask must always be specified; this + prevents any future fields in + [Instance][google.spanner.admin.instance.v1.Instance] from + being erased accidentally by clients that do not know about + them. + """ + + instance: 'Instance' = proto.Field( + proto.MESSAGE, + number=1, + message='Instance', + ) + field_mask: field_mask_pb2.FieldMask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class DeleteInstanceRequest(proto.Message): + r"""The request for + [DeleteInstance][google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance]. + + Attributes: + name (str): + Required. The name of the instance to be deleted. Values are + of the form ``projects//instances/`` + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateInstanceMetadata(proto.Message): + r"""Metadata type for the operation returned by + [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance]. + + Attributes: + instance (google.cloud.spanner_admin_instance_v1.types.Instance): + The instance being created. + start_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which the + [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance] + request was received. + cancel_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which this operation was + cancelled. If set, this operation is in the + process of undoing itself (which is guaranteed + to succeed) and cannot be cancelled again. + end_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which this operation failed or + was completed successfully. + """ + + instance: 'Instance' = proto.Field( + proto.MESSAGE, + number=1, + message='Instance', + ) + start_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + cancel_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + end_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + + +class UpdateInstanceMetadata(proto.Message): + r"""Metadata type for the operation returned by + [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance]. + + Attributes: + instance (google.cloud.spanner_admin_instance_v1.types.Instance): + The desired end state of the update. + start_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which + [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance] + request was received. + cancel_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which this operation was + cancelled. If set, this operation is in the + process of undoing itself (which is guaranteed + to succeed) and cannot be cancelled again. + end_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which this operation failed or + was completed successfully. + """ + + instance: 'Instance' = proto.Field( + proto.MESSAGE, + number=1, + message='Instance', + ) + start_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + cancel_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + end_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + + +class CreateInstanceConfigMetadata(proto.Message): + r"""Metadata type for the operation returned by + [CreateInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig]. + + Attributes: + instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): + The target instance config end state. + progress (google.cloud.spanner_admin_instance_v1.types.OperationProgress): + The progress of the + [CreateInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig] + operation. + cancel_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which this operation was + cancelled. + """ + + instance_config: 'InstanceConfig' = proto.Field( + proto.MESSAGE, + number=1, + message='InstanceConfig', + ) + progress: common.OperationProgress = proto.Field( + proto.MESSAGE, + number=2, + message=common.OperationProgress, + ) + cancel_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + + +class UpdateInstanceConfigMetadata(proto.Message): + r"""Metadata type for the operation returned by + [UpdateInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstanceConfig]. + + Attributes: + instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): + The desired instance config after updating. + progress (google.cloud.spanner_admin_instance_v1.types.OperationProgress): + The progress of the + [UpdateInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstanceConfig] + operation. + cancel_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which this operation was + cancelled. + """ + + instance_config: 'InstanceConfig' = proto.Field( + proto.MESSAGE, + number=1, + message='InstanceConfig', + ) + progress: common.OperationProgress = proto.Field( + proto.MESSAGE, + number=2, + message=common.OperationProgress, + ) + cancel_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner_admin_instance/v1/mypy.ini b/owl-bot-staging/spanner_admin_instance/v1/mypy.ini new file mode 100644 index 0000000000..574c5aed39 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.7 +namespace_packages = True diff --git a/owl-bot-staging/spanner_admin_instance/v1/noxfile.py b/owl-bot-staging/spanner_admin_instance/v1/noxfile.py new file mode 100644 index 0000000000..445d92b157 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/noxfile.py @@ -0,0 +1,184 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +import pathlib +import shutil +import subprocess +import sys + + +import nox # type: ignore + +ALL_PYTHON = [ + "3.7", + "3.8", + "3.9", + "3.10", + "3.11", +] + +CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() + +LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" +PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8") + +BLACK_VERSION = "black==22.3.0" +BLACK_PATHS = ["docs", "google", "tests", "samples", "noxfile.py", "setup.py"] +DEFAULT_PYTHON_VERSION = "3.11" + +nox.sessions = [ + "unit", + "cover", + "mypy", + "check_lower_bounds" + # exclude update_lower_bounds from default + "docs", + "blacken", + "lint", + "lint_setup_py", +] + +@nox.session(python=ALL_PYTHON) +def unit(session): + """Run the unit test suite.""" + + session.install('coverage', 'pytest', 'pytest-cov', 'pytest-asyncio', 'asyncmock; python_version < "3.8"') + session.install('-e', '.') + + session.run( + 'py.test', + '--quiet', + '--cov=google/cloud/spanner_admin_instance_v1/', + '--cov=tests/', + '--cov-config=.coveragerc', + '--cov-report=term', + '--cov-report=html', + os.path.join('tests', 'unit', ''.join(session.posargs)) + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def cover(session): + """Run the final coverage report. + This outputs the coverage report aggregating coverage from the unit + test runs (not system test runs), and then erases coverage data. + """ + session.install("coverage", "pytest-cov") + session.run("coverage", "report", "--show-missing", "--fail-under=100") + + session.run("coverage", "erase") + + +@nox.session(python=ALL_PYTHON) +def mypy(session): + """Run the type checker.""" + session.install( + 'mypy', + 'types-requests', + 'types-protobuf' + ) + session.install('.') + session.run( + 'mypy', + '--explicit-package-bases', + 'google', + ) + + +@nox.session +def update_lower_bounds(session): + """Update lower bounds in constraints.txt to match setup.py""" + session.install('google-cloud-testutils') + session.install('.') + + session.run( + 'lower-bound-checker', + 'update', + '--package-name', + PACKAGE_NAME, + '--constraints-file', + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + + +@nox.session +def check_lower_bounds(session): + """Check lower bounds in setup.py are reflected in constraints file""" + session.install('google-cloud-testutils') + session.install('.') + + session.run( + 'lower-bound-checker', + 'check', + '--package-name', + PACKAGE_NAME, + '--constraints-file', + str(LOWER_BOUND_CONSTRAINTS_FILE), + ) + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def docs(session): + """Build the docs for this library.""" + + session.install("-e", ".") + session.install("sphinx==4.0.1", "alabaster", "recommonmark") + + shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) + session.run( + "sphinx-build", + "-W", # warnings as errors + "-T", # show full traceback on exception + "-N", # no colors + "-b", + "html", + "-d", + os.path.join("docs", "_build", "doctrees", ""), + os.path.join("docs", ""), + os.path.join("docs", "_build", "html", ""), + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def lint(session): + """Run linters. + + Returns a failure if the linters find linting errors or sufficiently + serious code quality issues. + """ + session.install("flake8", BLACK_VERSION) + session.run( + "black", + "--check", + *BLACK_PATHS, + ) + session.run("flake8", "google", "tests", "samples") + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def blacken(session): + """Run black. Format code to uniform standard.""" + session.install(BLACK_VERSION) + session.run( + "black", + *BLACK_PATHS, + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def lint_setup_py(session): + """Verify that setup.py is valid (including RST check).""" + session.install("docutils", "pygments") + session.run("python", "setup.py", "check", "--restructuredtext", "--strict") diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.instance.v1.json b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.instance.v1.json new file mode 100644 index 0000000000..9572d4d727 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.instance.v1.json @@ -0,0 +1,2313 @@ +{ + "clientLibrary": { + "apis": [ + { + "id": "google.spanner.admin.instance.v1", + "version": "v1" + } + ], + "language": "PYTHON", + "name": "google-cloud-spanner-admin-instance", + "version": "0.1.0" + }, + "snippets": [ + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.create_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "CreateInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.CreateInstanceConfigRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "instance_config", + "type": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig" + }, + { + "name": "instance_config_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_instance_config" + }, + "description": "Sample for CreateInstanceConfig", + "file": "spanner_v1_generated_instance_admin_create_instance_config_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_async", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_create_instance_config_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.create_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "CreateInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.CreateInstanceConfigRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "instance_config", + "type": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig" + }, + { + "name": "instance_config_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_instance_config" + }, + "description": "Sample for CreateInstanceConfig", + "file": "spanner_v1_generated_instance_admin_create_instance_config_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_sync", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_create_instance_config_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.create_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "CreateInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.CreateInstanceRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "instance_id", + "type": "str" + }, + { + "name": "instance", + "type": "google.cloud.spanner_admin_instance_v1.types.Instance" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_instance" + }, + "description": "Sample for CreateInstance", + "file": "spanner_v1_generated_instance_admin_create_instance_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_CreateInstance_async", + "segments": [ + { + "end": 62, + "start": 27, + "type": "FULL" + }, + { + "end": 62, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 52, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 59, + "start": 53, + "type": "REQUEST_EXECUTION" + }, + { + "end": 63, + "start": 60, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_create_instance_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.create_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "CreateInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.CreateInstanceRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "instance_id", + "type": "str" + }, + { + "name": "instance", + "type": "google.cloud.spanner_admin_instance_v1.types.Instance" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_instance" + }, + "description": "Sample for CreateInstance", + "file": "spanner_v1_generated_instance_admin_create_instance_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_CreateInstance_sync", + "segments": [ + { + "end": 62, + "start": 27, + "type": "FULL" + }, + { + "end": 62, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 52, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 59, + "start": 53, + "type": "REQUEST_EXECUTION" + }, + { + "end": 63, + "start": 60, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_create_instance_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.delete_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "DeleteInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.DeleteInstanceConfigRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_instance_config" + }, + "description": "Sample for DeleteInstanceConfig", + "file": "spanner_v1_generated_instance_admin_delete_instance_config_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_delete_instance_config_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.delete_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "DeleteInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.DeleteInstanceConfigRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_instance_config" + }, + "description": "Sample for DeleteInstanceConfig", + "file": "spanner_v1_generated_instance_admin_delete_instance_config_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_delete_instance_config_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.delete_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "DeleteInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.DeleteInstanceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_instance" + }, + "description": "Sample for DeleteInstance", + "file": "spanner_v1_generated_instance_admin_delete_instance_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_DeleteInstance_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_delete_instance_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.delete_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "DeleteInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.DeleteInstanceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_instance" + }, + "description": "Sample for DeleteInstance", + "file": "spanner_v1_generated_instance_admin_delete_instance_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_DeleteInstance_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_delete_instance_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.get_iam_policy", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetIamPolicy", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "GetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "get_iam_policy" + }, + "description": "Sample for GetIamPolicy", + "file": "spanner_v1_generated_instance_admin_get_iam_policy_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetIamPolicy_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 41, + "start": 39, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 42, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_get_iam_policy_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_iam_policy", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetIamPolicy", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "GetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "get_iam_policy" + }, + "description": "Sample for GetIamPolicy", + "file": "spanner_v1_generated_instance_admin_get_iam_policy_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetIamPolicy_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 41, + "start": 39, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 42, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_get_iam_policy_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.get_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "GetInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig", + "shortName": "get_instance_config" + }, + "description": "Sample for GetInstanceConfig", + "file": "spanner_v1_generated_instance_admin_get_instance_config_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstanceConfig_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_get_instance_config_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "GetInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig", + "shortName": "get_instance_config" + }, + "description": "Sample for GetInstanceConfig", + "file": "spanner_v1_generated_instance_admin_get_instance_config_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstanceConfig_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_get_instance_config_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.get_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "GetInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.types.Instance", + "shortName": "get_instance" + }, + "description": "Sample for GetInstance", + "file": "spanner_v1_generated_instance_admin_get_instance_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstance_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_get_instance_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "GetInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.types.Instance", + "shortName": "get_instance" + }, + "description": "Sample for GetInstance", + "file": "spanner_v1_generated_instance_admin_get_instance_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstance_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_get_instance_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.list_instance_config_operations", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "ListInstanceConfigOperations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigOperationsAsyncPager", + "shortName": "list_instance_config_operations" + }, + "description": "Sample for ListInstanceConfigOperations", + "file": "spanner_v1_generated_instance_admin_list_instance_config_operations_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_list_instance_config_operations_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.list_instance_config_operations", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "ListInstanceConfigOperations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigOperationsPager", + "shortName": "list_instance_config_operations" + }, + "description": "Sample for ListInstanceConfigOperations", + "file": "spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.list_instance_configs", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "ListInstanceConfigs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigsAsyncPager", + "shortName": "list_instance_configs" + }, + "description": "Sample for ListInstanceConfigs", + "file": "spanner_v1_generated_instance_admin_list_instance_configs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_list_instance_configs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.list_instance_configs", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "ListInstanceConfigs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigsPager", + "shortName": "list_instance_configs" + }, + "description": "Sample for ListInstanceConfigs", + "file": "spanner_v1_generated_instance_admin_list_instance_configs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_list_instance_configs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.list_instances", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstances", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "ListInstances" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancesAsyncPager", + "shortName": "list_instances" + }, + "description": "Sample for ListInstances", + "file": "spanner_v1_generated_instance_admin_list_instances_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstances_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_list_instances_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.list_instances", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstances", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "ListInstances" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancesPager", + "shortName": "list_instances" + }, + "description": "Sample for ListInstances", + "file": "spanner_v1_generated_instance_admin_list_instances_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstances_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_list_instances_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.set_iam_policy", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.SetIamPolicy", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "SetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.SetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "set_iam_policy" + }, + "description": "Sample for SetIamPolicy", + "file": "spanner_v1_generated_instance_admin_set_iam_policy_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_SetIamPolicy_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 41, + "start": 39, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 42, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_set_iam_policy_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.set_iam_policy", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.SetIamPolicy", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "SetIamPolicy" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.SetIamPolicyRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.policy_pb2.Policy", + "shortName": "set_iam_policy" + }, + "description": "Sample for SetIamPolicy", + "file": "spanner_v1_generated_instance_admin_set_iam_policy_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_SetIamPolicy_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 41, + "start": 39, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 42, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_set_iam_policy_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.test_iam_permissions", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.TestIamPermissions", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "TestIamPermissions" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "permissions", + "type": "MutableSequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", + "shortName": "test_iam_permissions" + }, + "description": "Sample for TestIamPermissions", + "file": "spanner_v1_generated_instance_admin_test_iam_permissions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_TestIamPermissions_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 41, + "start": 39, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 42, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_test_iam_permissions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.test_iam_permissions", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.TestIamPermissions", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "TestIamPermissions" + }, + "parameters": [ + { + "name": "request", + "type": "google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest" + }, + { + "name": "resource", + "type": "str" + }, + { + "name": "permissions", + "type": "MutableSequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", + "shortName": "test_iam_permissions" + }, + "description": "Sample for TestIamPermissions", + "file": "spanner_v1_generated_instance_admin_test_iam_permissions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_TestIamPermissions_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 41, + "start": 39, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 42, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_test_iam_permissions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.update_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "UpdateInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.UpdateInstanceConfigRequest" + }, + { + "name": "instance_config", + "type": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_instance_config" + }, + "description": "Sample for UpdateInstanceConfig", + "file": "spanner_v1_generated_instance_admin_update_instance_config_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_async", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_update_instance_config_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.update_instance_config", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstanceConfig", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "UpdateInstanceConfig" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.UpdateInstanceConfigRequest" + }, + { + "name": "instance_config", + "type": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_instance_config" + }, + "description": "Sample for UpdateInstanceConfig", + "file": "spanner_v1_generated_instance_admin_update_instance_config_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_sync", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_update_instance_config_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", + "shortName": "InstanceAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.update_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "UpdateInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.UpdateInstanceRequest" + }, + { + "name": "instance", + "type": "google.cloud.spanner_admin_instance_v1.types.Instance" + }, + { + "name": "field_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_instance" + }, + "description": "Sample for UpdateInstance", + "file": "spanner_v1_generated_instance_admin_update_instance_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_UpdateInstance_async", + "segments": [ + { + "end": 60, + "start": 27, + "type": "FULL" + }, + { + "end": 60, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 50, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 57, + "start": 51, + "type": "REQUEST_EXECUTION" + }, + { + "end": 61, + "start": 58, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_update_instance_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", + "shortName": "InstanceAdminClient" + }, + "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.update_instance", + "method": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance", + "service": { + "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", + "shortName": "InstanceAdmin" + }, + "shortName": "UpdateInstance" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_instance_v1.types.UpdateInstanceRequest" + }, + { + "name": "instance", + "type": "google.cloud.spanner_admin_instance_v1.types.Instance" + }, + { + "name": "field_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_instance" + }, + "description": "Sample for UpdateInstance", + "file": "spanner_v1_generated_instance_admin_update_instance_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_InstanceAdmin_UpdateInstance_sync", + "segments": [ + { + "end": 60, + "start": 27, + "type": "FULL" + }, + { + "end": 60, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 50, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 57, + "start": 51, + "type": "REQUEST_EXECUTION" + }, + { + "end": 61, + "start": 58, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_instance_admin_update_instance_sync.py" + } + ] +} diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_async.py new file mode 100644 index 0000000000..baf18d92d1 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_async.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_CreateInstance_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +async def sample_create_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.CreateInstanceRequest( + parent="parent_value", + instance_id="instance_id_value", + instance=instance, + ) + + # Make the request + operation = client.create_instance(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_CreateInstance_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_async.py new file mode 100644 index 0000000000..804a0b94f7 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_async.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateInstanceConfig +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +async def sample_create_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.CreateInstanceConfigRequest( + parent="parent_value", + instance_config_id="instance_config_id_value", + ) + + # Make the request + operation = client.create_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_sync.py new file mode 100644 index 0000000000..fcd79a04ff --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_sync.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateInstanceConfig +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +def sample_create_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.CreateInstanceConfigRequest( + parent="parent_value", + instance_config_id="instance_config_id_value", + ) + + # Make the request + operation = client.create_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_sync.py new file mode 100644 index 0000000000..053c083191 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_sync.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_CreateInstance_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +def sample_create_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.CreateInstanceRequest( + parent="parent_value", + instance_id="instance_id_value", + instance=instance, + ) + + # Make the request + operation = client.create_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_CreateInstance_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_async.py new file mode 100644 index 0000000000..e455506517 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_DeleteInstance_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +async def sample_delete_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceRequest( + name="name_value", + ) + + # Make the request + await client.delete_instance(request=request) + + +# [END spanner_v1_generated_InstanceAdmin_DeleteInstance_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_async.py new file mode 100644 index 0000000000..0234dd31be --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteInstanceConfig +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +async def sample_delete_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceConfigRequest( + name="name_value", + ) + + # Make the request + await client.delete_instance_config(request=request) + + +# [END spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_sync.py new file mode 100644 index 0000000000..7e7ef31843 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteInstanceConfig +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +def sample_delete_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceConfigRequest( + name="name_value", + ) + + # Make the request + client.delete_instance_config(request=request) + + +# [END spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_sync.py new file mode 100644 index 0000000000..0b74e53652 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_DeleteInstance_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +def sample_delete_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.DeleteInstanceRequest( + name="name_value", + ) + + # Make the request + client.delete_instance(request=request) + + +# [END spanner_v1_generated_InstanceAdmin_DeleteInstance_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_async.py new file mode 100644 index 0000000000..9fd51bcd8d --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_GetIamPolicy_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +async def sample_get_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = await client.get_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_GetIamPolicy_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_sync.py new file mode 100644 index 0000000000..cad72ee137 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_GetIamPolicy_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +def sample_get_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.GetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.get_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_GetIamPolicy_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_async.py new file mode 100644 index 0000000000..f26919b4c5 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_GetInstance_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +async def sample_get_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceRequest( + name="name_value", + ) + + # Make the request + response = await client.get_instance(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_GetInstance_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_async.py new file mode 100644 index 0000000000..069fa1a4f3 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetInstanceConfig +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_GetInstanceConfig_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +async def sample_get_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceConfigRequest( + name="name_value", + ) + + # Make the request + response = await client.get_instance_config(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_GetInstanceConfig_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_sync.py new file mode 100644 index 0000000000..59c31e2931 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetInstanceConfig +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_GetInstanceConfig_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +def sample_get_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceConfigRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance_config(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_GetInstanceConfig_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_sync.py new file mode 100644 index 0000000000..7cb95b3256 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_GetInstance_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +def sample_get_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.GetInstanceRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_GetInstance_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_async.py new file mode 100644 index 0000000000..ba5baa65d4 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListInstanceConfigOperations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +async def sample_list_instance_config_operations(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_config_operations(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py new file mode 100644 index 0000000000..b7e113488b --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListInstanceConfigOperations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +def sample_list_instance_config_operations(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigOperationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_config_operations(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_async.py new file mode 100644 index 0000000000..531e22516f --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListInstanceConfigs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +async def sample_list_instance_configs(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_configs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_sync.py new file mode 100644 index 0000000000..297fa5bee2 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListInstanceConfigs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +def sample_list_instance_configs(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstanceConfigsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instance_configs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_async.py new file mode 100644 index 0000000000..9769963f45 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListInstances +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_ListInstances_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +async def sample_list_instances(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstancesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instances(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END spanner_v1_generated_InstanceAdmin_ListInstances_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_sync.py new file mode 100644 index 0000000000..6ce1c4089c --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListInstances +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_ListInstances_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +def sample_list_instances(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.ListInstancesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instances(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END spanner_v1_generated_InstanceAdmin_ListInstances_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_async.py new file mode 100644 index 0000000000..6ffa4e1f51 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_SetIamPolicy_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +async def sample_set_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = await client.set_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_SetIamPolicy_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_sync.py new file mode 100644 index 0000000000..46646279e7 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SetIamPolicy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_SetIamPolicy_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +def sample_set_iam_policy(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.SetIamPolicyRequest( + resource="resource_value", + ) + + # Make the request + response = client.set_iam_policy(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_SetIamPolicy_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_async.py new file mode 100644 index 0000000000..7014b6ed4a --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for TestIamPermissions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_TestIamPermissions_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +async def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value1', 'permissions_value2'], + ) + + # Make the request + response = await client.test_iam_permissions(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_TestIamPermissions_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_sync.py new file mode 100644 index 0000000000..92037b5780 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for TestIamPermissions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_TestIamPermissions_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 +from google.iam.v1 import iam_policy_pb2 # type: ignore + + +def sample_test_iam_permissions(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = iam_policy_pb2.TestIamPermissionsRequest( + resource="resource_value", + permissions=['permissions_value1', 'permissions_value2'], + ) + + # Make the request + response = client.test_iam_permissions(request=request) + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_TestIamPermissions_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_async.py new file mode 100644 index 0000000000..214b138ea4 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_async.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_UpdateInstance_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +async def sample_update_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.UpdateInstanceRequest( + instance=instance, + ) + + # Make the request + operation = client.update_instance(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_UpdateInstance_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_async.py new file mode 100644 index 0000000000..6f33a85a25 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_async.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateInstanceConfig +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_async] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +async def sample_update_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminAsyncClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.UpdateInstanceConfigRequest( + ) + + # Make the request + operation = client.update_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_sync.py new file mode 100644 index 0000000000..bdcb9a8dbd --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_sync.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateInstanceConfig +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +def sample_update_instance_config(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + request = spanner_admin_instance_v1.UpdateInstanceConfigRequest( + ) + + # Make the request + operation = client.update_instance_config(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_sync.py new file mode 100644 index 0000000000..c614d8a6b0 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_sync.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateInstance +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-spanner-admin-instance + + +# [START spanner_v1_generated_InstanceAdmin_UpdateInstance_sync] +# This snippet has been automatically generated and should be regarded as a +# code template only. +# It will require modifications to work: +# - It may require correct/in-range values for request initialization. +# - It may require specifying regional endpoints when creating the service +# client as shown in: +# https://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import spanner_admin_instance_v1 + + +def sample_update_instance(): + # Create a client + client = spanner_admin_instance_v1.InstanceAdminClient() + + # Initialize request argument(s) + instance = spanner_admin_instance_v1.Instance() + instance.name = "name_value" + instance.config = "config_value" + instance.display_name = "display_name_value" + + request = spanner_admin_instance_v1.UpdateInstanceRequest( + instance=instance, + ) + + # Make the request + operation = client.update_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END spanner_v1_generated_InstanceAdmin_UpdateInstance_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/scripts/fixup_spanner_admin_instance_v1_keywords.py b/owl-bot-staging/spanner_admin_instance/v1/scripts/fixup_spanner_admin_instance_v1_keywords.py new file mode 100644 index 0000000000..c5d08e6b51 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/scripts/fixup_spanner_admin_instance_v1_keywords.py @@ -0,0 +1,189 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import argparse +import os +import libcst as cst +import pathlib +import sys +from typing import (Any, Callable, Dict, List, Sequence, Tuple) + + +def partition( + predicate: Callable[[Any], bool], + iterator: Sequence[Any] +) -> Tuple[List[Any], List[Any]]: + """A stable, out-of-place partition.""" + results = ([], []) + + for i in iterator: + results[int(predicate(i))].append(i) + + # Returns trueList, falseList + return results[1], results[0] + + +class spanner_admin_instanceCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'create_instance': ('parent', 'instance_id', 'instance', ), + 'create_instance_config': ('parent', 'instance_config_id', 'instance_config', 'validate_only', ), + 'delete_instance': ('name', ), + 'delete_instance_config': ('name', 'etag', 'validate_only', ), + 'get_iam_policy': ('resource', 'options', ), + 'get_instance': ('name', 'field_mask', ), + 'get_instance_config': ('name', ), + 'list_instance_config_operations': ('parent', 'filter', 'page_size', 'page_token', ), + 'list_instance_configs': ('parent', 'page_size', 'page_token', ), + 'list_instances': ('parent', 'page_size', 'page_token', 'filter', ), + 'set_iam_policy': ('resource', 'policy', 'update_mask', ), + 'test_iam_permissions': ('resource', 'permissions', ), + 'update_instance': ('instance', 'field_mask', ), + 'update_instance_config': ('instance_config', 'update_mask', 'validate_only', ), + } + + def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: + try: + key = original.func.attr.value + kword_params = self.METHOD_TO_PARAMS[key] + except (AttributeError, KeyError): + # Either not a method from the API or too convoluted to be sure. + return updated + + # If the existing code is valid, keyword args come after positional args. + # Therefore, all positional args must map to the first parameters. + args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) + if any(k.keyword.value == "request" for k in kwargs): + # We've already fixed this file, don't fix it again. + return updated + + kwargs, ctrl_kwargs = partition( + lambda a: a.keyword.value not in self.CTRL_PARAMS, + kwargs + ) + + args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] + ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) + for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) + + request_arg = cst.Arg( + value=cst.Dict([ + cst.DictElement( + cst.SimpleString("'{}'".format(name)), +cst.Element(value=arg.value) + ) + # Note: the args + kwargs looks silly, but keep in mind that + # the control parameters had to be stripped out, and that + # those could have been passed positionally or by keyword. + for name, arg in zip(kword_params, args + kwargs)]), + keyword=cst.Name("request") + ) + + return updated.with_changes( + args=[request_arg] + ctrl_kwargs + ) + + +def fix_files( + in_dir: pathlib.Path, + out_dir: pathlib.Path, + *, + transformer=spanner_admin_instanceCallTransformer(), +): + """Duplicate the input dir to the output dir, fixing file method calls. + + Preconditions: + * in_dir is a real directory + * out_dir is a real, empty directory + """ + pyfile_gen = ( + pathlib.Path(os.path.join(root, f)) + for root, _, files in os.walk(in_dir) + for f in files if os.path.splitext(f)[1] == ".py" + ) + + for fpath in pyfile_gen: + with open(fpath, 'r') as f: + src = f.read() + + # Parse the code and insert method call fixes. + tree = cst.parse_module(src) + updated = tree.visit(transformer) + + # Create the path and directory structure for the new file. + updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) + updated_path.parent.mkdir(parents=True, exist_ok=True) + + # Generate the updated source file at the corresponding path. + with open(updated_path, 'w') as f: + f.write(updated.code) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description="""Fix up source that uses the spanner_admin_instance client library. + +The existing sources are NOT overwritten but are copied to output_dir with changes made. + +Note: This tool operates at a best-effort level at converting positional + parameters in client method calls to keyword based parameters. + Cases where it WILL FAIL include + A) * or ** expansion in a method call. + B) Calls via function or method alias (includes free function calls) + C) Indirect or dispatched calls (e.g. the method is looked up dynamically) + + These all constitute false negatives. The tool will also detect false + positives when an API method shares a name with another method. +""") + parser.add_argument( + '-d', + '--input-directory', + required=True, + dest='input_dir', + help='the input directory to walk for python files to fix up', + ) + parser.add_argument( + '-o', + '--output-directory', + required=True, + dest='output_dir', + help='the directory to output files fixed via un-flattening', + ) + args = parser.parse_args() + input_dir = pathlib.Path(args.input_dir) + output_dir = pathlib.Path(args.output_dir) + if not input_dir.is_dir(): + print( + f"input directory '{input_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if not output_dir.is_dir(): + print( + f"output directory '{output_dir}' does not exist or is not a directory", + file=sys.stderr, + ) + sys.exit(-1) + + if os.listdir(output_dir): + print( + f"output directory '{output_dir}' is not empty", + file=sys.stderr, + ) + sys.exit(-1) + + fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/spanner_admin_instance/v1/setup.py b/owl-bot-staging/spanner_admin_instance/v1/setup.py new file mode 100644 index 0000000000..4d627f7a23 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/setup.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import io +import os + +import setuptools # type: ignore + +package_root = os.path.abspath(os.path.dirname(__file__)) + +name = 'google-cloud-spanner-admin-instance' + + +description = "Google Cloud Spanner Admin Instance API client library" + +version = {} +with open(os.path.join(package_root, 'google/cloud/spanner_admin_instance/gapic_version.py')) as fp: + exec(fp.read(), version) +version = version["__version__"] + +if version[0] == "0": + release_status = "Development Status :: 4 - Beta" +else: + release_status = "Development Status :: 5 - Production/Stable" + +dependencies = [ + "google-api-core[grpc] >= 1.34.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", + "proto-plus >= 1.22.0, <2.0.0dev", + "proto-plus >= 1.22.2, <2.0.0dev; python_version>='3.11'", + "protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "grpc-google-iam-v1 >= 0.12.4, <1.0.0dev", +] +url = "https://github.com/googleapis/python-spanner-admin-instance" + +package_root = os.path.abspath(os.path.dirname(__file__)) + +readme_filename = os.path.join(package_root, "README.rst") +with io.open(readme_filename, encoding="utf-8") as readme_file: + readme = readme_file.read() + +packages = [ + package + for package in setuptools.PEP420PackageFinder.find() + if package.startswith("google") +] + +namespaces = ["google", "google.cloud"] + +setuptools.setup( + name=name, + version=version, + description=description, + long_description=readme, + author="Google LLC", + author_email="googleapis-packages@google.com", + license="Apache 2.0", + url=url, + classifiers=[ + release_status, + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Operating System :: OS Independent", + "Topic :: Internet", + ], + platforms="Posix; MacOS X; Windows", + packages=packages, + python_requires=">=3.7", + namespace_packages=namespaces, + install_requires=dependencies, + include_package_data=True, + zip_safe=False, +) diff --git a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.10.txt b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.10.txt new file mode 100644 index 0000000000..ad3f0fa58e --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.10.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.11.txt b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.11.txt new file mode 100644 index 0000000000..ad3f0fa58e --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.11.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.12.txt b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.12.txt new file mode 100644 index 0000000000..ad3f0fa58e --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.12.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.7.txt b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.7.txt new file mode 100644 index 0000000000..2beecf99e0 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.7.txt @@ -0,0 +1,10 @@ +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file. +# Pin the version to the lower bound. +# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", +# Then this file should have google-cloud-foo==1.14.0 +google-api-core==1.34.0 +proto-plus==1.22.0 +protobuf==3.19.5 +grpc-google-iam-v1==0.12.4 diff --git a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.8.txt b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.8.txt new file mode 100644 index 0000000000..ad3f0fa58e --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.8.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.9.txt b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.9.txt new file mode 100644 index 0000000000..ad3f0fa58e --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.9.txt @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +proto-plus +protobuf +grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_instance/v1/tests/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/tests/__init__.py new file mode 100644 index 0000000000..231bc12501 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/tests/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner_admin_instance/v1/tests/unit/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/tests/unit/__init__.py new file mode 100644 index 0000000000..231bc12501 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/tests/unit/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/__init__.py new file mode 100644 index 0000000000..231bc12501 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/__init__.py new file mode 100644 index 0000000000..231bc12501 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/__init__.py @@ -0,0 +1,16 @@ + +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py b/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py new file mode 100644 index 0000000000..24efc63392 --- /dev/null +++ b/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py @@ -0,0 +1,8775 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock # pragma: NO COVER +except ImportError: # pragma: NO COVER + import mock + +import grpc +from grpc.experimental import aio +from collections.abc import Iterable +from google.protobuf import json_format +import json +import math +import pytest +from proto.marshal.rules.dates import DurationRule, TimestampRule +from proto.marshal.rules import wrappers +from requests import Response +from requests import Request, PreparedRequest +from requests.sessions import Session +from google.protobuf import json_format + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import future +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import operation +from google.api_core import operation_async # type: ignore +from google.api_core import operations_v1 +from google.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.spanner_admin_instance_v1.services.instance_admin import InstanceAdminAsyncClient +from google.cloud.spanner_admin_instance_v1.services.instance_admin import InstanceAdminClient +from google.cloud.spanner_admin_instance_v1.services.instance_admin import pagers +from google.cloud.spanner_admin_instance_v1.services.instance_admin import transports +from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from google.oauth2 import service_account +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.type import expr_pb2 # type: ignore +import google.auth + + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert InstanceAdminClient._get_default_mtls_endpoint(None) is None + assert InstanceAdminClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + assert InstanceAdminClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint + assert InstanceAdminClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint + assert InstanceAdminClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint + assert InstanceAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class,transport_name", [ + (InstanceAdminClient, "grpc"), + (InstanceAdminAsyncClient, "grpc_asyncio"), + (InstanceAdminClient, "rest"), +]) +def test_instance_admin_client_from_service_account_info(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info, transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ( + 'spanner.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://spanner.googleapis.com' + ) + + +@pytest.mark.parametrize("transport_class,transport_name", [ + (transports.InstanceAdminGrpcTransport, "grpc"), + (transports.InstanceAdminGrpcAsyncIOTransport, "grpc_asyncio"), + (transports.InstanceAdminRestTransport, "rest"), +]) +def test_instance_admin_client_service_account_always_use_jwt(transport_class, transport_name): + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize("client_class,transport_name", [ + (InstanceAdminClient, "grpc"), + (InstanceAdminAsyncClient, "grpc_asyncio"), + (InstanceAdminClient, "rest"), +]) +def test_instance_admin_client_from_service_account_file(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: + factory.return_value = creds + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ( + 'spanner.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://spanner.googleapis.com' + ) + + +def test_instance_admin_client_get_transport_class(): + transport = InstanceAdminClient.get_transport_class() + available_transports = [ + transports.InstanceAdminGrpcTransport, + transports.InstanceAdminRestTransport, + ] + assert transport in available_transports + + transport = InstanceAdminClient.get_transport_class("grpc") + assert transport == transports.InstanceAdminGrpcTransport + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (InstanceAdminClient, transports.InstanceAdminGrpcTransport, "grpc"), + (InstanceAdminAsyncClient, transports.InstanceAdminGrpcAsyncIOTransport, "grpc_asyncio"), + (InstanceAdminClient, transports.InstanceAdminRestTransport, "rest"), +]) +@mock.patch.object(InstanceAdminClient, "DEFAULT_ENDPOINT", modify_default_endpoint(InstanceAdminClient)) +@mock.patch.object(InstanceAdminAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(InstanceAdminAsyncClient)) +def test_instance_admin_client_client_options(client_class, transport_class, transport_name): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(InstanceAdminClient, 'get_transport_class') as gtc: + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(InstanceAdminClient, 'get_transport_class') as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name, client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class(transport=transport_name) + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): + with pytest.raises(ValueError): + client = client_class(transport=transport_name) + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + # Check the case api_endpoint is provided + options = client_options.ClientOptions(api_audience="https://language.googleapis.com") + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience="https://language.googleapis.com" + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ + (InstanceAdminClient, transports.InstanceAdminGrpcTransport, "grpc", "true"), + (InstanceAdminAsyncClient, transports.InstanceAdminGrpcAsyncIOTransport, "grpc_asyncio", "true"), + (InstanceAdminClient, transports.InstanceAdminGrpcTransport, "grpc", "false"), + (InstanceAdminAsyncClient, transports.InstanceAdminGrpcAsyncIOTransport, "grpc_asyncio", "false"), + (InstanceAdminClient, transports.InstanceAdminRestTransport, "rest", "true"), + (InstanceAdminClient, transports.InstanceAdminRestTransport, "rest", "false"), +]) +@mock.patch.object(InstanceAdminClient, "DEFAULT_ENDPOINT", modify_default_endpoint(InstanceAdminClient)) +@mock.patch.object(InstanceAdminAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(InstanceAdminAsyncClient)) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_instance_admin_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): + with mock.patch.object(transport_class, '__init__') as patched: + with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + +@pytest.mark.parametrize("client_class", [ + InstanceAdminClient, InstanceAdminAsyncClient +]) +@mock.patch.object(InstanceAdminClient, "DEFAULT_ENDPOINT", modify_default_endpoint(InstanceAdminClient)) +@mock.patch.object(InstanceAdminAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(InstanceAdminAsyncClient)) +def test_instance_admin_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): + with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_client_cert_source): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + +@pytest.mark.parametrize("client_class,transport_class,transport_name", [ + (InstanceAdminClient, transports.InstanceAdminGrpcTransport, "grpc"), + (InstanceAdminAsyncClient, transports.InstanceAdminGrpcAsyncIOTransport, "grpc_asyncio"), + (InstanceAdminClient, transports.InstanceAdminRestTransport, "rest"), +]) +def test_instance_admin_client_client_options_scopes(client_class, transport_class, transport_name): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + +@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ + (InstanceAdminClient, transports.InstanceAdminGrpcTransport, "grpc", grpc_helpers), + (InstanceAdminAsyncClient, transports.InstanceAdminGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), + (InstanceAdminClient, transports.InstanceAdminRestTransport, "rest", None), +]) +def test_instance_admin_client_client_options_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + +def test_instance_admin_client_client_options_from_dict(): + with mock.patch('google.cloud.spanner_admin_instance_v1.services.instance_admin.transports.InstanceAdminGrpcTransport.__init__') as grpc_transport: + grpc_transport.return_value = None + client = InstanceAdminClient( + client_options={'api_endpoint': 'squid.clam.whelk'} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + +@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ + (InstanceAdminClient, transports.InstanceAdminGrpcTransport, "grpc", grpc_helpers), + (InstanceAdminAsyncClient, transports.InstanceAdminGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), +]) +def test_instance_admin_client_create_channel_credentials_file(client_class, transport_class, transport_name, grpc_helpers): + # Check the case credentials file is provided. + options = client_options.ClientOptions( + credentials_file="credentials.json" + ) + + with mock.patch.object(transport_class, '__init__') as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "spanner.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.admin', +), + scopes=None, + default_host="spanner.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.ListInstanceConfigsRequest, + dict, +]) +def test_list_instance_configs(request_type, transport: str = 'grpc'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_configs), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.ListInstanceConfigsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_instance_configs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.ListInstanceConfigsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstanceConfigsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_instance_configs_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_configs), + '__call__') as call: + client.list_instance_configs() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.ListInstanceConfigsRequest() + +@pytest.mark.asyncio +async def test_list_instance_configs_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.ListInstanceConfigsRequest): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_configs), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstanceConfigsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_instance_configs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.ListInstanceConfigsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstanceConfigsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_instance_configs_async_from_dict(): + await test_list_instance_configs_async(request_type=dict) + + +def test_list_instance_configs_field_headers(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.ListInstanceConfigsRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_configs), + '__call__') as call: + call.return_value = spanner_instance_admin.ListInstanceConfigsResponse() + client.list_instance_configs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_list_instance_configs_field_headers_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.ListInstanceConfigsRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_configs), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstanceConfigsResponse()) + await client.list_instance_configs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_list_instance_configs_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_configs), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.ListInstanceConfigsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_instance_configs( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + + +def test_list_instance_configs_flattened_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_instance_configs( + spanner_instance_admin.ListInstanceConfigsRequest(), + parent='parent_value', + ) + +@pytest.mark.asyncio +async def test_list_instance_configs_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_configs), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.ListInstanceConfigsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstanceConfigsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_instance_configs( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_list_instance_configs_flattened_error_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_instance_configs( + spanner_instance_admin.ListInstanceConfigsRequest(), + parent='parent_value', + ) + + +def test_list_instance_configs_pager(transport_name: str = "grpc"): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_configs), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_instance_configs(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, spanner_instance_admin.InstanceConfig) + for i in results) +def test_list_instance_configs_pages(transport_name: str = "grpc"): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_configs), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + ], + ), + RuntimeError, + ) + pages = list(client.list_instance_configs(request={}).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.asyncio +async def test_list_instance_configs_async_pager(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_configs), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_instance_configs(request={},) + assert async_pager.next_page_token == 'abc' + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, spanner_instance_admin.InstanceConfig) + for i in responses) + + +@pytest.mark.asyncio +async def test_list_instance_configs_async_pages(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_configs), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_instance_configs(request={})).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.GetInstanceConfigRequest, + dict, +]) +def test_get_instance_config(request_type, transport: str = 'grpc'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.InstanceConfig( + name='name_value', + display_name='display_name_value', + config_type=spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED, + base_config='base_config_value', + etag='etag_value', + leader_options=['leader_options_value'], + reconciling=True, + state=spanner_instance_admin.InstanceConfig.State.CREATING, + ) + response = client.get_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.GetInstanceConfigRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner_instance_admin.InstanceConfig) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.config_type == spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED + assert response.base_config == 'base_config_value' + assert response.etag == 'etag_value' + assert response.leader_options == ['leader_options_value'] + assert response.reconciling is True + assert response.state == spanner_instance_admin.InstanceConfig.State.CREATING + + +def test_get_instance_config_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_config), + '__call__') as call: + client.get_instance_config() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.GetInstanceConfigRequest() + +@pytest.mark.asyncio +async def test_get_instance_config_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.GetInstanceConfigRequest): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.InstanceConfig( + name='name_value', + display_name='display_name_value', + config_type=spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED, + base_config='base_config_value', + etag='etag_value', + leader_options=['leader_options_value'], + reconciling=True, + state=spanner_instance_admin.InstanceConfig.State.CREATING, + )) + response = await client.get_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.GetInstanceConfigRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner_instance_admin.InstanceConfig) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.config_type == spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED + assert response.base_config == 'base_config_value' + assert response.etag == 'etag_value' + assert response.leader_options == ['leader_options_value'] + assert response.reconciling is True + assert response.state == spanner_instance_admin.InstanceConfig.State.CREATING + + +@pytest.mark.asyncio +async def test_get_instance_config_async_from_dict(): + await test_get_instance_config_async(request_type=dict) + + +def test_get_instance_config_field_headers(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.GetInstanceConfigRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_config), + '__call__') as call: + call.return_value = spanner_instance_admin.InstanceConfig() + client.get_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_get_instance_config_field_headers_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.GetInstanceConfigRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_config), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.InstanceConfig()) + await client.get_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +def test_get_instance_config_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.InstanceConfig() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_instance_config( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + + +def test_get_instance_config_flattened_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_instance_config( + spanner_instance_admin.GetInstanceConfigRequest(), + name='name_value', + ) + +@pytest.mark.asyncio +async def test_get_instance_config_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.InstanceConfig() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.InstanceConfig()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_instance_config( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_get_instance_config_flattened_error_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_instance_config( + spanner_instance_admin.GetInstanceConfigRequest(), + name='name_value', + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.CreateInstanceConfigRequest, + dict, +]) +def test_create_instance_config(request_type, transport: str = 'grpc'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.create_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.CreateInstanceConfigRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_instance_config_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance_config), + '__call__') as call: + client.create_instance_config() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.CreateInstanceConfigRequest() + +@pytest.mark.asyncio +async def test_create_instance_config_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.CreateInstanceConfigRequest): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.create_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.CreateInstanceConfigRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_instance_config_async_from_dict(): + await test_create_instance_config_async(request_type=dict) + + +def test_create_instance_config_field_headers(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.CreateInstanceConfigRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance_config), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.create_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_create_instance_config_field_headers_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.CreateInstanceConfigRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance_config), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.create_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_create_instance_config_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_instance_config( + parent='parent_value', + instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), + instance_config_id='instance_config_id_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + arg = args[0].instance_config + mock_val = spanner_instance_admin.InstanceConfig(name='name_value') + assert arg == mock_val + arg = args[0].instance_config_id + mock_val = 'instance_config_id_value' + assert arg == mock_val + + +def test_create_instance_config_flattened_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_instance_config( + spanner_instance_admin.CreateInstanceConfigRequest(), + parent='parent_value', + instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), + instance_config_id='instance_config_id_value', + ) + +@pytest.mark.asyncio +async def test_create_instance_config_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_instance_config( + parent='parent_value', + instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), + instance_config_id='instance_config_id_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + arg = args[0].instance_config + mock_val = spanner_instance_admin.InstanceConfig(name='name_value') + assert arg == mock_val + arg = args[0].instance_config_id + mock_val = 'instance_config_id_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_create_instance_config_flattened_error_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_instance_config( + spanner_instance_admin.CreateInstanceConfigRequest(), + parent='parent_value', + instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), + instance_config_id='instance_config_id_value', + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.UpdateInstanceConfigRequest, + dict, +]) +def test_update_instance_config(request_type, transport: str = 'grpc'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.update_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.UpdateInstanceConfigRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_instance_config_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance_config), + '__call__') as call: + client.update_instance_config() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.UpdateInstanceConfigRequest() + +@pytest.mark.asyncio +async def test_update_instance_config_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.UpdateInstanceConfigRequest): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.update_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.UpdateInstanceConfigRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_instance_config_async_from_dict(): + await test_update_instance_config_async(request_type=dict) + + +def test_update_instance_config_field_headers(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.UpdateInstanceConfigRequest() + + request.instance_config.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance_config), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.update_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'instance_config.name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_update_instance_config_field_headers_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.UpdateInstanceConfigRequest() + + request.instance_config.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance_config), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.update_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'instance_config.name=name_value', + ) in kw['metadata'] + + +def test_update_instance_config_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_instance_config( + instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].instance_config + mock_val = spanner_instance_admin.InstanceConfig(name='name_value') + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) + assert arg == mock_val + + +def test_update_instance_config_flattened_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_instance_config( + spanner_instance_admin.UpdateInstanceConfigRequest(), + instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + +@pytest.mark.asyncio +async def test_update_instance_config_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_instance_config( + instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].instance_config + mock_val = spanner_instance_admin.InstanceConfig(name='name_value') + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) + assert arg == mock_val + +@pytest.mark.asyncio +async def test_update_instance_config_flattened_error_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_instance_config( + spanner_instance_admin.UpdateInstanceConfigRequest(), + instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.DeleteInstanceConfigRequest, + dict, +]) +def test_delete_instance_config(request_type, transport: str = 'grpc'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.DeleteInstanceConfigRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_instance_config_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance_config), + '__call__') as call: + client.delete_instance_config() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.DeleteInstanceConfigRequest() + +@pytest.mark.asyncio +async def test_delete_instance_config_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.DeleteInstanceConfigRequest): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.DeleteInstanceConfigRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_instance_config_async_from_dict(): + await test_delete_instance_config_async(request_type=dict) + + +def test_delete_instance_config_field_headers(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.DeleteInstanceConfigRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance_config), + '__call__') as call: + call.return_value = None + client.delete_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_delete_instance_config_field_headers_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.DeleteInstanceConfigRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance_config), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_instance_config(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +def test_delete_instance_config_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_instance_config( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + + +def test_delete_instance_config_flattened_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_instance_config( + spanner_instance_admin.DeleteInstanceConfigRequest(), + name='name_value', + ) + +@pytest.mark.asyncio +async def test_delete_instance_config_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance_config), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_instance_config( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_delete_instance_config_flattened_error_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_instance_config( + spanner_instance_admin.DeleteInstanceConfigRequest(), + name='name_value', + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.ListInstanceConfigOperationsRequest, + dict, +]) +def test_list_instance_config_operations(request_type, transport: str = 'grpc'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse( + next_page_token='next_page_token_value', + ) + response = client.list_instance_config_operations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.ListInstanceConfigOperationsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstanceConfigOperationsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_instance_config_operations_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), + '__call__') as call: + client.list_instance_config_operations() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.ListInstanceConfigOperationsRequest() + +@pytest.mark.asyncio +async def test_list_instance_config_operations_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.ListInstanceConfigOperationsRequest): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstanceConfigOperationsResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_instance_config_operations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.ListInstanceConfigOperationsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstanceConfigOperationsAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_instance_config_operations_async_from_dict(): + await test_list_instance_config_operations_async(request_type=dict) + + +def test_list_instance_config_operations_field_headers(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.ListInstanceConfigOperationsRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), + '__call__') as call: + call.return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse() + client.list_instance_config_operations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_list_instance_config_operations_field_headers_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.ListInstanceConfigOperationsRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstanceConfigOperationsResponse()) + await client.list_instance_config_operations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_list_instance_config_operations_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_instance_config_operations( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + + +def test_list_instance_config_operations_flattened_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_instance_config_operations( + spanner_instance_admin.ListInstanceConfigOperationsRequest(), + parent='parent_value', + ) + +@pytest.mark.asyncio +async def test_list_instance_config_operations_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstanceConfigOperationsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_instance_config_operations( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_list_instance_config_operations_flattened_error_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_instance_config_operations( + spanner_instance_admin.ListInstanceConfigOperationsRequest(), + parent='parent_value', + ) + + +def test_list_instance_config_operations_pager(transport_name: str = "grpc"): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_instance_config_operations(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, operations_pb2.Operation) + for i in results) +def test_list_instance_config_operations_pages(transport_name: str = "grpc"): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + pages = list(client.list_instance_config_operations(request={}).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.asyncio +async def test_list_instance_config_operations_async_pager(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_instance_config_operations(request={},) + assert async_pager.next_page_token == 'abc' + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, operations_pb2.Operation) + for i in responses) + + +@pytest.mark.asyncio +async def test_list_instance_config_operations_async_pages(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instance_config_operations), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_instance_config_operations(request={})).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.ListInstancesRequest, + dict, +]) +def test_list_instances(request_type, transport: str = 'grpc'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instances), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.ListInstancesResponse( + next_page_token='next_page_token_value', + ) + response = client.list_instances(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.ListInstancesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstancesPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_instances_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instances), + '__call__') as call: + client.list_instances() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.ListInstancesRequest() + +@pytest.mark.asyncio +async def test_list_instances_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.ListInstancesRequest): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instances), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstancesResponse( + next_page_token='next_page_token_value', + )) + response = await client.list_instances(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.ListInstancesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstancesAsyncPager) + assert response.next_page_token == 'next_page_token_value' + + +@pytest.mark.asyncio +async def test_list_instances_async_from_dict(): + await test_list_instances_async(request_type=dict) + + +def test_list_instances_field_headers(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.ListInstancesRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instances), + '__call__') as call: + call.return_value = spanner_instance_admin.ListInstancesResponse() + client.list_instances(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_list_instances_field_headers_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.ListInstancesRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instances), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstancesResponse()) + await client.list_instances(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_list_instances_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instances), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.ListInstancesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_instances( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + + +def test_list_instances_flattened_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_instances( + spanner_instance_admin.ListInstancesRequest(), + parent='parent_value', + ) + +@pytest.mark.asyncio +async def test_list_instances_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instances), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.ListInstancesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstancesResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_instances( + parent='parent_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_list_instances_flattened_error_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_instances( + spanner_instance_admin.ListInstancesRequest(), + parent='parent_value', + ) + + +def test_list_instances_pager(transport_name: str = "grpc"): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instances), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata(( + ('parent', ''), + )), + ) + pager = client.list_instances(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, spanner_instance_admin.Instance) + for i in results) +def test_list_instances_pages(transport_name: str = "grpc"): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instances), + '__call__') as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + ], + ), + RuntimeError, + ) + pages = list(client.list_instances(request={}).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.asyncio +async def test_list_instances_async_pager(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instances), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_instances(request={},) + assert async_pager.next_page_token == 'abc' + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, spanner_instance_admin.Instance) + for i in responses) + + +@pytest.mark.asyncio +async def test_list_instances_async_pages(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_instances), + '__call__', new_callable=mock.AsyncMock) as call: + # Set the response to a series of pages. + call.side_effect = ( + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_instances(request={})).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.GetInstanceRequest, + dict, +]) +def test_get_instance(request_type, transport: str = 'grpc'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.Instance( + name='name_value', + config='config_value', + display_name='display_name_value', + node_count=1070, + processing_units=1743, + state=spanner_instance_admin.Instance.State.CREATING, + endpoint_uris=['endpoint_uris_value'], + ) + response = client.get_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.GetInstanceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner_instance_admin.Instance) + assert response.name == 'name_value' + assert response.config == 'config_value' + assert response.display_name == 'display_name_value' + assert response.node_count == 1070 + assert response.processing_units == 1743 + assert response.state == spanner_instance_admin.Instance.State.CREATING + assert response.endpoint_uris == ['endpoint_uris_value'] + + +def test_get_instance_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance), + '__call__') as call: + client.get_instance() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.GetInstanceRequest() + +@pytest.mark.asyncio +async def test_get_instance_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.GetInstanceRequest): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.Instance( + name='name_value', + config='config_value', + display_name='display_name_value', + node_count=1070, + processing_units=1743, + state=spanner_instance_admin.Instance.State.CREATING, + endpoint_uris=['endpoint_uris_value'], + )) + response = await client.get_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.GetInstanceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner_instance_admin.Instance) + assert response.name == 'name_value' + assert response.config == 'config_value' + assert response.display_name == 'display_name_value' + assert response.node_count == 1070 + assert response.processing_units == 1743 + assert response.state == spanner_instance_admin.Instance.State.CREATING + assert response.endpoint_uris == ['endpoint_uris_value'] + + +@pytest.mark.asyncio +async def test_get_instance_async_from_dict(): + await test_get_instance_async(request_type=dict) + + +def test_get_instance_field_headers(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.GetInstanceRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance), + '__call__') as call: + call.return_value = spanner_instance_admin.Instance() + client.get_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_get_instance_field_headers_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.GetInstanceRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.Instance()) + await client.get_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +def test_get_instance_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.Instance() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_instance( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + + +def test_get_instance_flattened_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_instance( + spanner_instance_admin.GetInstanceRequest(), + name='name_value', + ) + +@pytest.mark.asyncio +async def test_get_instance_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = spanner_instance_admin.Instance() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.Instance()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_instance( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_get_instance_flattened_error_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_instance( + spanner_instance_admin.GetInstanceRequest(), + name='name_value', + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.CreateInstanceRequest, + dict, +]) +def test_create_instance(request_type, transport: str = 'grpc'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.create_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.CreateInstanceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_instance_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance), + '__call__') as call: + client.create_instance() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.CreateInstanceRequest() + +@pytest.mark.asyncio +async def test_create_instance_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.CreateInstanceRequest): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.create_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.CreateInstanceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_instance_async_from_dict(): + await test_create_instance_async(request_type=dict) + + +def test_create_instance_field_headers(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.CreateInstanceRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.create_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_create_instance_field_headers_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.CreateInstanceRequest() + + request.parent = 'parent_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.create_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'parent=parent_value', + ) in kw['metadata'] + + +def test_create_instance_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_instance( + parent='parent_value', + instance_id='instance_id_value', + instance=spanner_instance_admin.Instance(name='name_value'), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + arg = args[0].instance_id + mock_val = 'instance_id_value' + assert arg == mock_val + arg = args[0].instance + mock_val = spanner_instance_admin.Instance(name='name_value') + assert arg == mock_val + + +def test_create_instance_flattened_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_instance( + spanner_instance_admin.CreateInstanceRequest(), + parent='parent_value', + instance_id='instance_id_value', + instance=spanner_instance_admin.Instance(name='name_value'), + ) + +@pytest.mark.asyncio +async def test_create_instance_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_instance( + parent='parent_value', + instance_id='instance_id_value', + instance=spanner_instance_admin.Instance(name='name_value'), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = 'parent_value' + assert arg == mock_val + arg = args[0].instance_id + mock_val = 'instance_id_value' + assert arg == mock_val + arg = args[0].instance + mock_val = spanner_instance_admin.Instance(name='name_value') + assert arg == mock_val + +@pytest.mark.asyncio +async def test_create_instance_flattened_error_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_instance( + spanner_instance_admin.CreateInstanceRequest(), + parent='parent_value', + instance_id='instance_id_value', + instance=spanner_instance_admin.Instance(name='name_value'), + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.UpdateInstanceRequest, + dict, +]) +def test_update_instance(request_type, transport: str = 'grpc'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/spam') + response = client.update_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.UpdateInstanceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_instance_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance), + '__call__') as call: + client.update_instance() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.UpdateInstanceRequest() + +@pytest.mark.asyncio +async def test_update_instance_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.UpdateInstanceRequest): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + response = await client.update_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.UpdateInstanceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_instance_async_from_dict(): + await test_update_instance_async(request_type=dict) + + +def test_update_instance_field_headers(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.UpdateInstanceRequest() + + request.instance.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance), + '__call__') as call: + call.return_value = operations_pb2.Operation(name='operations/op') + client.update_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'instance.name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_update_instance_field_headers_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.UpdateInstanceRequest() + + request.instance.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) + await client.update_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'instance.name=name_value', + ) in kw['metadata'] + + +def test_update_instance_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_instance( + instance=spanner_instance_admin.Instance(name='name_value'), + field_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].instance + mock_val = spanner_instance_admin.Instance(name='name_value') + assert arg == mock_val + arg = args[0].field_mask + mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) + assert arg == mock_val + + +def test_update_instance_flattened_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_instance( + spanner_instance_admin.UpdateInstanceRequest(), + instance=spanner_instance_admin.Instance(name='name_value'), + field_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + +@pytest.mark.asyncio +async def test_update_instance_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name='operations/op') + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name='operations/spam') + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_instance( + instance=spanner_instance_admin.Instance(name='name_value'), + field_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].instance + mock_val = spanner_instance_admin.Instance(name='name_value') + assert arg == mock_val + arg = args[0].field_mask + mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) + assert arg == mock_val + +@pytest.mark.asyncio +async def test_update_instance_flattened_error_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_instance( + spanner_instance_admin.UpdateInstanceRequest(), + instance=spanner_instance_admin.Instance(name='name_value'), + field_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.DeleteInstanceRequest, + dict, +]) +def test_delete_instance(request_type, transport: str = 'grpc'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.DeleteInstanceRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_instance_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance), + '__call__') as call: + client.delete_instance() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.DeleteInstanceRequest() + +@pytest.mark.asyncio +async def test_delete_instance_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.DeleteInstanceRequest): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_instance_admin.DeleteInstanceRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_instance_async_from_dict(): + await test_delete_instance_async(request_type=dict) + + +def test_delete_instance_field_headers(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.DeleteInstanceRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance), + '__call__') as call: + call.return_value = None + client.delete_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_delete_instance_field_headers_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_instance_admin.DeleteInstanceRequest() + + request.name = 'name_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_instance(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'name=name_value', + ) in kw['metadata'] + + +def test_delete_instance_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_instance( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + + +def test_delete_instance_flattened_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_instance( + spanner_instance_admin.DeleteInstanceRequest(), + name='name_value', + ) + +@pytest.mark.asyncio +async def test_delete_instance_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_instance), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_instance( + name='name_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = 'name_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_delete_instance_flattened_error_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_instance( + spanner_instance_admin.DeleteInstanceRequest(), + name='name_value', + ) + + +@pytest.mark.parametrize("request_type", [ + iam_policy_pb2.SetIamPolicyRequest, + dict, +]) +def test_set_iam_policy(request_type, transport: str = 'grpc'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b'etag_blob', + ) + response = client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b'etag_blob' + + +def test_set_iam_policy_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + client.set_iam_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = 'grpc_asyncio', request_type=iam_policy_pb2.SetIamPolicyRequest): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy( + version=774, + etag=b'etag_blob', + )) + response = await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b'etag_blob' + + +@pytest.mark.asyncio +async def test_set_iam_policy_async_from_dict(): + await test_set_iam_policy_async(request_type=dict) + + +def test_set_iam_policy_field_headers(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + + request.resource = 'resource_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + call.return_value = policy_pb2.Policy() + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'resource=resource_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + + request.resource = 'resource_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'resource=resource_value', + ) in kw['metadata'] + +def test_set_iam_policy_from_dict_foreign(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.set_iam_policy(request={ + 'resource': 'resource_value', + 'policy': policy_pb2.Policy(version=774), + 'update_mask': field_mask_pb2.FieldMask(paths=['paths_value']), + } + ) + call.assert_called() + + +def test_set_iam_policy_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.set_iam_policy( + resource='resource_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].resource + mock_val = 'resource_value' + assert arg == mock_val + + +def test_set_iam_policy_flattened_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.set_iam_policy( + iam_policy_pb2.SetIamPolicyRequest(), + resource='resource_value', + ) + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.set_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.set_iam_policy( + resource='resource_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].resource + mock_val = 'resource_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_error_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.set_iam_policy( + iam_policy_pb2.SetIamPolicyRequest(), + resource='resource_value', + ) + + +@pytest.mark.parametrize("request_type", [ + iam_policy_pb2.GetIamPolicyRequest, + dict, +]) +def test_get_iam_policy(request_type, transport: str = 'grpc'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b'etag_blob', + ) + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b'etag_blob' + + +def test_get_iam_policy_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + client.get_iam_policy() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = 'grpc_asyncio', request_type=iam_policy_pb2.GetIamPolicyRequest): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy( + version=774, + etag=b'etag_blob', + )) + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b'etag_blob' + + +@pytest.mark.asyncio +async def test_get_iam_policy_async_from_dict(): + await test_get_iam_policy_async(request_type=dict) + + +def test_get_iam_policy_field_headers(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + + request.resource = 'resource_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + call.return_value = policy_pb2.Policy() + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'resource=resource_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + + request.resource = 'resource_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'resource=resource_value', + ) in kw['metadata'] + +def test_get_iam_policy_from_dict_foreign(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.get_iam_policy(request={ + 'resource': 'resource_value', + 'options': options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_get_iam_policy_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_iam_policy( + resource='resource_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].resource + mock_val = 'resource_value' + assert arg == mock_val + + +def test_get_iam_policy_flattened_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_iam_policy( + iam_policy_pb2.GetIamPolicyRequest(), + resource='resource_value', + ) + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_iam_policy), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_iam_policy( + resource='resource_value', + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].resource + mock_val = 'resource_value' + assert arg == mock_val + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_error_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_iam_policy( + iam_policy_pb2.GetIamPolicyRequest(), + resource='resource_value', + ) + + +@pytest.mark.parametrize("request_type", [ + iam_policy_pb2.TestIamPermissionsRequest, + dict, +]) +def test_test_iam_permissions(request_type, transport: str = 'grpc'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=['permissions_value'], + ) + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + assert response.permissions == ['permissions_value'] + + +def test_test_iam_permissions_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + client.test_iam_permissions() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = 'grpc_asyncio', request_type=iam_policy_pb2.TestIamPermissionsRequest): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(iam_policy_pb2.TestIamPermissionsResponse( + permissions=['permissions_value'], + )) + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + assert response.permissions == ['permissions_value'] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async_from_dict(): + await test_test_iam_permissions_async(request_type=dict) + + +def test_test_iam_permissions_field_headers(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + + request.resource = 'resource_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'resource=resource_value', + ) in kw['metadata'] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + + request.resource = 'resource_value' + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(iam_policy_pb2.TestIamPermissionsResponse()) + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + 'x-goog-request-params', + 'resource=resource_value', + ) in kw['metadata'] + +def test_test_iam_permissions_from_dict_foreign(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + response = client.test_iam_permissions(request={ + 'resource': 'resource_value', + 'permissions': ['permissions_value'], + } + ) + call.assert_called() + + +def test_test_iam_permissions_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.test_iam_permissions( + resource='resource_value', + permissions=['permissions_value'], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].resource + mock_val = 'resource_value' + assert arg == mock_val + arg = args[0].permissions + mock_val = ['permissions_value'] + assert arg == mock_val + + +def test_test_iam_permissions_flattened_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.test_iam_permissions( + iam_policy_pb2.TestIamPermissionsRequest(), + resource='resource_value', + permissions=['permissions_value'], + ) + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), + '__call__') as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(iam_policy_pb2.TestIamPermissionsResponse()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.test_iam_permissions( + resource='resource_value', + permissions=['permissions_value'], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].resource + mock_val = 'resource_value' + assert arg == mock_val + arg = args[0].permissions + mock_val = ['permissions_value'] + assert arg == mock_val + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_error_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.test_iam_permissions( + iam_policy_pb2.TestIamPermissionsRequest(), + resource='resource_value', + permissions=['permissions_value'], + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.ListInstanceConfigsRequest, + dict, +]) +def test_list_instance_configs_rest(request_type): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.ListInstanceConfigsResponse( + next_page_token='next_page_token_value', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_instance_admin.ListInstanceConfigsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.list_instance_configs(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstanceConfigsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_instance_configs_rest_required_fields(request_type=spanner_instance_admin.ListInstanceConfigsRequest): + transport_class = transports.InstanceAdminRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_instance_configs._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_instance_configs._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("page_size", "page_token", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.ListInstanceConfigsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner_instance_admin.ListInstanceConfigsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.list_instance_configs(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_list_instance_configs_rest_unset_required_fields(): + transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.list_instance_configs._get_unset_required_fields({}) + assert set(unset_fields) == (set(("pageSize", "pageToken", )) & set(("parent", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_instance_configs_rest_interceptors(null_interceptor): + transport = transports.InstanceAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), + ) + client = InstanceAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "post_list_instance_configs") as post, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_list_instance_configs") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_instance_admin.ListInstanceConfigsRequest.pb(spanner_instance_admin.ListInstanceConfigsRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner_instance_admin.ListInstanceConfigsResponse.to_json(spanner_instance_admin.ListInstanceConfigsResponse()) + + request = spanner_instance_admin.ListInstanceConfigsRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner_instance_admin.ListInstanceConfigsResponse() + + client.list_instance_configs(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_list_instance_configs_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.ListInstanceConfigsRequest): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.list_instance_configs(request) + + +def test_list_instance_configs_rest_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.ListInstanceConfigsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'projects/sample1'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_instance_admin.ListInstanceConfigsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.list_instance_configs(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{parent=projects/*}/instanceConfigs" % client.transport._host, args[1]) + + +def test_list_instance_configs_rest_flattened_error(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_instance_configs( + spanner_instance_admin.ListInstanceConfigsRequest(), + parent='parent_value', + ) + + +def test_list_instance_configs_rest_pager(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + #with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstanceConfigsResponse( + instance_configs=[ + spanner_instance_admin.InstanceConfig(), + spanner_instance_admin.InstanceConfig(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(spanner_instance_admin.ListInstanceConfigsResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode('UTF-8') + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {'parent': 'projects/sample1'} + + pager = client.list_instance_configs(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, spanner_instance_admin.InstanceConfig) + for i in results) + + pages = list(client.list_instance_configs(request=sample_request).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.GetInstanceConfigRequest, + dict, +]) +def test_get_instance_config_rest(request_type): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instanceConfigs/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.InstanceConfig( + name='name_value', + display_name='display_name_value', + config_type=spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED, + base_config='base_config_value', + etag='etag_value', + leader_options=['leader_options_value'], + reconciling=True, + state=spanner_instance_admin.InstanceConfig.State.CREATING, + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_instance_admin.InstanceConfig.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.get_instance_config(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner_instance_admin.InstanceConfig) + assert response.name == 'name_value' + assert response.display_name == 'display_name_value' + assert response.config_type == spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED + assert response.base_config == 'base_config_value' + assert response.etag == 'etag_value' + assert response.leader_options == ['leader_options_value'] + assert response.reconciling is True + assert response.state == spanner_instance_admin.InstanceConfig.State.CREATING + + +def test_get_instance_config_rest_required_fields(request_type=spanner_instance_admin.GetInstanceConfigRequest): + transport_class = transports.InstanceAdminRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_instance_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = 'name_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_instance_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == 'name_value' + + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.InstanceConfig() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner_instance_admin.InstanceConfig.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.get_instance_config(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_get_instance_config_rest_unset_required_fields(): + transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.get_instance_config._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_instance_config_rest_interceptors(null_interceptor): + transport = transports.InstanceAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), + ) + client = InstanceAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "post_get_instance_config") as post, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_get_instance_config") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_instance_admin.GetInstanceConfigRequest.pb(spanner_instance_admin.GetInstanceConfigRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner_instance_admin.InstanceConfig.to_json(spanner_instance_admin.InstanceConfig()) + + request = spanner_instance_admin.GetInstanceConfigRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner_instance_admin.InstanceConfig() + + client.get_instance_config(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_get_instance_config_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.GetInstanceConfigRequest): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instanceConfigs/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.get_instance_config(request) + + +def test_get_instance_config_rest_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.InstanceConfig() + + # get arguments that satisfy an http rule for this method + sample_request = {'name': 'projects/sample1/instanceConfigs/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + name='name_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_instance_admin.InstanceConfig.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.get_instance_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{name=projects/*/instanceConfigs/*}" % client.transport._host, args[1]) + + +def test_get_instance_config_rest_flattened_error(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_instance_config( + spanner_instance_admin.GetInstanceConfigRequest(), + name='name_value', + ) + + +def test_get_instance_config_rest_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.CreateInstanceConfigRequest, + dict, +]) +def test_create_instance_config_rest(request_type): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.create_instance_config(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_create_instance_config_rest_required_fields(request_type=spanner_instance_admin.CreateInstanceConfigRequest): + transport_class = transports.InstanceAdminRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["instance_config_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_instance_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + jsonified_request["instanceConfigId"] = 'instance_config_id_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_instance_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + assert "instanceConfigId" in jsonified_request + assert jsonified_request["instanceConfigId"] == 'instance_config_id_value' + + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.create_instance_config(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_create_instance_config_rest_unset_required_fields(): + transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.create_instance_config._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("parent", "instanceConfigId", "instanceConfig", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_instance_config_rest_interceptors(null_interceptor): + transport = transports.InstanceAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), + ) + client = InstanceAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(operation.Operation, "_set_result_from_operation"), \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "post_create_instance_config") as post, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_create_instance_config") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_instance_admin.CreateInstanceConfigRequest.pb(spanner_instance_admin.CreateInstanceConfigRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) + + request = spanner_instance_admin.CreateInstanceConfigRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.create_instance_config(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_create_instance_config_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.CreateInstanceConfigRequest): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.create_instance_config(request) + + +def test_create_instance_config_rest_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'projects/sample1'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), + instance_config_id='instance_config_id_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.create_instance_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{parent=projects/*}/instanceConfigs" % client.transport._host, args[1]) + + +def test_create_instance_config_rest_flattened_error(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_instance_config( + spanner_instance_admin.CreateInstanceConfigRequest(), + parent='parent_value', + instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), + instance_config_id='instance_config_id_value', + ) + + +def test_create_instance_config_rest_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.UpdateInstanceConfigRequest, + dict, +]) +def test_update_instance_config_rest(request_type): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'instance_config': {'name': 'projects/sample1/instanceConfigs/sample2'}} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.update_instance_config(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_update_instance_config_rest_required_fields(request_type=spanner_instance_admin.UpdateInstanceConfigRequest): + transport_class = transports.InstanceAdminRestTransport + + request_init = {} + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_instance_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_instance_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "patch", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.update_instance_config(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_update_instance_config_rest_unset_required_fields(): + transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.update_instance_config._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("instanceConfig", "updateMask", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_instance_config_rest_interceptors(null_interceptor): + transport = transports.InstanceAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), + ) + client = InstanceAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(operation.Operation, "_set_result_from_operation"), \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "post_update_instance_config") as post, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_update_instance_config") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_instance_admin.UpdateInstanceConfigRequest.pb(spanner_instance_admin.UpdateInstanceConfigRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) + + request = spanner_instance_admin.UpdateInstanceConfigRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.update_instance_config(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_update_instance_config_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.UpdateInstanceConfigRequest): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'instance_config': {'name': 'projects/sample1/instanceConfigs/sample2'}} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.update_instance_config(request) + + +def test_update_instance_config_rest_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # get arguments that satisfy an http rule for this method + sample_request = {'instance_config': {'name': 'projects/sample1/instanceConfigs/sample2'}} + + # get truthy value for each flattened field + mock_args = dict( + instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.update_instance_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{instance_config.name=projects/*/instanceConfigs/*}" % client.transport._host, args[1]) + + +def test_update_instance_config_rest_flattened_error(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_instance_config( + spanner_instance_admin.UpdateInstanceConfigRequest(), + instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), + update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +def test_update_instance_config_rest_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.DeleteInstanceConfigRequest, + dict, +]) +def test_delete_instance_config_rest(request_type): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instanceConfigs/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.delete_instance_config(request) + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_instance_config_rest_required_fields(request_type=spanner_instance_admin.DeleteInstanceConfigRequest): + transport_class = transports.InstanceAdminRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_instance_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = 'name_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_instance_config._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("etag", "validate_only", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == 'name_value' + + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = None + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "delete", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.delete_instance_config(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_delete_instance_config_rest_unset_required_fields(): + transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.delete_instance_config._get_unset_required_fields({}) + assert set(unset_fields) == (set(("etag", "validateOnly", )) & set(("name", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_instance_config_rest_interceptors(null_interceptor): + transport = transports.InstanceAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), + ) + client = InstanceAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_delete_instance_config") as pre: + pre.assert_not_called() + pb_message = spanner_instance_admin.DeleteInstanceConfigRequest.pb(spanner_instance_admin.DeleteInstanceConfigRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + + request = spanner_instance_admin.DeleteInstanceConfigRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + + client.delete_instance_config(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + + +def test_delete_instance_config_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.DeleteInstanceConfigRequest): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instanceConfigs/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.delete_instance_config(request) + + +def test_delete_instance_config_rest_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # get arguments that satisfy an http rule for this method + sample_request = {'name': 'projects/sample1/instanceConfigs/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + name='name_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.delete_instance_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{name=projects/*/instanceConfigs/*}" % client.transport._host, args[1]) + + +def test_delete_instance_config_rest_flattened_error(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_instance_config( + spanner_instance_admin.DeleteInstanceConfigRequest(), + name='name_value', + ) + + +def test_delete_instance_config_rest_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.ListInstanceConfigOperationsRequest, + dict, +]) +def test_list_instance_config_operations_rest(request_type): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse( + next_page_token='next_page_token_value', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.list_instance_config_operations(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstanceConfigOperationsPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_instance_config_operations_rest_required_fields(request_type=spanner_instance_admin.ListInstanceConfigOperationsRequest): + transport_class = transports.InstanceAdminRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_instance_config_operations._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_instance_config_operations._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("filter", "page_size", "page_token", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.list_instance_config_operations(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_list_instance_config_operations_rest_unset_required_fields(): + transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.list_instance_config_operations._get_unset_required_fields({}) + assert set(unset_fields) == (set(("filter", "pageSize", "pageToken", )) & set(("parent", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_instance_config_operations_rest_interceptors(null_interceptor): + transport = transports.InstanceAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), + ) + client = InstanceAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "post_list_instance_config_operations") as post, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_list_instance_config_operations") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_instance_admin.ListInstanceConfigOperationsRequest.pb(spanner_instance_admin.ListInstanceConfigOperationsRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner_instance_admin.ListInstanceConfigOperationsResponse.to_json(spanner_instance_admin.ListInstanceConfigOperationsResponse()) + + request = spanner_instance_admin.ListInstanceConfigOperationsRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse() + + client.list_instance_config_operations(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_list_instance_config_operations_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.ListInstanceConfigOperationsRequest): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.list_instance_config_operations(request) + + +def test_list_instance_config_operations_rest_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'projects/sample1'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.list_instance_config_operations(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{parent=projects/*}/instanceConfigOperations" % client.transport._host, args[1]) + + +def test_list_instance_config_operations_rest_flattened_error(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_instance_config_operations( + spanner_instance_admin.ListInstanceConfigOperationsRequest(), + parent='parent_value', + ) + + +def test_list_instance_config_operations_rest_pager(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + #with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstanceConfigOperationsResponse( + operations=[ + operations_pb2.Operation(), + operations_pb2.Operation(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(spanner_instance_admin.ListInstanceConfigOperationsResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode('UTF-8') + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {'parent': 'projects/sample1'} + + pager = client.list_instance_config_operations(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, operations_pb2.Operation) + for i in results) + + pages = list(client.list_instance_config_operations(request=sample_request).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.ListInstancesRequest, + dict, +]) +def test_list_instances_rest(request_type): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.ListInstancesResponse( + next_page_token='next_page_token_value', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_instance_admin.ListInstancesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.list_instances(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListInstancesPager) + assert response.next_page_token == 'next_page_token_value' + + +def test_list_instances_rest_required_fields(request_type=spanner_instance_admin.ListInstancesRequest): + transport_class = transports.InstanceAdminRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_instances._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_instances._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("filter", "page_size", "page_token", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.ListInstancesResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner_instance_admin.ListInstancesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.list_instances(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_list_instances_rest_unset_required_fields(): + transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.list_instances._get_unset_required_fields({}) + assert set(unset_fields) == (set(("filter", "pageSize", "pageToken", )) & set(("parent", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_instances_rest_interceptors(null_interceptor): + transport = transports.InstanceAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), + ) + client = InstanceAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "post_list_instances") as post, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_list_instances") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_instance_admin.ListInstancesRequest.pb(spanner_instance_admin.ListInstancesRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner_instance_admin.ListInstancesResponse.to_json(spanner_instance_admin.ListInstancesResponse()) + + request = spanner_instance_admin.ListInstancesRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner_instance_admin.ListInstancesResponse() + + client.list_instances(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_list_instances_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.ListInstancesRequest): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.list_instances(request) + + +def test_list_instances_rest_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.ListInstancesResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'projects/sample1'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_instance_admin.ListInstancesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.list_instances(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{parent=projects/*}/instances" % client.transport._host, args[1]) + + +def test_list_instances_rest_flattened_error(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_instances( + spanner_instance_admin.ListInstancesRequest(), + parent='parent_value', + ) + + +def test_list_instances_rest_pager(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + #with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + ], + next_page_token='abc', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[], + next_page_token='def', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + ], + next_page_token='ghi', + ), + spanner_instance_admin.ListInstancesResponse( + instances=[ + spanner_instance_admin.Instance(), + spanner_instance_admin.Instance(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple(spanner_instance_admin.ListInstancesResponse.to_json(x) for x in response) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode('UTF-8') + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {'parent': 'projects/sample1'} + + pager = client.list_instances(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, spanner_instance_admin.Instance) + for i in results) + + pages = list(client.list_instances(request=sample_request).pages) + for page_, token in zip(pages, ['abc','def','ghi', '']): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.GetInstanceRequest, + dict, +]) +def test_get_instance_rest(request_type): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.Instance( + name='name_value', + config='config_value', + display_name='display_name_value', + node_count=1070, + processing_units=1743, + state=spanner_instance_admin.Instance.State.CREATING, + endpoint_uris=['endpoint_uris_value'], + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_instance_admin.Instance.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.get_instance(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, spanner_instance_admin.Instance) + assert response.name == 'name_value' + assert response.config == 'config_value' + assert response.display_name == 'display_name_value' + assert response.node_count == 1070 + assert response.processing_units == 1743 + assert response.state == spanner_instance_admin.Instance.State.CREATING + assert response.endpoint_uris == ['endpoint_uris_value'] + + +def test_get_instance_rest_required_fields(request_type=spanner_instance_admin.GetInstanceRequest): + transport_class = transports.InstanceAdminRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_instance._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = 'name_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_instance._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("field_mask", )) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == 'name_value' + + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.Instance() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "get", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = spanner_instance_admin.Instance.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.get_instance(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_get_instance_rest_unset_required_fields(): + transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.get_instance._get_unset_required_fields({}) + assert set(unset_fields) == (set(("fieldMask", )) & set(("name", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_instance_rest_interceptors(null_interceptor): + transport = transports.InstanceAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), + ) + client = InstanceAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "post_get_instance") as post, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_get_instance") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_instance_admin.GetInstanceRequest.pb(spanner_instance_admin.GetInstanceRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = spanner_instance_admin.Instance.to_json(spanner_instance_admin.Instance()) + + request = spanner_instance_admin.GetInstanceRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = spanner_instance_admin.Instance() + + client.get_instance(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_get_instance_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.GetInstanceRequest): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.get_instance(request) + + +def test_get_instance_rest_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = spanner_instance_admin.Instance() + + # get arguments that satisfy an http rule for this method + sample_request = {'name': 'projects/sample1/instances/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + name='name_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = spanner_instance_admin.Instance.pb(return_value) + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.get_instance(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{name=projects/*/instances/*}" % client.transport._host, args[1]) + + +def test_get_instance_rest_flattened_error(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_instance( + spanner_instance_admin.GetInstanceRequest(), + name='name_value', + ) + + +def test_get_instance_rest_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.CreateInstanceRequest, + dict, +]) +def test_create_instance_rest(request_type): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.create_instance(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_create_instance_rest_required_fields(request_type=spanner_instance_admin.CreateInstanceRequest): + transport_class = transports.InstanceAdminRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["instance_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_instance._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = 'parent_value' + jsonified_request["instanceId"] = 'instance_id_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_instance._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == 'parent_value' + assert "instanceId" in jsonified_request + assert jsonified_request["instanceId"] == 'instance_id_value' + + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.create_instance(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_create_instance_rest_unset_required_fields(): + transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.create_instance._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("parent", "instanceId", "instance", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_instance_rest_interceptors(null_interceptor): + transport = transports.InstanceAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), + ) + client = InstanceAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(operation.Operation, "_set_result_from_operation"), \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "post_create_instance") as post, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_create_instance") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_instance_admin.CreateInstanceRequest.pb(spanner_instance_admin.CreateInstanceRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) + + request = spanner_instance_admin.CreateInstanceRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.create_instance(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_create_instance_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.CreateInstanceRequest): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'parent': 'projects/sample1'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.create_instance(request) + + +def test_create_instance_rest_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # get arguments that satisfy an http rule for this method + sample_request = {'parent': 'projects/sample1'} + + # get truthy value for each flattened field + mock_args = dict( + parent='parent_value', + instance_id='instance_id_value', + instance=spanner_instance_admin.Instance(name='name_value'), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.create_instance(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{parent=projects/*}/instances" % client.transport._host, args[1]) + + +def test_create_instance_rest_flattened_error(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_instance( + spanner_instance_admin.CreateInstanceRequest(), + parent='parent_value', + instance_id='instance_id_value', + instance=spanner_instance_admin.Instance(name='name_value'), + ) + + +def test_create_instance_rest_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.UpdateInstanceRequest, + dict, +]) +def test_update_instance_rest(request_type): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'instance': {'name': 'projects/sample1/instances/sample2'}} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.update_instance(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_update_instance_rest_required_fields(request_type=spanner_instance_admin.UpdateInstanceRequest): + transport_class = transports.InstanceAdminRestTransport + + request_init = {} + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_instance._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_instance._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "patch", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.update_instance(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_update_instance_rest_unset_required_fields(): + transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.update_instance._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("instance", "fieldMask", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_instance_rest_interceptors(null_interceptor): + transport = transports.InstanceAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), + ) + client = InstanceAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(operation.Operation, "_set_result_from_operation"), \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "post_update_instance") as post, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_update_instance") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_instance_admin.UpdateInstanceRequest.pb(spanner_instance_admin.UpdateInstanceRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) + + request = spanner_instance_admin.UpdateInstanceRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.update_instance(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_update_instance_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.UpdateInstanceRequest): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'instance': {'name': 'projects/sample1/instances/sample2'}} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.update_instance(request) + + +def test_update_instance_rest_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name='operations/spam') + + # get arguments that satisfy an http rule for this method + sample_request = {'instance': {'name': 'projects/sample1/instances/sample2'}} + + # get truthy value for each flattened field + mock_args = dict( + instance=spanner_instance_admin.Instance(name='name_value'), + field_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.update_instance(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{instance.name=projects/*/instances/*}" % client.transport._host, args[1]) + + +def test_update_instance_rest_flattened_error(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_instance( + spanner_instance_admin.UpdateInstanceRequest(), + instance=spanner_instance_admin.Instance(name='name_value'), + field_mask=field_mask_pb2.FieldMask(paths=['paths_value']), + ) + + +def test_update_instance_rest_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + spanner_instance_admin.DeleteInstanceRequest, + dict, +]) +def test_delete_instance_rest(request_type): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.delete_instance(request) + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_instance_rest_required_fields(request_type=spanner_instance_admin.DeleteInstanceRequest): + transport_class = transports.InstanceAdminRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_instance._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = 'name_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_instance._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == 'name_value' + + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = None + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "delete", + 'query_params': pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.delete_instance(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_delete_instance_rest_unset_required_fields(): + transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.delete_instance._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_instance_rest_interceptors(null_interceptor): + transport = transports.InstanceAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), + ) + client = InstanceAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_delete_instance") as pre: + pre.assert_not_called() + pb_message = spanner_instance_admin.DeleteInstanceRequest.pb(spanner_instance_admin.DeleteInstanceRequest()) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + + request = spanner_instance_admin.DeleteInstanceRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + + client.delete_instance(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + + +def test_delete_instance_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.DeleteInstanceRequest): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'name': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.delete_instance(request) + + +def test_delete_instance_rest_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = None + + # get arguments that satisfy an http rule for this method + sample_request = {'name': 'projects/sample1/instances/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + name='name_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = '' + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.delete_instance(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{name=projects/*/instances/*}" % client.transport._host, args[1]) + + +def test_delete_instance_rest_flattened_error(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_instance( + spanner_instance_admin.DeleteInstanceRequest(), + name='name_value', + ) + + +def test_delete_instance_rest_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + iam_policy_pb2.SetIamPolicyRequest, + dict, +]) +def test_set_iam_policy_rest(request_type): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'resource': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = policy_pb2.Policy( + version=774, + etag=b'etag_blob', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.set_iam_policy(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b'etag_blob' + + +def test_set_iam_policy_rest_required_fields(request_type=iam_policy_pb2.SetIamPolicyRequest): + transport_class = transports.InstanceAdminRestTransport + + request_init = {} + request_init["resource"] = "" + request = request_type(**request_init) + pb_request = request + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).set_iam_policy._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["resource"] = 'resource_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).set_iam_policy._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "resource" in jsonified_request + assert jsonified_request["resource"] == 'resource_value' + + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = policy_pb2.Policy() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.set_iam_policy(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_set_iam_policy_rest_unset_required_fields(): + transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.set_iam_policy._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("resource", "policy", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_set_iam_policy_rest_interceptors(null_interceptor): + transport = transports.InstanceAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), + ) + client = InstanceAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "post_set_iam_policy") as post, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_set_iam_policy") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = iam_policy_pb2.SetIamPolicyRequest() + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(policy_pb2.Policy()) + + request = iam_policy_pb2.SetIamPolicyRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = policy_pb2.Policy() + + client.set_iam_policy(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_set_iam_policy_rest_bad_request(transport: str = 'rest', request_type=iam_policy_pb2.SetIamPolicyRequest): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'resource': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.set_iam_policy(request) + + +def test_set_iam_policy_rest_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = policy_pb2.Policy() + + # get arguments that satisfy an http rule for this method + sample_request = {'resource': 'projects/sample1/instances/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + resource='resource_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.set_iam_policy(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{resource=projects/*/instances/*}:setIamPolicy" % client.transport._host, args[1]) + + +def test_set_iam_policy_rest_flattened_error(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.set_iam_policy( + iam_policy_pb2.SetIamPolicyRequest(), + resource='resource_value', + ) + + +def test_set_iam_policy_rest_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + iam_policy_pb2.GetIamPolicyRequest, + dict, +]) +def test_get_iam_policy_rest(request_type): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'resource': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = policy_pb2.Policy( + version=774, + etag=b'etag_blob', + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.get_iam_policy(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 + assert response.etag == b'etag_blob' + + +def test_get_iam_policy_rest_required_fields(request_type=iam_policy_pb2.GetIamPolicyRequest): + transport_class = transports.InstanceAdminRestTransport + + request_init = {} + request_init["resource"] = "" + request = request_type(**request_init) + pb_request = request + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_iam_policy._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["resource"] = 'resource_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_iam_policy._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "resource" in jsonified_request + assert jsonified_request["resource"] == 'resource_value' + + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = policy_pb2.Policy() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.get_iam_policy(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_get_iam_policy_rest_unset_required_fields(): + transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.get_iam_policy._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("resource", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_iam_policy_rest_interceptors(null_interceptor): + transport = transports.InstanceAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), + ) + client = InstanceAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "post_get_iam_policy") as post, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_get_iam_policy") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = iam_policy_pb2.GetIamPolicyRequest() + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(policy_pb2.Policy()) + + request = iam_policy_pb2.GetIamPolicyRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = policy_pb2.Policy() + + client.get_iam_policy(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_get_iam_policy_rest_bad_request(transport: str = 'rest', request_type=iam_policy_pb2.GetIamPolicyRequest): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'resource': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.get_iam_policy(request) + + +def test_get_iam_policy_rest_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = policy_pb2.Policy() + + # get arguments that satisfy an http rule for this method + sample_request = {'resource': 'projects/sample1/instances/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + resource='resource_value', + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.get_iam_policy(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{resource=projects/*/instances/*}:getIamPolicy" % client.transport._host, args[1]) + + +def test_get_iam_policy_rest_flattened_error(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_iam_policy( + iam_policy_pb2.GetIamPolicyRequest(), + resource='resource_value', + ) + + +def test_get_iam_policy_rest_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +@pytest.mark.parametrize("request_type", [ + iam_policy_pb2.TestIamPermissionsRequest, + dict, +]) +def test_test_iam_permissions_rest(request_type): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = {'resource': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=['permissions_value'], + ) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + response = client.test_iam_permissions(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + assert response.permissions == ['permissions_value'] + + +def test_test_iam_permissions_rest_required_fields(request_type=iam_policy_pb2.TestIamPermissionsRequest): + transport_class = transports.InstanceAdminRestTransport + + request_init = {} + request_init["resource"] = "" + request_init["permissions"] = "" + request = request_type(**request_init) + pb_request = request + jsonified_request = json.loads(json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False + )) + + # verify fields with default values are dropped + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).test_iam_permissions._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["resource"] = 'resource_value' + jsonified_request["permissions"] = 'permissions_value' + + unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).test_iam_permissions._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "resource" in jsonified_request + assert jsonified_request["resource"] == 'resource_value' + assert "permissions" in jsonified_request + assert jsonified_request["permissions"] == 'permissions_value' + + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = iam_policy_pb2.TestIamPermissionsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, 'request') as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, 'transcode') as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request + transcode_result = { + 'uri': 'v1/sample_method', + 'method': "post", + 'query_params': pb_request, + } + transcode_result['body'] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + response = client.test_iam_permissions(request) + + expected_params = [ + ('$alt', 'json;enum-encoding=int') + ] + actual_params = req.call_args.kwargs['params'] + assert expected_params == actual_params + + +def test_test_iam_permissions_rest_unset_required_fields(): + transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) + + unset_fields = transport.test_iam_permissions._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("resource", "permissions", ))) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_test_iam_permissions_rest_interceptors(null_interceptor): + transport = transports.InstanceAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), + ) + client = InstanceAdminClient(transport=transport) + with mock.patch.object(type(client.transport._session), "request") as req, \ + mock.patch.object(path_template, "transcode") as transcode, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "post_test_iam_permissions") as post, \ + mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_test_iam_permissions") as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = iam_policy_pb2.TestIamPermissionsRequest() + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson(iam_policy_pb2.TestIamPermissionsResponse()) + + request = iam_policy_pb2.TestIamPermissionsRequest() + metadata =[ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) + + pre.assert_called_once() + post.assert_called_once() + + +def test_test_iam_permissions_rest_bad_request(transport: str = 'rest', request_type=iam_policy_pb2.TestIamPermissionsRequest): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = {'resource': 'projects/sample1/instances/sample2'} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.test_iam_permissions(request) + + +def test_test_iam_permissions_rest_flattened(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), 'request') as req: + # Designate an appropriate value for the returned response. + return_value = iam_policy_pb2.TestIamPermissionsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {'resource': 'projects/sample1/instances/sample2'} + + # get truthy value for each flattened field + mock_args = dict( + resource='resource_value', + permissions=['permissions_value'], + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + pb_return_value = return_value + json_return_value = json_format.MessageToJson(pb_return_value) + response_value._content = json_return_value.encode('UTF-8') + req.return_value = response_value + + client.test_iam_permissions(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate("%s/v1/{resource=projects/*/instances/*}:testIamPermissions" % client.transport._host, args[1]) + + +def test_test_iam_permissions_rest_flattened_error(transport: str = 'rest'): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.test_iam_permissions( + iam_policy_pb2.TestIamPermissionsRequest(), + resource='resource_value', + permissions=['permissions_value'], + ) + + +def test_test_iam_permissions_rest_error(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest' + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.InstanceAdminGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.InstanceAdminGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = InstanceAdminClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.InstanceAdminGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = InstanceAdminClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = InstanceAdminClient( + client_options=options, + credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.InstanceAdminGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = InstanceAdminClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.InstanceAdminGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = InstanceAdminClient(transport=transport) + assert client.transport is transport + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.InstanceAdminGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.InstanceAdminGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + +@pytest.mark.parametrize("transport_class", [ + transports.InstanceAdminGrpcTransport, + transports.InstanceAdminGrpcAsyncIOTransport, + transports.InstanceAdminRestTransport, +]) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "rest", +]) +def test_transport_kind(transport_name): + transport = InstanceAdminClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.InstanceAdminGrpcTransport, + ) + +def test_instance_admin_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.InstanceAdminTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json" + ) + + +def test_instance_admin_base_transport(): + # Instantiate the base transport. + with mock.patch('google.cloud.spanner_admin_instance_v1.services.instance_admin.transports.InstanceAdminTransport.__init__') as Transport: + Transport.return_value = None + transport = transports.InstanceAdminTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + 'list_instance_configs', + 'get_instance_config', + 'create_instance_config', + 'update_instance_config', + 'delete_instance_config', + 'list_instance_config_operations', + 'list_instances', + 'get_instance', + 'create_instance', + 'update_instance', + 'delete_instance', + 'set_iam_policy', + 'get_iam_policy', + 'test_iam_permissions', + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + # Catch all for all remaining methods and properties + remainder = [ + 'kind', + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_instance_admin_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.spanner_admin_instance_v1.services.instance_admin.transports.InstanceAdminTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.InstanceAdminTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with("credentials.json", + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.admin', +), + quota_project_id="octopus", + ) + + +def test_instance_admin_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.cloud.spanner_admin_instance_v1.services.instance_admin.transports.InstanceAdminTransport._prep_wrapped_messages') as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.InstanceAdminTransport() + adc.assert_called_once() + + +def test_instance_admin_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + InstanceAdminClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.admin', +), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.InstanceAdminGrpcTransport, + transports.InstanceAdminGrpcAsyncIOTransport, + ], +) +def test_instance_admin_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/spanner.admin',), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.InstanceAdminGrpcTransport, + transports.InstanceAdminGrpcAsyncIOTransport, + transports.InstanceAdminRestTransport, + ], +) +def test_instance_admin_transport_auth_gdch_credentials(transport_class): + host = 'https://language.com' + api_audience_tests = [None, 'https://language2.com'] + api_audience_expect = [host, 'https://language2.com'] + for t, e in zip(api_audience_tests, api_audience_expect): + with mock.patch.object(google.auth, 'default', autospec=True) as adc: + gdch_mock = mock.MagicMock() + type(gdch_mock).with_gdch_audience = mock.PropertyMock(return_value=gdch_mock) + adc.return_value = (gdch_mock, None) + transport_class(host=host, api_audience=t) + gdch_mock.with_gdch_audience.assert_called_once_with( + e + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.InstanceAdminGrpcTransport, grpc_helpers), + (transports.InstanceAdminGrpcAsyncIOTransport, grpc_helpers_async) + ], +) +def test_instance_admin_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class( + quota_project_id="octopus", + scopes=["1", "2"] + ) + + create_channel.assert_called_with( + "spanner.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/spanner.admin', +), + scopes=["1", "2"], + default_host="spanner.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("transport_class", [transports.InstanceAdminGrpcTransport, transports.InstanceAdminGrpcAsyncIOTransport]) +def test_instance_admin_grpc_transport_client_cert_source_for_mtls( + transport_class +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, + private_key=expected_key + ) + +def test_instance_admin_http_transport_client_cert_source_for_mtls(): + cred = ga_credentials.AnonymousCredentials() + with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel") as mock_configure_mtls_channel: + transports.InstanceAdminRestTransport ( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback + ) + mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) + + +def test_instance_admin_rest_lro_client(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='rest', + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.AbstractOperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", + "rest", +]) +def test_instance_admin_host_no_port(transport_name): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='spanner.googleapis.com'), + transport=transport_name, + ) + assert client.transport._host == ( + 'spanner.googleapis.com:443' + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://spanner.googleapis.com' + ) + +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", + "rest", +]) +def test_instance_admin_host_with_port(transport_name): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions(api_endpoint='spanner.googleapis.com:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + 'spanner.googleapis.com:8000' + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://spanner.googleapis.com:8000' + ) + +@pytest.mark.parametrize("transport_name", [ + "rest", +]) +def test_instance_admin_client_transport_session_collision(transport_name): + creds1 = ga_credentials.AnonymousCredentials() + creds2 = ga_credentials.AnonymousCredentials() + client1 = InstanceAdminClient( + credentials=creds1, + transport=transport_name, + ) + client2 = InstanceAdminClient( + credentials=creds2, + transport=transport_name, + ) + session1 = client1.transport.list_instance_configs._session + session2 = client2.transport.list_instance_configs._session + assert session1 != session2 + session1 = client1.transport.get_instance_config._session + session2 = client2.transport.get_instance_config._session + assert session1 != session2 + session1 = client1.transport.create_instance_config._session + session2 = client2.transport.create_instance_config._session + assert session1 != session2 + session1 = client1.transport.update_instance_config._session + session2 = client2.transport.update_instance_config._session + assert session1 != session2 + session1 = client1.transport.delete_instance_config._session + session2 = client2.transport.delete_instance_config._session + assert session1 != session2 + session1 = client1.transport.list_instance_config_operations._session + session2 = client2.transport.list_instance_config_operations._session + assert session1 != session2 + session1 = client1.transport.list_instances._session + session2 = client2.transport.list_instances._session + assert session1 != session2 + session1 = client1.transport.get_instance._session + session2 = client2.transport.get_instance._session + assert session1 != session2 + session1 = client1.transport.create_instance._session + session2 = client2.transport.create_instance._session + assert session1 != session2 + session1 = client1.transport.update_instance._session + session2 = client2.transport.update_instance._session + assert session1 != session2 + session1 = client1.transport.delete_instance._session + session2 = client2.transport.delete_instance._session + assert session1 != session2 + session1 = client1.transport.set_iam_policy._session + session2 = client2.transport.set_iam_policy._session + assert session1 != session2 + session1 = client1.transport.get_iam_policy._session + session2 = client2.transport.get_iam_policy._session + assert session1 != session2 + session1 = client1.transport.test_iam_permissions._session + session2 = client2.transport.test_iam_permissions._session + assert session1 != session2 +def test_instance_admin_grpc_transport_channel(): + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.InstanceAdminGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_instance_admin_grpc_asyncio_transport_channel(): + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.InstanceAdminGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.InstanceAdminGrpcTransport, transports.InstanceAdminGrpcAsyncIOTransport]) +def test_instance_admin_transport_channel_mtls_with_client_cert_source( + transport_class +): + with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, 'default') as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize("transport_class", [transports.InstanceAdminGrpcTransport, transports.InstanceAdminGrpcAsyncIOTransport]) +def test_instance_admin_transport_channel_mtls_with_adc( + transport_class +): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_instance_admin_grpc_lro_client(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc', + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_instance_admin_grpc_lro_async_client(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport='grpc_asyncio', + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_instance_path(): + project = "squid" + instance = "clam" + expected = "projects/{project}/instances/{instance}".format(project=project, instance=instance, ) + actual = InstanceAdminClient.instance_path(project, instance) + assert expected == actual + + +def test_parse_instance_path(): + expected = { + "project": "whelk", + "instance": "octopus", + } + path = InstanceAdminClient.instance_path(**expected) + + # Check that the path construction is reversible. + actual = InstanceAdminClient.parse_instance_path(path) + assert expected == actual + +def test_instance_config_path(): + project = "oyster" + instance_config = "nudibranch" + expected = "projects/{project}/instanceConfigs/{instance_config}".format(project=project, instance_config=instance_config, ) + actual = InstanceAdminClient.instance_config_path(project, instance_config) + assert expected == actual + + +def test_parse_instance_config_path(): + expected = { + "project": "cuttlefish", + "instance_config": "mussel", + } + path = InstanceAdminClient.instance_config_path(**expected) + + # Check that the path construction is reversible. + actual = InstanceAdminClient.parse_instance_config_path(path) + assert expected == actual + +def test_common_billing_account_path(): + billing_account = "winkle" + expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) + actual = InstanceAdminClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nautilus", + } + path = InstanceAdminClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = InstanceAdminClient.parse_common_billing_account_path(path) + assert expected == actual + +def test_common_folder_path(): + folder = "scallop" + expected = "folders/{folder}".format(folder=folder, ) + actual = InstanceAdminClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "abalone", + } + path = InstanceAdminClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = InstanceAdminClient.parse_common_folder_path(path) + assert expected == actual + +def test_common_organization_path(): + organization = "squid" + expected = "organizations/{organization}".format(organization=organization, ) + actual = InstanceAdminClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "clam", + } + path = InstanceAdminClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = InstanceAdminClient.parse_common_organization_path(path) + assert expected == actual + +def test_common_project_path(): + project = "whelk" + expected = "projects/{project}".format(project=project, ) + actual = InstanceAdminClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "octopus", + } + path = InstanceAdminClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = InstanceAdminClient.parse_common_project_path(path) + assert expected == actual + +def test_common_location_path(): + project = "oyster" + location = "nudibranch" + expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) + actual = InstanceAdminClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "cuttlefish", + "location": "mussel", + } + path = InstanceAdminClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = InstanceAdminClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object(transports.InstanceAdminTransport, '_prep_wrapped_messages') as prep: + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object(transports.InstanceAdminTransport, '_prep_wrapped_messages') as prep: + transport_class = InstanceAdminClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = InstanceAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "rest": "_session", + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: + with client: + close.assert_not_called() + close.assert_called_once() + +def test_client_ctx(): + transports = [ + 'rest', + 'grpc', + ] + for transport in transports: + client = InstanceAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + +@pytest.mark.parametrize("client_class,transport_class", [ + (InstanceAdminClient, transports.InstanceAdminGrpcTransport), + (InstanceAdminAsyncClient, transports.InstanceAdminGrpcAsyncIOTransport), +]) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + api_audience=None, + ) From 29e481f965f1869b8f18ba7065ed744a2e7fd216 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 12 May 2023 08:50:42 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../spanner_admin_database_v1/__init__.py | 4 + .../gapic_metadata.json | 15 + .../services/database_admin/async_client.py | 182 + .../services/database_admin/client.py | 172 + .../database_admin/transports/base.py | 24 + .../database_admin/transports/grpc.py | 65 + .../database_admin/transports/grpc_asyncio.py | 66 + .../database_admin/transports/rest.py | 140 + .../types/__init__.py | 4 + .../types/spanner_database_admin.py | 80 + owl-bot-staging/spanner/v1/.coveragerc | 13 - owl-bot-staging/spanner/v1/.flake8 | 33 - owl-bot-staging/spanner/v1/MANIFEST.in | 2 - owl-bot-staging/spanner/v1/README.rst | 49 - owl-bot-staging/spanner/v1/docs/conf.py | 376 - owl-bot-staging/spanner/v1/docs/index.rst | 7 - .../spanner/v1/docs/spanner_v1/services.rst | 6 - .../spanner/v1/docs/spanner_v1/spanner.rst | 10 - .../spanner/v1/docs/spanner_v1/types.rst | 6 - .../v1/google/cloud/spanner/__init__.py | 103 - .../v1/google/cloud/spanner/gapic_version.py | 16 - .../spanner/v1/google/cloud/spanner/py.typed | 2 - .../v1/google/cloud/spanner_v1/__init__.py | 104 - .../cloud/spanner_v1/gapic_metadata.json | 253 - .../google/cloud/spanner_v1/gapic_version.py | 16 - .../v1/google/cloud/spanner_v1/py.typed | 2 - .../cloud/spanner_v1/services/__init__.py | 15 - .../spanner_v1/services/spanner/__init__.py | 22 - .../services/spanner/async_client.py | 1920 --- .../spanner_v1/services/spanner/client.py | 2062 --- .../spanner_v1/services/spanner/pagers.py | 139 - .../services/spanner/transports/__init__.py | 38 - .../services/spanner/transports/base.py | 427 - .../services/spanner/transports/grpc.py | 766 - .../spanner/transports/grpc_asyncio.py | 765 - .../services/spanner/transports/rest.py | 1973 --- .../google/cloud/spanner_v1/types/__init__.py | 110 - .../cloud/spanner_v1/types/commit_response.py | 79 - .../v1/google/cloud/spanner_v1/types/keys.py | 248 - .../google/cloud/spanner_v1/types/mutation.py | 201 - .../cloud/spanner_v1/types/query_plan.py | 219 - .../cloud/spanner_v1/types/result_set.py | 341 - .../google/cloud/spanner_v1/types/spanner.py | 1327 -- .../cloud/spanner_v1/types/transaction.py | 673 - .../v1/google/cloud/spanner_v1/types/type.py | 248 - owl-bot-staging/spanner/v1/mypy.ini | 3 - owl-bot-staging/spanner/v1/noxfile.py | 184 - .../snippet_metadata_google.spanner.v1.json | 2410 --- ...ted_spanner_batch_create_sessions_async.py | 53 - ...ated_spanner_batch_create_sessions_sync.py | 53 - ...nerated_spanner_begin_transaction_async.py | 52 - ...enerated_spanner_begin_transaction_sync.py | 52 - ...anner_v1_generated_spanner_commit_async.py | 53 - ...panner_v1_generated_spanner_commit_sync.py | 53 - ..._generated_spanner_create_session_async.py | 52 - ...1_generated_spanner_create_session_sync.py | 52 - ..._generated_spanner_delete_session_async.py | 50 - ...1_generated_spanner_delete_session_sync.py | 50 - ...nerated_spanner_execute_batch_dml_async.py | 57 - ...enerated_spanner_execute_batch_dml_sync.py | 57 - ..._v1_generated_spanner_execute_sql_async.py | 53 - ...r_v1_generated_spanner_execute_sql_sync.py | 53 - ...ted_spanner_execute_streaming_sql_async.py | 54 - ...ated_spanner_execute_streaming_sql_sync.py | 54 - ..._v1_generated_spanner_get_session_async.py | 52 - ...r_v1_generated_spanner_get_session_sync.py | 52 - ...1_generated_spanner_list_sessions_async.py | 53 - ...v1_generated_spanner_list_sessions_sync.py | 53 - ...generated_spanner_partition_query_async.py | 53 - ..._generated_spanner_partition_query_sync.py | 53 - ..._generated_spanner_partition_read_async.py | 53 - ...1_generated_spanner_partition_read_sync.py | 53 - ...spanner_v1_generated_spanner_read_async.py | 54 - .../spanner_v1_generated_spanner_read_sync.py | 54 - ...ner_v1_generated_spanner_rollback_async.py | 51 - ...nner_v1_generated_spanner_rollback_sync.py | 51 - ..._generated_spanner_streaming_read_async.py | 55 - ...1_generated_spanner_streaming_read_sync.py | 55 - .../v1/scripts/fixup_spanner_v1_keywords.py | 190 - owl-bot-staging/spanner/v1/setup.py | 90 - .../spanner/v1/testing/constraints-3.10.txt | 6 - .../spanner/v1/testing/constraints-3.11.txt | 6 - .../spanner/v1/testing/constraints-3.12.txt | 6 - .../spanner/v1/testing/constraints-3.7.txt | 9 - .../spanner/v1/testing/constraints-3.8.txt | 6 - .../spanner/v1/testing/constraints-3.9.txt | 6 - owl-bot-staging/spanner/v1/tests/__init__.py | 16 - .../spanner/v1/tests/unit/__init__.py | 16 - .../spanner/v1/tests/unit/gapic/__init__.py | 16 - .../tests/unit/gapic/spanner_v1/__init__.py | 16 - .../unit/gapic/spanner_v1/test_spanner.py | 7665 --------- .../spanner_admin_database/v1/.coveragerc | 13 - .../spanner_admin_database/v1/.flake8 | 33 - .../spanner_admin_database/v1/MANIFEST.in | 2 - .../spanner_admin_database/v1/README.rst | 49 - .../spanner_admin_database/v1/docs/conf.py | 376 - .../spanner_admin_database/v1/docs/index.rst | 7 - .../database_admin.rst | 10 - .../spanner_admin_database_v1/services.rst | 6 - .../docs/spanner_admin_database_v1/types.rst | 6 - .../cloud/spanner_admin_database/__init__.py | 113 - .../spanner_admin_database/gapic_version.py | 16 - .../cloud/spanner_admin_database/py.typed | 2 - .../spanner_admin_database_v1/__init__.py | 114 - .../gapic_metadata.json | 328 - .../gapic_version.py | 16 - .../cloud/spanner_admin_database_v1/py.typed | 2 - .../services/__init__.py | 15 - .../services/database_admin/__init__.py | 22 - .../services/database_admin/async_client.py | 3146 ---- .../services/database_admin/client.py | 3296 ---- .../services/database_admin/pagers.py | 625 - .../database_admin/transports/__init__.py | 38 - .../database_admin/transports/base.py | 562 - .../database_admin/transports/grpc.py | 1015 -- .../database_admin/transports/grpc_asyncio.py | 1014 -- .../database_admin/transports/rest.py | 3132 ---- .../types/__init__.py | 110 - .../spanner_admin_database_v1/types/backup.py | 906 -- .../spanner_admin_database_v1/types/common.py | 155 - .../types/spanner_database_admin.py | 1059 -- .../spanner_admin_database/v1/mypy.ini | 3 - .../spanner_admin_database/v1/noxfile.py | 184 - ...data_google.spanner.admin.database.v1.json | 3319 ---- ...erated_database_admin_copy_backup_async.py | 58 - ...nerated_database_admin_copy_backup_sync.py | 58 - ...ated_database_admin_create_backup_async.py | 57 - ...rated_database_admin_create_backup_sync.py | 57 - ...ed_database_admin_create_database_async.py | 57 - ...ted_database_admin_create_database_sync.py | 57 - ...ated_database_admin_delete_backup_async.py | 50 - ...rated_database_admin_delete_backup_sync.py | 50 - ...ated_database_admin_drop_database_async.py | 50 - ...rated_database_admin_drop_database_sync.py | 50 - ...nerated_database_admin_get_backup_async.py | 52 - ...enerated_database_admin_get_backup_sync.py | 52 - ...rated_database_admin_get_database_async.py | 52 - ...d_database_admin_get_database_ddl_async.py | 52 - ...ed_database_admin_get_database_ddl_sync.py | 52 - ...erated_database_admin_get_database_sync.py | 52 - ...ted_database_admin_get_iam_policy_async.py | 53 - ...ated_database_admin_get_iam_policy_sync.py | 53 - ...base_admin_list_backup_operations_async.py | 53 - ...abase_admin_list_backup_operations_sync.py | 53 - ...rated_database_admin_list_backups_async.py | 53 - ...erated_database_admin_list_backups_sync.py | 53 - ...se_admin_list_database_operations_async.py | 53 - ...ase_admin_list_database_operations_sync.py | 53 - ...atabase_admin_list_database_roles_async.py | 53 - ...database_admin_list_database_roles_sync.py | 53 - ...ted_database_admin_list_databases_async.py | 53 - ...ated_database_admin_list_databases_sync.py | 53 - ...d_database_admin_restore_database_async.py | 58 - ...ed_database_admin_restore_database_sync.py | 58 - ...ted_database_admin_set_iam_policy_async.py | 53 - ...ated_database_admin_set_iam_policy_sync.py | 53 - ...tabase_admin_test_iam_permissions_async.py | 54 - ...atabase_admin_test_iam_permissions_sync.py | 54 - ...ated_database_admin_update_backup_async.py | 51 - ...rated_database_admin_update_backup_sync.py | 51 - ...atabase_admin_update_database_ddl_async.py | 57 - ...database_admin_update_database_ddl_sync.py | 57 - ...ixup_spanner_admin_database_v1_keywords.py | 195 - .../spanner_admin_database/v1/setup.py | 91 - .../v1/testing/constraints-3.10.txt | 7 - .../v1/testing/constraints-3.11.txt | 7 - .../v1/testing/constraints-3.12.txt | 7 - .../v1/testing/constraints-3.7.txt | 10 - .../v1/testing/constraints-3.8.txt | 7 - .../v1/testing/constraints-3.9.txt | 7 - .../v1/tests/__init__.py | 16 - .../v1/tests/unit/__init__.py | 16 - .../v1/tests/unit/gapic/__init__.py | 16 - .../spanner_admin_database_v1/__init__.py | 16 - .../test_database_admin.py | 12988 ---------------- .../spanner_admin_instance/v1/.coveragerc | 13 - .../spanner_admin_instance/v1/.flake8 | 33 - .../spanner_admin_instance/v1/MANIFEST.in | 2 - .../spanner_admin_instance/v1/README.rst | 49 - .../spanner_admin_instance/v1/docs/conf.py | 376 - .../spanner_admin_instance/v1/docs/index.rst | 7 - .../instance_admin.rst | 10 - .../spanner_admin_instance_v1/services.rst | 6 - .../docs/spanner_admin_instance_v1/types.rst | 6 - .../cloud/spanner_admin_instance/__init__.py | 71 - .../spanner_admin_instance/gapic_version.py | 16 - .../cloud/spanner_admin_instance/py.typed | 2 - .../spanner_admin_instance_v1/__init__.py | 72 - .../gapic_metadata.json | 238 - .../gapic_version.py | 16 - .../cloud/spanner_admin_instance_v1/py.typed | 2 - .../services/__init__.py | 15 - .../services/instance_admin/__init__.py | 22 - .../services/instance_admin/async_client.py | 2221 --- .../services/instance_admin/client.py | 2391 --- .../services/instance_admin/pagers.py | 382 - .../instance_admin/transports/__init__.py | 38 - .../instance_admin/transports/base.py | 383 - .../instance_admin/transports/grpc.py | 861 - .../instance_admin/transports/grpc_asyncio.py | 860 - .../instance_admin/transports/rest.py | 2003 --- .../types/__init__.py | 66 - .../spanner_admin_instance_v1/types/common.py | 64 - .../types/spanner_instance_admin.py | 1128 -- .../spanner_admin_instance/v1/mypy.ini | 3 - .../spanner_admin_instance/v1/noxfile.py | 184 - ...data_google.spanner.admin.instance.v1.json | 2313 --- ...ed_instance_admin_create_instance_async.py | 63 - ...ance_admin_create_instance_config_async.py | 57 - ...tance_admin_create_instance_config_sync.py | 57 - ...ted_instance_admin_create_instance_sync.py | 63 - ...ed_instance_admin_delete_instance_async.py | 50 - ...ance_admin_delete_instance_config_async.py | 50 - ...tance_admin_delete_instance_config_sync.py | 50 - ...ted_instance_admin_delete_instance_sync.py | 50 - ...ted_instance_admin_get_iam_policy_async.py | 53 - ...ated_instance_admin_get_iam_policy_sync.py | 53 - ...rated_instance_admin_get_instance_async.py | 52 - ...nstance_admin_get_instance_config_async.py | 52 - ...instance_admin_get_instance_config_sync.py | 52 - ...erated_instance_admin_get_instance_sync.py | 52 - ...n_list_instance_config_operations_async.py | 53 - ...in_list_instance_config_operations_sync.py | 53 - ...tance_admin_list_instance_configs_async.py | 53 - ...stance_admin_list_instance_configs_sync.py | 53 - ...ted_instance_admin_list_instances_async.py | 53 - ...ated_instance_admin_list_instances_sync.py | 53 - ...ted_instance_admin_set_iam_policy_async.py | 53 - ...ated_instance_admin_set_iam_policy_sync.py | 53 - ...stance_admin_test_iam_permissions_async.py | 54 - ...nstance_admin_test_iam_permissions_sync.py | 54 - ...ed_instance_admin_update_instance_async.py | 61 - ...ance_admin_update_instance_config_async.py | 55 - ...tance_admin_update_instance_config_sync.py | 55 - ...ted_instance_admin_update_instance_sync.py | 61 - ...ixup_spanner_admin_instance_v1_keywords.py | 189 - .../spanner_admin_instance/v1/setup.py | 91 - .../v1/testing/constraints-3.10.txt | 7 - .../v1/testing/constraints-3.11.txt | 7 - .../v1/testing/constraints-3.12.txt | 7 - .../v1/testing/constraints-3.7.txt | 10 - .../v1/testing/constraints-3.8.txt | 7 - .../v1/testing/constraints-3.9.txt | 7 - .../v1/tests/__init__.py | 16 - .../v1/tests/unit/__init__.py | 16 - .../v1/tests/unit/gapic/__init__.py | 16 - .../spanner_admin_instance_v1/__init__.py | 16 - .../test_instance_admin.py | 8775 ----------- ...data_google.spanner.admin.database.v1.json | 171 +- ...data_google.spanner.admin.instance.v1.json | 2 +- .../snippet_metadata_google.spanner.v1.json | 2 +- ...ed_database_admin_update_database_async.py | 0 ...ted_database_admin_update_database_sync.py | 0 ...ixup_spanner_admin_database_v1_keywords.py | 1 + .../test_database_admin.py | 604 + 255 files changed, 1529 insertions(+), 84459 deletions(-) delete mode 100644 owl-bot-staging/spanner/v1/.coveragerc delete mode 100644 owl-bot-staging/spanner/v1/.flake8 delete mode 100644 owl-bot-staging/spanner/v1/MANIFEST.in delete mode 100644 owl-bot-staging/spanner/v1/README.rst delete mode 100644 owl-bot-staging/spanner/v1/docs/conf.py delete mode 100644 owl-bot-staging/spanner/v1/docs/index.rst delete mode 100644 owl-bot-staging/spanner/v1/docs/spanner_v1/services.rst delete mode 100644 owl-bot-staging/spanner/v1/docs/spanner_v1/spanner.rst delete mode 100644 owl-bot-staging/spanner/v1/docs/spanner_v1/types.rst delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner/__init__.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner/gapic_version.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner/py.typed delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/__init__.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_metadata.json delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_version.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/py.typed delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/__init__.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/__init__.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/async_client.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/client.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/pagers.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/__init__.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/base.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/rest.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/__init__.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/commit_response.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/keys.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/mutation.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/query_plan.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/result_set.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/spanner.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/transaction.py delete mode 100644 owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/type.py delete mode 100644 owl-bot-staging/spanner/v1/mypy.ini delete mode 100644 owl-bot-staging/spanner/v1/noxfile.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/snippet_metadata_google.spanner.v1.json delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_sync.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_sync.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_sync.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_sync.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_sync.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_sync.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_sync.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_sync.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_sync.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_sync.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_sync.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_sync.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_sync.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_sync.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_async.py delete mode 100644 owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_sync.py delete mode 100644 owl-bot-staging/spanner/v1/scripts/fixup_spanner_v1_keywords.py delete mode 100644 owl-bot-staging/spanner/v1/setup.py delete mode 100644 owl-bot-staging/spanner/v1/testing/constraints-3.10.txt delete mode 100644 owl-bot-staging/spanner/v1/testing/constraints-3.11.txt delete mode 100644 owl-bot-staging/spanner/v1/testing/constraints-3.12.txt delete mode 100644 owl-bot-staging/spanner/v1/testing/constraints-3.7.txt delete mode 100644 owl-bot-staging/spanner/v1/testing/constraints-3.8.txt delete mode 100644 owl-bot-staging/spanner/v1/testing/constraints-3.9.txt delete mode 100644 owl-bot-staging/spanner/v1/tests/__init__.py delete mode 100644 owl-bot-staging/spanner/v1/tests/unit/__init__.py delete mode 100644 owl-bot-staging/spanner/v1/tests/unit/gapic/__init__.py delete mode 100644 owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/__init__.py delete mode 100644 owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/test_spanner.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/.coveragerc delete mode 100644 owl-bot-staging/spanner_admin_database/v1/.flake8 delete mode 100644 owl-bot-staging/spanner_admin_database/v1/MANIFEST.in delete mode 100644 owl-bot-staging/spanner_admin_database/v1/README.rst delete mode 100644 owl-bot-staging/spanner_admin_database/v1/docs/conf.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/docs/index.rst delete mode 100644 owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/database_admin.rst delete mode 100644 owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/services.rst delete mode 100644 owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/types.rst delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/gapic_version.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/py.typed delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_metadata.json delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_version.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/py.typed delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/client.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/backup.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/common.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/mypy.ini delete mode 100644 owl-bot-staging/spanner_admin_database/v1/noxfile.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.database.v1.json delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_async.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_sync.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/scripts/fixup_spanner_admin_database_v1_keywords.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/setup.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.10.txt delete mode 100644 owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.11.txt delete mode 100644 owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.12.txt delete mode 100644 owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.7.txt delete mode 100644 owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.8.txt delete mode 100644 owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.9.txt delete mode 100644 owl-bot-staging/spanner_admin_database/v1/tests/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/tests/unit/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/.coveragerc delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/.flake8 delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/MANIFEST.in delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/README.rst delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/docs/conf.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/docs/index.rst delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/instance_admin.rst delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/services.rst delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/types.rst delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/gapic_version.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/py.typed delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_metadata.json delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_version.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/py.typed delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/common.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/mypy.ini delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/noxfile.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.instance.v1.json delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_async.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_async.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_sync.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_sync.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_async.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_async.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_sync.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_sync.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_async.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_sync.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_async.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_async.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_sync.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_sync.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_async.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_async.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_sync.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_async.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_sync.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_async.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_sync.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_async.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_sync.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_async.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_async.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_sync.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_sync.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/scripts/fixup_spanner_admin_instance_v1_keywords.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/setup.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.10.txt delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.11.txt delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.12.txt delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.7.txt delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.8.txt delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.9.txt delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/tests/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/tests/unit/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/__init__.py delete mode 100644 owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py rename {owl-bot-staging/spanner_admin_database/v1/samples => samples}/generated_samples/spanner_v1_generated_database_admin_update_database_async.py (100%) rename {owl-bot-staging/spanner_admin_database/v1/samples => samples}/generated_samples/spanner_v1_generated_database_admin_update_database_sync.py (100%) diff --git a/google/cloud/spanner_admin_database_v1/__init__.py b/google/cloud/spanner_admin_database_v1/__init__.py index a985273089..ac9f326d88 100644 --- a/google/cloud/spanner_admin_database_v1/__init__.py +++ b/google/cloud/spanner_admin_database_v1/__init__.py @@ -61,6 +61,8 @@ from .types.spanner_database_admin import RestoreInfo from .types.spanner_database_admin import UpdateDatabaseDdlMetadata from .types.spanner_database_admin import UpdateDatabaseDdlRequest +from .types.spanner_database_admin import UpdateDatabaseMetadata +from .types.spanner_database_admin import UpdateDatabaseRequest from .types.spanner_database_admin import RestoreSourceType __all__ = ( @@ -107,4 +109,6 @@ "UpdateBackupRequest", "UpdateDatabaseDdlMetadata", "UpdateDatabaseDdlRequest", + "UpdateDatabaseMetadata", + "UpdateDatabaseRequest", ) diff --git a/google/cloud/spanner_admin_database_v1/gapic_metadata.json b/google/cloud/spanner_admin_database_v1/gapic_metadata.json index 86b9820ca8..b0fb4f1384 100644 --- a/google/cloud/spanner_admin_database_v1/gapic_metadata.json +++ b/google/cloud/spanner_admin_database_v1/gapic_metadata.json @@ -100,6 +100,11 @@ "update_backup" ] }, + "UpdateDatabase": { + "methods": [ + "update_database" + ] + }, "UpdateDatabaseDdl": { "methods": [ "update_database_ddl" @@ -200,6 +205,11 @@ "update_backup" ] }, + "UpdateDatabase": { + "methods": [ + "update_database" + ] + }, "UpdateDatabaseDdl": { "methods": [ "update_database_ddl" @@ -300,6 +310,11 @@ "update_backup" ] }, + "UpdateDatabase": { + "methods": [ + "update_database" + ] + }, "UpdateDatabaseDdl": { "methods": [ "update_database_ddl" diff --git a/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py b/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py index f0fd218cce..373c6ecd82 100644 --- a/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py +++ b/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py @@ -633,6 +633,188 @@ async def sample_get_database(): # Done; return the response. return response + async def update_database( + self, + request: Optional[ + Union[spanner_database_admin.UpdateDatabaseRequest, dict] + ] = None, + *, + database: Optional[spanner_database_admin.Database] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Updates a Cloud Spanner database. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the database. If the named database + does not exist, returns ``NOT_FOUND``. + + While the operation is pending: + + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field is set to true. + - Cancelling the operation is best-effort. If the cancellation + succeeds, the operation metadata's + [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] + is set, the updates are reverted, and the operation + terminates with a ``CANCELLED`` status. + - New UpdateDatabase requests will return a + ``FAILED_PRECONDITION`` error until the pending operation is + done (returns successfully or with error). + - Reading the database via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - The new values are in effect and readable via the API. + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format + ``projects//instances//databases//operations/`` + and can be used to track the database modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Database][google.spanner.admin.database.v1.Database], if + successful. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + async def sample_update_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminAsyncClient() + + # Initialize request argument(s) + database = spanner_admin_database_v1.Database() + database.name = "name_value" + + request = spanner_admin_database_v1.UpdateDatabaseRequest( + database=database, + ) + + # Make the request + operation = client.update_database(request=request) + + print("Waiting for operation to complete...") + + response = (await operation).result() + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest, dict]]): + The request object. The request for + [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. + database (:class:`google.cloud.spanner_admin_database_v1.types.Database`): + Required. The database to update. The ``name`` field of + the database is of the form + ``projects//instances//databases/``. + + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. The list of fields to update. Currently, only + ``enable_drop_protection`` field can be updated. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_database_v1.types.Database` + A Cloud Spanner database. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = spanner_database_admin.UpdateDatabaseRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_database, + default_retry=retries.Retry( + initial=1.0, + maximum=32.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("database.name", request.database.name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + spanner_database_admin.Database, + metadata_type=spanner_database_admin.UpdateDatabaseMetadata, + ) + + # Done; return the response. + return response + async def update_database_ddl( self, request: Optional[ diff --git a/google/cloud/spanner_admin_database_v1/services/database_admin/client.py b/google/cloud/spanner_admin_database_v1/services/database_admin/client.py index 8628469e19..e40fb5512b 100644 --- a/google/cloud/spanner_admin_database_v1/services/database_admin/client.py +++ b/google/cloud/spanner_admin_database_v1/services/database_admin/client.py @@ -939,6 +939,178 @@ def sample_get_database(): # Done; return the response. return response + def update_database( + self, + request: Optional[ + Union[spanner_database_admin.UpdateDatabaseRequest, dict] + ] = None, + *, + database: Optional[spanner_database_admin.Database] = None, + update_mask: Optional[field_mask_pb2.FieldMask] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Updates a Cloud Spanner database. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the database. If the named database + does not exist, returns ``NOT_FOUND``. + + While the operation is pending: + + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field is set to true. + - Cancelling the operation is best-effort. If the cancellation + succeeds, the operation metadata's + [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] + is set, the updates are reverted, and the operation + terminates with a ``CANCELLED`` status. + - New UpdateDatabase requests will return a + ``FAILED_PRECONDITION`` error until the pending operation is + done (returns successfully or with error). + - Reading the database via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - The new values are in effect and readable via the API. + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format + ``projects//instances//databases//operations/`` + and can be used to track the database modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Database][google.spanner.admin.database.v1.Database], if + successful. + + .. code-block:: python + + # This snippet has been automatically generated and should be regarded as a + # code template only. + # It will require modifications to work: + # - It may require correct/in-range values for request initialization. + # - It may require specifying regional endpoints when creating the service + # client as shown in: + # https://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import spanner_admin_database_v1 + + def sample_update_database(): + # Create a client + client = spanner_admin_database_v1.DatabaseAdminClient() + + # Initialize request argument(s) + database = spanner_admin_database_v1.Database() + database.name = "name_value" + + request = spanner_admin_database_v1.UpdateDatabaseRequest( + database=database, + ) + + # Make the request + operation = client.update_database(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest, dict]): + The request object. The request for + [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. + database (google.cloud.spanner_admin_database_v1.types.Database): + Required. The database to update. The ``name`` field of + the database is of the form + ``projects//instances//databases/``. + + This corresponds to the ``database`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. The list of fields to update. Currently, only + ``enable_drop_protection`` field can be updated. + + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.spanner_admin_database_v1.types.Database` + A Cloud Spanner database. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([database, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a spanner_database_admin.UpdateDatabaseRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, spanner_database_admin.UpdateDatabaseRequest): + request = spanner_database_admin.UpdateDatabaseRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if database is not None: + request.database = database + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_database] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("database.name", request.database.name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + spanner_database_admin.Database, + metadata_type=spanner_database_admin.UpdateDatabaseMetadata, + ) + + # Done; return the response. + return response + def update_database_ddl( self, request: Optional[ diff --git a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py index e4a522e7ca..12b0b4e5d1 100644 --- a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py +++ b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py @@ -169,6 +169,21 @@ def _prep_wrapped_messages(self, client_info): default_timeout=3600.0, client_info=client_info, ), + self.update_database: gapic_v1.method.wrap_method( + self.update_database, + default_retry=retries.Retry( + initial=1.0, + maximum=32.0, + multiplier=1.3, + predicate=retries.if_exception_type( + core_exceptions.DeadlineExceeded, + core_exceptions.ServiceUnavailable, + ), + deadline=3600.0, + ), + default_timeout=3600.0, + client_info=client_info, + ), self.update_database_ddl: gapic_v1.method.wrap_method( self.update_database_ddl, default_retry=retries.Retry( @@ -407,6 +422,15 @@ def get_database( ]: raise NotImplementedError() + @property + def update_database( + self, + ) -> Callable[ + [spanner_database_admin.UpdateDatabaseRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def update_database_ddl( self, diff --git a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py index b39f0758e2..1f2f01e497 100644 --- a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py +++ b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py @@ -353,6 +353,71 @@ def get_database( ) return self._stubs["get_database"] + @property + def update_database( + self, + ) -> Callable[ + [spanner_database_admin.UpdateDatabaseRequest], operations_pb2.Operation + ]: + r"""Return a callable for the update database method over gRPC. + + Updates a Cloud Spanner database. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the database. If the named database + does not exist, returns ``NOT_FOUND``. + + While the operation is pending: + + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field is set to true. + - Cancelling the operation is best-effort. If the cancellation + succeeds, the operation metadata's + [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] + is set, the updates are reverted, and the operation + terminates with a ``CANCELLED`` status. + - New UpdateDatabase requests will return a + ``FAILED_PRECONDITION`` error until the pending operation is + done (returns successfully or with error). + - Reading the database via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - The new values are in effect and readable via the API. + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format + ``projects//instances//databases//operations/`` + and can be used to track the database modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Database][google.spanner.admin.database.v1.Database], if + successful. + + Returns: + Callable[[~.UpdateDatabaseRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_database" not in self._stubs: + self._stubs["update_database"] = self.grpc_channel.unary_unary( + "/google.spanner.admin.database.v1.DatabaseAdmin/UpdateDatabase", + request_serializer=spanner_database_admin.UpdateDatabaseRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_database"] + @property def update_database_ddl( self, diff --git a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py index 0d5fccf84a..1267b946fe 100644 --- a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py +++ b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py @@ -360,6 +360,72 @@ def get_database( ) return self._stubs["get_database"] + @property + def update_database( + self, + ) -> Callable[ + [spanner_database_admin.UpdateDatabaseRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the update database method over gRPC. + + Updates a Cloud Spanner database. The returned [long-running + operation][google.longrunning.Operation] can be used to track + the progress of updating the database. If the named database + does not exist, returns ``NOT_FOUND``. + + While the operation is pending: + + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field is set to true. + - Cancelling the operation is best-effort. If the cancellation + succeeds, the operation metadata's + [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] + is set, the updates are reverted, and the operation + terminates with a ``CANCELLED`` status. + - New UpdateDatabase requests will return a + ``FAILED_PRECONDITION`` error until the pending operation is + done (returns successfully or with error). + - Reading the database via the API continues to give the + pre-request values. + + Upon completion of the returned operation: + + - The new values are in effect and readable via the API. + - The database's + [reconciling][google.spanner.admin.database.v1.Database.reconciling] + field becomes false. + + The returned [long-running + operation][google.longrunning.Operation] will have a name of the + format + ``projects//instances//databases//operations/`` + and can be used to track the database modification. The + [metadata][google.longrunning.Operation.metadata] field type is + [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. + The [response][google.longrunning.Operation.response] field type + is [Database][google.spanner.admin.database.v1.Database], if + successful. + + Returns: + Callable[[~.UpdateDatabaseRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_database" not in self._stubs: + self._stubs["update_database"] = self.grpc_channel.unary_unary( + "/google.spanner.admin.database.v1.DatabaseAdmin/UpdateDatabase", + request_serializer=spanner_database_admin.UpdateDatabaseRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_database"] + @property def update_database_ddl( self, diff --git a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py index dfe0289b05..8f0c58c256 100644 --- a/google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py +++ b/google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py @@ -213,6 +213,14 @@ def post_update_backup(self, response): logging.log(f"Received response: {response}") return response + def pre_update_database(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_update_database(self, response): + logging.log(f"Received response: {response}") + return response + def pre_update_database_ddl(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -609,6 +617,29 @@ def post_update_backup(self, response: gsad_backup.Backup) -> gsad_backup.Backup """ return response + def pre_update_database( + self, + request: spanner_database_admin.UpdateDatabaseRequest, + metadata: Sequence[Tuple[str, str]], + ) -> Tuple[spanner_database_admin.UpdateDatabaseRequest, Sequence[Tuple[str, str]]]: + """Pre-rpc interceptor for update_database + + Override in a subclass to manipulate the request or metadata + before they are sent to the DatabaseAdmin server. + """ + return request, metadata + + def post_update_database( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for update_database + + Override in a subclass to manipulate the response + after it is returned by the DatabaseAdmin server but before + it is returned to user code. + """ + return response + def pre_update_database_ddl( self, request: spanner_database_admin.UpdateDatabaseDdlRequest, @@ -2742,6 +2773,105 @@ def __call__( resp = self._interceptor.post_update_backup(resp) return resp + class _UpdateDatabase(DatabaseAdminRestStub): + def __hash__(self): + return hash("UpdateDatabase") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "updateMask": {}, + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + def __call__( + self, + request: spanner_database_admin.UpdateDatabaseRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Call the update database method over HTTP. + + Args: + request (~.spanner_database_admin.UpdateDatabaseRequest): + The request object. The request for + [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options: List[Dict[str, str]] = [ + { + "method": "patch", + "uri": "/v1/{database.name=projects/*/instances/*/databases/*}", + "body": "database", + }, + ] + request, metadata = self._interceptor.pre_update_database(request, metadata) + pb_request = spanner_database_admin.UpdateDatabaseRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + uri = transcoded_request["uri"] + method = transcoded_request["method"] + + # Jsonify the query params + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + including_default_value_fields=False, + use_integers_for_enums=True, + ) + ) + query_params.update(self._get_unset_required_fields(query_params)) + + query_params["$alt"] = "json;enum-encoding=int" + + # Send the request + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(self._session, method)( + "{host}{uri}".format(host=self._host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + resp = self._interceptor.post_update_database(resp) + return resp + class _UpdateDatabaseDdl(DatabaseAdminRestStub): def __hash__(self): return hash("UpdateDatabaseDdl") @@ -3021,6 +3151,16 @@ def update_backup( # In C++ this would require a dynamic_cast return self._UpdateBackup(self._session, self._host, self._interceptor) # type: ignore + @property + def update_database( + self, + ) -> Callable[ + [spanner_database_admin.UpdateDatabaseRequest], operations_pb2.Operation + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._UpdateDatabase(self._session, self._host, self._interceptor) # type: ignore + @property def update_database_ddl( self, diff --git a/google/cloud/spanner_admin_database_v1/types/__init__.py b/google/cloud/spanner_admin_database_v1/types/__init__.py index 9552559efa..405629136c 100644 --- a/google/cloud/spanner_admin_database_v1/types/__init__.py +++ b/google/cloud/spanner_admin_database_v1/types/__init__.py @@ -58,6 +58,8 @@ RestoreInfo, UpdateDatabaseDdlMetadata, UpdateDatabaseDdlRequest, + UpdateDatabaseMetadata, + UpdateDatabaseRequest, RestoreSourceType, ) @@ -102,5 +104,7 @@ "RestoreInfo", "UpdateDatabaseDdlMetadata", "UpdateDatabaseDdlRequest", + "UpdateDatabaseMetadata", + "UpdateDatabaseRequest", "RestoreSourceType", ) diff --git a/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py b/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py index 44c1c32421..15f38a30fd 100644 --- a/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py +++ b/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py @@ -22,6 +22,7 @@ from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup from google.cloud.spanner_admin_database_v1.types import common from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -36,6 +37,8 @@ "CreateDatabaseRequest", "CreateDatabaseMetadata", "GetDatabaseRequest", + "UpdateDatabaseRequest", + "UpdateDatabaseMetadata", "UpdateDatabaseDdlRequest", "UpdateDatabaseDdlMetadata", "DropDatabaseRequest", @@ -160,6 +163,13 @@ class Database(proto.Message): database_dialect (google.cloud.spanner_admin_database_v1.types.DatabaseDialect): Output only. The dialect of the Cloud Spanner Database. + enable_drop_protection (bool): + Whether drop protection is enabled for this + database. Defaults to false, if not set. + reconciling (bool): + Output only. If true, the database is being + updated. If false, there are no ongoing update + operations for the database. """ class State(proto.Enum): @@ -238,6 +248,14 @@ class State(proto.Enum): number=10, enum=common.DatabaseDialect, ) + enable_drop_protection: bool = proto.Field( + proto.BOOL, + number=11, + ) + reconciling: bool = proto.Field( + proto.BOOL, + number=12, + ) class ListDatabasesRequest(proto.Message): @@ -391,6 +409,68 @@ class GetDatabaseRequest(proto.Message): ) +class UpdateDatabaseRequest(proto.Message): + r"""The request for + [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. + + Attributes: + database (google.cloud.spanner_admin_database_v1.types.Database): + Required. The database to update. The ``name`` field of the + database is of the form + ``projects//instances//databases/``. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. The list of fields to update. Currently, only + ``enable_drop_protection`` field can be updated. + """ + + database: "Database" = proto.Field( + proto.MESSAGE, + number=1, + message="Database", + ) + update_mask: field_mask_pb2.FieldMask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class UpdateDatabaseMetadata(proto.Message): + r"""Metadata type for the operation returned by + [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. + + Attributes: + request (google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest): + The request for + [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. + progress (google.cloud.spanner_admin_database_v1.types.OperationProgress): + The progress of the + [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase] + operation. + cancel_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which this operation was + cancelled. If set, this operation is in the + process of undoing itself (which is + best-effort). + """ + + request: "UpdateDatabaseRequest" = proto.Field( + proto.MESSAGE, + number=1, + message="UpdateDatabaseRequest", + ) + progress: common.OperationProgress = proto.Field( + proto.MESSAGE, + number=2, + message=common.OperationProgress, + ) + cancel_time: timestamp_pb2.Timestamp = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + + class UpdateDatabaseDdlRequest(proto.Message): r"""Enqueues the given DDL statements to be applied, in order but not necessarily all at once, to the database schema at some point (or diff --git a/owl-bot-staging/spanner/v1/.coveragerc b/owl-bot-staging/spanner/v1/.coveragerc deleted file mode 100644 index 677a992799..0000000000 --- a/owl-bot-staging/spanner/v1/.coveragerc +++ /dev/null @@ -1,13 +0,0 @@ -[run] -branch = True - -[report] -show_missing = True -omit = - google/cloud/spanner/__init__.py - google/cloud/spanner/gapic_version.py -exclude_lines = - # Re-enable the standard pragma - pragma: NO COVER - # Ignore debug-only repr - def __repr__ diff --git a/owl-bot-staging/spanner/v1/.flake8 b/owl-bot-staging/spanner/v1/.flake8 deleted file mode 100644 index 29227d4cf4..0000000000 --- a/owl-bot-staging/spanner/v1/.flake8 +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Generated by synthtool. DO NOT EDIT! -[flake8] -ignore = E203, E266, E501, W503 -exclude = - # Exclude generated code. - **/proto/** - **/gapic/** - **/services/** - **/types/** - *_pb2.py - - # Standard linting exemptions. - **/.nox/** - __pycache__, - .git, - *.pyc, - conf.py diff --git a/owl-bot-staging/spanner/v1/MANIFEST.in b/owl-bot-staging/spanner/v1/MANIFEST.in deleted file mode 100644 index 2bde59af4d..0000000000 --- a/owl-bot-staging/spanner/v1/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include google/cloud/spanner *.py -recursive-include google/cloud/spanner_v1 *.py diff --git a/owl-bot-staging/spanner/v1/README.rst b/owl-bot-staging/spanner/v1/README.rst deleted file mode 100644 index d6abf98111..0000000000 --- a/owl-bot-staging/spanner/v1/README.rst +++ /dev/null @@ -1,49 +0,0 @@ -Python Client for Google Cloud Spanner API -================================================= - -Quick Start ------------ - -In order to use this library, you first need to go through the following steps: - -1. `Select or create a Cloud Platform project.`_ -2. `Enable billing for your project.`_ -3. Enable the Google Cloud Spanner API. -4. `Setup Authentication.`_ - -.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project -.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project -.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html - -Installation -~~~~~~~~~~~~ - -Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to -create isolated Python environments. The basic problem it addresses is one of -dependencies and versions, and indirectly permissions. - -With `virtualenv`_, it's possible to install this library without needing system -install permissions, and without clashing with the installed system -dependencies. - -.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ - - -Mac/Linux -^^^^^^^^^ - -.. code-block:: console - - python3 -m venv - source /bin/activate - /bin/pip install /path/to/library - - -Windows -^^^^^^^ - -.. code-block:: console - - python3 -m venv - \Scripts\activate - \Scripts\pip.exe install \path\to\library diff --git a/owl-bot-staging/spanner/v1/docs/conf.py b/owl-bot-staging/spanner/v1/docs/conf.py deleted file mode 100644 index a2a239f23f..0000000000 --- a/owl-bot-staging/spanner/v1/docs/conf.py +++ /dev/null @@ -1,376 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# -# google-cloud-spanner documentation build configuration file -# -# This file is execfile()d with the current directory set to its -# containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -import sys -import os -import shlex - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath("..")) - -__version__ = "0.1.0" - -# -- General configuration ------------------------------------------------ - -# If your documentation needs a minimal Sphinx version, state it here. -needs_sphinx = "4.0.1" - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.autosummary", - "sphinx.ext.intersphinx", - "sphinx.ext.coverage", - "sphinx.ext.napoleon", - "sphinx.ext.todo", - "sphinx.ext.viewcode", -] - -# autodoc/autosummary flags -autoclass_content = "both" -autodoc_default_flags = ["members"] -autosummary_generate = True - - -# Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] - -# Allow markdown includes (so releases.md can include CHANGLEOG.md) -# http://www.sphinx-doc.org/en/master/markdown.html -source_parsers = {".md": "recommonmark.parser.CommonMarkParser"} - -# The suffix(es) of source filenames. -# You can specify multiple suffix as a list of string: -source_suffix = [".rst", ".md"] - -# The encoding of source files. -# source_encoding = 'utf-8-sig' - -# The root toctree document. -root_doc = "index" - -# General information about the project. -project = u"google-cloud-spanner" -copyright = u"2022, Google, LLC" -author = u"Google APIs" # TODO: autogenerate this bit - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The full version, including alpha/beta/rc tags. -release = __version__ -# The short X.Y version. -version = ".".join(release.split(".")[0:2]) - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. -language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -# today = '' -# Else, today_fmt is used as the format for a strftime call. -# today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = ["_build"] - -# The reST default role (used for this markup: `text`) to use for all -# documents. -# default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -# add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -# add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -# show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = "sphinx" - -# A list of ignored prefixes for module index sorting. -# modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built documents. -# keep_warnings = False - -# If true, `todo` and `todoList` produce output, else they produce nothing. -todo_include_todos = True - - -# -- Options for HTML output ---------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = "alabaster" - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -html_theme_options = { - "description": "Google Cloud Client Libraries for Python", - "github_user": "googleapis", - "github_repo": "google-cloud-python", - "github_banner": True, - "font_family": "'Roboto', Georgia, sans", - "head_font_family": "'Roboto', Georgia, serif", - "code_font_family": "'Roboto Mono', 'Consolas', monospace", -} - -# Add any paths that contain custom themes here, relative to this directory. -# html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -# html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -# html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -# html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -# html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] - -# Add any extra paths that contain custom files (such as robots.txt or -# .htaccess) here, relative to this directory. These files are copied -# directly to the root of the documentation. -# html_extra_path = [] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -# html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -# html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -# html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -# html_additional_pages = {} - -# If false, no module index is generated. -# html_domain_indices = True - -# If false, no index is generated. -# html_use_index = True - -# If true, the index is split into individual pages for each letter. -# html_split_index = False - -# If true, links to the reST sources are added to the pages. -# html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -# html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -# html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -# html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -# html_file_suffix = None - -# Language to be used for generating the HTML full-text search index. -# Sphinx supports the following languages: -# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' -# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' -# html_search_language = 'en' - -# A dictionary with options for the search language support, empty by default. -# Now only 'ja' uses this config value -# html_search_options = {'type': 'default'} - -# The name of a javascript file (relative to the configuration directory) that -# implements a search results scorer. If empty, the default will be used. -# html_search_scorer = 'scorer.js' - -# Output file base name for HTML help builder. -htmlhelp_basename = "google-cloud-spanner-doc" - -# -- Options for warnings ------------------------------------------------------ - - -suppress_warnings = [ - # Temporarily suppress this to avoid "more than one target found for - # cross-reference" warning, which are intractable for us to avoid while in - # a mono-repo. - # See https://github.com/sphinx-doc/sphinx/blob - # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 - "ref.python" -] - -# -- Options for LaTeX output --------------------------------------------- - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). - # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. - # 'preamble': '', - # Latex figure (float) alignment - # 'figure_align': 'htbp', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - ( - root_doc, - "google-cloud-spanner.tex", - u"google-cloud-spanner Documentation", - author, - "manual", - ) -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -# latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -# latex_use_parts = False - -# If true, show page references after internal links. -# latex_show_pagerefs = False - -# If true, show URL addresses after external links. -# latex_show_urls = False - -# Documents to append as an appendix to all manuals. -# latex_appendices = [] - -# If false, no module index is generated. -# latex_domain_indices = True - - -# -- Options for manual page output --------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - ( - root_doc, - "google-cloud-spanner", - u"Google Cloud Spanner Documentation", - [author], - 1, - ) -] - -# If true, show URL addresses after external links. -# man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - ( - root_doc, - "google-cloud-spanner", - u"google-cloud-spanner Documentation", - author, - "google-cloud-spanner", - "GAPIC library for Google Cloud Spanner API", - "APIs", - ) -] - -# Documents to append as an appendix to all manuals. -# texinfo_appendices = [] - -# If false, no module index is generated. -# texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -# texinfo_show_urls = 'footnote' - -# If true, do not generate a @detailmenu in the "Top" node's menu. -# texinfo_no_detailmenu = False - - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = { - "python": ("http://python.readthedocs.org/en/latest/", None), - "gax": ("https://gax-python.readthedocs.org/en/latest/", None), - "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), - "google-gax": ("https://gax-python.readthedocs.io/en/latest/", None), - "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None), - "grpc": ("https://grpc.io/grpc/python/", None), - "requests": ("http://requests.kennethreitz.org/en/stable/", None), - "proto": ("https://proto-plus-python.readthedocs.io/en/stable", None), - "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), -} - - -# Napoleon settings -napoleon_google_docstring = True -napoleon_numpy_docstring = True -napoleon_include_private_with_doc = False -napoleon_include_special_with_doc = True -napoleon_use_admonition_for_examples = False -napoleon_use_admonition_for_notes = False -napoleon_use_admonition_for_references = False -napoleon_use_ivar = False -napoleon_use_param = True -napoleon_use_rtype = True diff --git a/owl-bot-staging/spanner/v1/docs/index.rst b/owl-bot-staging/spanner/v1/docs/index.rst deleted file mode 100644 index ee873ac9c1..0000000000 --- a/owl-bot-staging/spanner/v1/docs/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -API Reference -------------- -.. toctree:: - :maxdepth: 2 - - spanner_v1/services - spanner_v1/types diff --git a/owl-bot-staging/spanner/v1/docs/spanner_v1/services.rst b/owl-bot-staging/spanner/v1/docs/spanner_v1/services.rst deleted file mode 100644 index 3bbbb55f79..0000000000 --- a/owl-bot-staging/spanner/v1/docs/spanner_v1/services.rst +++ /dev/null @@ -1,6 +0,0 @@ -Services for Google Cloud Spanner v1 API -======================================== -.. toctree:: - :maxdepth: 2 - - spanner diff --git a/owl-bot-staging/spanner/v1/docs/spanner_v1/spanner.rst b/owl-bot-staging/spanner/v1/docs/spanner_v1/spanner.rst deleted file mode 100644 index b51f4447e4..0000000000 --- a/owl-bot-staging/spanner/v1/docs/spanner_v1/spanner.rst +++ /dev/null @@ -1,10 +0,0 @@ -Spanner -------------------------- - -.. automodule:: google.cloud.spanner_v1.services.spanner - :members: - :inherited-members: - -.. automodule:: google.cloud.spanner_v1.services.spanner.pagers - :members: - :inherited-members: diff --git a/owl-bot-staging/spanner/v1/docs/spanner_v1/types.rst b/owl-bot-staging/spanner/v1/docs/spanner_v1/types.rst deleted file mode 100644 index c7ff7e6c71..0000000000 --- a/owl-bot-staging/spanner/v1/docs/spanner_v1/types.rst +++ /dev/null @@ -1,6 +0,0 @@ -Types for Google Cloud Spanner v1 API -===================================== - -.. automodule:: google.cloud.spanner_v1.types - :members: - :show-inheritance: diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner/__init__.py b/owl-bot-staging/spanner/v1/google/cloud/spanner/__init__.py deleted file mode 100644 index 757431564c..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner/__init__.py +++ /dev/null @@ -1,103 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from google.cloud.spanner import gapic_version as package_version - -__version__ = package_version.__version__ - - -from google.cloud.spanner_v1.services.spanner.client import SpannerClient -from google.cloud.spanner_v1.services.spanner.async_client import SpannerAsyncClient - -from google.cloud.spanner_v1.types.commit_response import CommitResponse -from google.cloud.spanner_v1.types.keys import KeyRange -from google.cloud.spanner_v1.types.keys import KeySet -from google.cloud.spanner_v1.types.mutation import Mutation -from google.cloud.spanner_v1.types.query_plan import PlanNode -from google.cloud.spanner_v1.types.query_plan import QueryPlan -from google.cloud.spanner_v1.types.result_set import PartialResultSet -from google.cloud.spanner_v1.types.result_set import ResultSet -from google.cloud.spanner_v1.types.result_set import ResultSetMetadata -from google.cloud.spanner_v1.types.result_set import ResultSetStats -from google.cloud.spanner_v1.types.spanner import BatchCreateSessionsRequest -from google.cloud.spanner_v1.types.spanner import BatchCreateSessionsResponse -from google.cloud.spanner_v1.types.spanner import BeginTransactionRequest -from google.cloud.spanner_v1.types.spanner import CommitRequest -from google.cloud.spanner_v1.types.spanner import CreateSessionRequest -from google.cloud.spanner_v1.types.spanner import DeleteSessionRequest -from google.cloud.spanner_v1.types.spanner import ExecuteBatchDmlRequest -from google.cloud.spanner_v1.types.spanner import ExecuteBatchDmlResponse -from google.cloud.spanner_v1.types.spanner import ExecuteSqlRequest -from google.cloud.spanner_v1.types.spanner import GetSessionRequest -from google.cloud.spanner_v1.types.spanner import ListSessionsRequest -from google.cloud.spanner_v1.types.spanner import ListSessionsResponse -from google.cloud.spanner_v1.types.spanner import Partition -from google.cloud.spanner_v1.types.spanner import PartitionOptions -from google.cloud.spanner_v1.types.spanner import PartitionQueryRequest -from google.cloud.spanner_v1.types.spanner import PartitionReadRequest -from google.cloud.spanner_v1.types.spanner import PartitionResponse -from google.cloud.spanner_v1.types.spanner import ReadRequest -from google.cloud.spanner_v1.types.spanner import RequestOptions -from google.cloud.spanner_v1.types.spanner import RollbackRequest -from google.cloud.spanner_v1.types.spanner import Session -from google.cloud.spanner_v1.types.transaction import Transaction -from google.cloud.spanner_v1.types.transaction import TransactionOptions -from google.cloud.spanner_v1.types.transaction import TransactionSelector -from google.cloud.spanner_v1.types.type import StructType -from google.cloud.spanner_v1.types.type import Type -from google.cloud.spanner_v1.types.type import TypeAnnotationCode -from google.cloud.spanner_v1.types.type import TypeCode - -__all__ = ('SpannerClient', - 'SpannerAsyncClient', - 'CommitResponse', - 'KeyRange', - 'KeySet', - 'Mutation', - 'PlanNode', - 'QueryPlan', - 'PartialResultSet', - 'ResultSet', - 'ResultSetMetadata', - 'ResultSetStats', - 'BatchCreateSessionsRequest', - 'BatchCreateSessionsResponse', - 'BeginTransactionRequest', - 'CommitRequest', - 'CreateSessionRequest', - 'DeleteSessionRequest', - 'ExecuteBatchDmlRequest', - 'ExecuteBatchDmlResponse', - 'ExecuteSqlRequest', - 'GetSessionRequest', - 'ListSessionsRequest', - 'ListSessionsResponse', - 'Partition', - 'PartitionOptions', - 'PartitionQueryRequest', - 'PartitionReadRequest', - 'PartitionResponse', - 'ReadRequest', - 'RequestOptions', - 'RollbackRequest', - 'Session', - 'Transaction', - 'TransactionOptions', - 'TransactionSelector', - 'StructType', - 'Type', - 'TypeAnnotationCode', - 'TypeCode', -) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner/gapic_version.py b/owl-bot-staging/spanner/v1/google/cloud/spanner/gapic_version.py deleted file mode 100644 index 405b1cebcf..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner/gapic_version.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -__version__ = "0.1.0" # {x-release-please-version} diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner/py.typed b/owl-bot-staging/spanner/v1/google/cloud/spanner/py.typed deleted file mode 100644 index 0989eccd04..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-spanner package uses inline types. diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/__init__.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/__init__.py deleted file mode 100644 index 27c3210864..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/__init__.py +++ /dev/null @@ -1,104 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from google.cloud.spanner_v1 import gapic_version as package_version - -__version__ = package_version.__version__ - - -from .services.spanner import SpannerClient -from .services.spanner import SpannerAsyncClient - -from .types.commit_response import CommitResponse -from .types.keys import KeyRange -from .types.keys import KeySet -from .types.mutation import Mutation -from .types.query_plan import PlanNode -from .types.query_plan import QueryPlan -from .types.result_set import PartialResultSet -from .types.result_set import ResultSet -from .types.result_set import ResultSetMetadata -from .types.result_set import ResultSetStats -from .types.spanner import BatchCreateSessionsRequest -from .types.spanner import BatchCreateSessionsResponse -from .types.spanner import BeginTransactionRequest -from .types.spanner import CommitRequest -from .types.spanner import CreateSessionRequest -from .types.spanner import DeleteSessionRequest -from .types.spanner import ExecuteBatchDmlRequest -from .types.spanner import ExecuteBatchDmlResponse -from .types.spanner import ExecuteSqlRequest -from .types.spanner import GetSessionRequest -from .types.spanner import ListSessionsRequest -from .types.spanner import ListSessionsResponse -from .types.spanner import Partition -from .types.spanner import PartitionOptions -from .types.spanner import PartitionQueryRequest -from .types.spanner import PartitionReadRequest -from .types.spanner import PartitionResponse -from .types.spanner import ReadRequest -from .types.spanner import RequestOptions -from .types.spanner import RollbackRequest -from .types.spanner import Session -from .types.transaction import Transaction -from .types.transaction import TransactionOptions -from .types.transaction import TransactionSelector -from .types.type import StructType -from .types.type import Type -from .types.type import TypeAnnotationCode -from .types.type import TypeCode - -__all__ = ( - 'SpannerAsyncClient', -'BatchCreateSessionsRequest', -'BatchCreateSessionsResponse', -'BeginTransactionRequest', -'CommitRequest', -'CommitResponse', -'CreateSessionRequest', -'DeleteSessionRequest', -'ExecuteBatchDmlRequest', -'ExecuteBatchDmlResponse', -'ExecuteSqlRequest', -'GetSessionRequest', -'KeyRange', -'KeySet', -'ListSessionsRequest', -'ListSessionsResponse', -'Mutation', -'PartialResultSet', -'Partition', -'PartitionOptions', -'PartitionQueryRequest', -'PartitionReadRequest', -'PartitionResponse', -'PlanNode', -'QueryPlan', -'ReadRequest', -'RequestOptions', -'ResultSet', -'ResultSetMetadata', -'ResultSetStats', -'RollbackRequest', -'Session', -'SpannerClient', -'StructType', -'Transaction', -'TransactionOptions', -'TransactionSelector', -'Type', -'TypeAnnotationCode', -'TypeCode', -) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_metadata.json b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_metadata.json deleted file mode 100644 index ea51736a55..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_metadata.json +++ /dev/null @@ -1,253 +0,0 @@ - { - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "python", - "libraryPackage": "google.cloud.spanner_v1", - "protoPackage": "google.spanner.v1", - "schema": "1.0", - "services": { - "Spanner": { - "clients": { - "grpc": { - "libraryClient": "SpannerClient", - "rpcs": { - "BatchCreateSessions": { - "methods": [ - "batch_create_sessions" - ] - }, - "BeginTransaction": { - "methods": [ - "begin_transaction" - ] - }, - "Commit": { - "methods": [ - "commit" - ] - }, - "CreateSession": { - "methods": [ - "create_session" - ] - }, - "DeleteSession": { - "methods": [ - "delete_session" - ] - }, - "ExecuteBatchDml": { - "methods": [ - "execute_batch_dml" - ] - }, - "ExecuteSql": { - "methods": [ - "execute_sql" - ] - }, - "ExecuteStreamingSql": { - "methods": [ - "execute_streaming_sql" - ] - }, - "GetSession": { - "methods": [ - "get_session" - ] - }, - "ListSessions": { - "methods": [ - "list_sessions" - ] - }, - "PartitionQuery": { - "methods": [ - "partition_query" - ] - }, - "PartitionRead": { - "methods": [ - "partition_read" - ] - }, - "Read": { - "methods": [ - "read" - ] - }, - "Rollback": { - "methods": [ - "rollback" - ] - }, - "StreamingRead": { - "methods": [ - "streaming_read" - ] - } - } - }, - "grpc-async": { - "libraryClient": "SpannerAsyncClient", - "rpcs": { - "BatchCreateSessions": { - "methods": [ - "batch_create_sessions" - ] - }, - "BeginTransaction": { - "methods": [ - "begin_transaction" - ] - }, - "Commit": { - "methods": [ - "commit" - ] - }, - "CreateSession": { - "methods": [ - "create_session" - ] - }, - "DeleteSession": { - "methods": [ - "delete_session" - ] - }, - "ExecuteBatchDml": { - "methods": [ - "execute_batch_dml" - ] - }, - "ExecuteSql": { - "methods": [ - "execute_sql" - ] - }, - "ExecuteStreamingSql": { - "methods": [ - "execute_streaming_sql" - ] - }, - "GetSession": { - "methods": [ - "get_session" - ] - }, - "ListSessions": { - "methods": [ - "list_sessions" - ] - }, - "PartitionQuery": { - "methods": [ - "partition_query" - ] - }, - "PartitionRead": { - "methods": [ - "partition_read" - ] - }, - "Read": { - "methods": [ - "read" - ] - }, - "Rollback": { - "methods": [ - "rollback" - ] - }, - "StreamingRead": { - "methods": [ - "streaming_read" - ] - } - } - }, - "rest": { - "libraryClient": "SpannerClient", - "rpcs": { - "BatchCreateSessions": { - "methods": [ - "batch_create_sessions" - ] - }, - "BeginTransaction": { - "methods": [ - "begin_transaction" - ] - }, - "Commit": { - "methods": [ - "commit" - ] - }, - "CreateSession": { - "methods": [ - "create_session" - ] - }, - "DeleteSession": { - "methods": [ - "delete_session" - ] - }, - "ExecuteBatchDml": { - "methods": [ - "execute_batch_dml" - ] - }, - "ExecuteSql": { - "methods": [ - "execute_sql" - ] - }, - "ExecuteStreamingSql": { - "methods": [ - "execute_streaming_sql" - ] - }, - "GetSession": { - "methods": [ - "get_session" - ] - }, - "ListSessions": { - "methods": [ - "list_sessions" - ] - }, - "PartitionQuery": { - "methods": [ - "partition_query" - ] - }, - "PartitionRead": { - "methods": [ - "partition_read" - ] - }, - "Read": { - "methods": [ - "read" - ] - }, - "Rollback": { - "methods": [ - "rollback" - ] - }, - "StreamingRead": { - "methods": [ - "streaming_read" - ] - } - } - } - } - } - } -} diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_version.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_version.py deleted file mode 100644 index 405b1cebcf..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/gapic_version.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -__version__ = "0.1.0" # {x-release-please-version} diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/py.typed b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/py.typed deleted file mode 100644 index 0989eccd04..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-spanner package uses inline types. diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/__init__.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/__init__.py deleted file mode 100644 index e8e1c3845d..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/__init__.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/__init__.py deleted file mode 100644 index 04d980250a..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .client import SpannerClient -from .async_client import SpannerAsyncClient - -__all__ = ( - 'SpannerClient', - 'SpannerAsyncClient', -) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/async_client.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/async_client.py deleted file mode 100644 index 1657668e54..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/async_client.py +++ /dev/null @@ -1,1920 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -import functools -import re -from typing import Dict, Mapping, MutableMapping, MutableSequence, Optional, AsyncIterable, Awaitable, Sequence, Tuple, Type, Union - -from google.cloud.spanner_v1 import gapic_version as package_version - -from google.api_core.client_options import ClientOptions -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore - -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object] # type: ignore - -from google.cloud.spanner_v1.services.spanner import pagers -from google.cloud.spanner_v1.types import commit_response -from google.cloud.spanner_v1.types import mutation -from google.cloud.spanner_v1.types import result_set -from google.cloud.spanner_v1.types import spanner -from google.cloud.spanner_v1.types import transaction -from google.protobuf import struct_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from .transports.base import SpannerTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import SpannerGrpcAsyncIOTransport -from .client import SpannerClient - - -class SpannerAsyncClient: - """Cloud Spanner API - The Cloud Spanner API can be used to manage sessions and execute - transactions on data stored in Cloud Spanner databases. - """ - - _client: SpannerClient - - DEFAULT_ENDPOINT = SpannerClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = SpannerClient.DEFAULT_MTLS_ENDPOINT - - database_path = staticmethod(SpannerClient.database_path) - parse_database_path = staticmethod(SpannerClient.parse_database_path) - session_path = staticmethod(SpannerClient.session_path) - parse_session_path = staticmethod(SpannerClient.parse_session_path) - common_billing_account_path = staticmethod(SpannerClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(SpannerClient.parse_common_billing_account_path) - common_folder_path = staticmethod(SpannerClient.common_folder_path) - parse_common_folder_path = staticmethod(SpannerClient.parse_common_folder_path) - common_organization_path = staticmethod(SpannerClient.common_organization_path) - parse_common_organization_path = staticmethod(SpannerClient.parse_common_organization_path) - common_project_path = staticmethod(SpannerClient.common_project_path) - parse_common_project_path = staticmethod(SpannerClient.parse_common_project_path) - common_location_path = staticmethod(SpannerClient.common_location_path) - parse_common_location_path = staticmethod(SpannerClient.parse_common_location_path) - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - SpannerAsyncClient: The constructed client. - """ - return SpannerClient.from_service_account_info.__func__(SpannerAsyncClient, info, *args, **kwargs) # type: ignore - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - SpannerAsyncClient: The constructed client. - """ - return SpannerClient.from_service_account_file.__func__(SpannerAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @classmethod - def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[ClientOptions] = None): - """Return the API endpoint and client cert source for mutual TLS. - - The client cert source is determined in the following order: - (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the - client cert source is None. - (2) if `client_options.client_cert_source` is provided, use the provided one; if the - default client cert source exists, use the default one; otherwise the client cert - source is None. - - The API endpoint is determined in the following order: - (1) if `client_options.api_endpoint` if provided, use the provided one. - (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the - default mTLS endpoint; if the environment variable is "never", use the default API - endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise - use the default API endpoint. - - More details can be found at https://google.aip.dev/auth/4114. - - Args: - client_options (google.api_core.client_options.ClientOptions): Custom options for the - client. Only the `api_endpoint` and `client_cert_source` properties may be used - in this method. - - Returns: - Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the - client cert source to use. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If any errors happen. - """ - return SpannerClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore - - @property - def transport(self) -> SpannerTransport: - """Returns the transport used by the client instance. - - Returns: - SpannerTransport: The transport used by the client instance. - """ - return self._client.transport - - get_transport_class = functools.partial(type(SpannerClient).get_transport_class, type(SpannerClient)) - - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, SpannerTransport] = "grpc_asyncio", - client_options: Optional[ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the spanner client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Union[str, ~.SpannerTransport]): The - transport to use. If set to None, a transport is chosen - automatically. - client_options (ClientOptions): Custom options for the client. It - won't take effect if a ``transport`` instance is provided. - (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT - environment variable can also be used to override the endpoint: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto switch to the - default mTLS endpoint if client certificate is present, this is - the default value). However, the ``api_endpoint`` property takes - precedence if provided. - (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide client certificate for mutual TLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - """ - self._client = SpannerClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - async def create_session(self, - request: Optional[Union[spanner.CreateSessionRequest, dict]] = None, - *, - database: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner.Session: - r"""Creates a new session. A session can be used to perform - transactions that read and/or modify data in a Cloud Spanner - database. Sessions are meant to be reused for many consecutive - transactions. - - Sessions can only execute one transaction at a time. To execute - multiple concurrent read-write/write-only transactions, create - multiple sessions. Note that standalone reads and queries use a - transaction internally, and count toward the one transaction - limit. - - Active sessions use additional server resources, so it is a good - idea to delete idle and unneeded sessions. Aside from explicit - deletes, Cloud Spanner may delete sessions for which no - operations are sent for more than an hour. If a session is - deleted, requests to it return ``NOT_FOUND``. - - Idle sessions can be kept alive by sending a trivial SQL query - periodically, e.g., ``"SELECT 1"``. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_create_session(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.CreateSessionRequest( - database="database_value", - ) - - # Make the request - response = await client.create_session(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.CreateSessionRequest, dict]]): - The request object. The request for - [CreateSession][google.spanner.v1.Spanner.CreateSession]. - database (:class:`str`): - Required. The database in which the - new session is created. - - This corresponds to the ``database`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.Session: - A session in the Cloud Spanner API. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([database]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner.CreateSessionRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if database is not None: - request.database = database - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.create_session, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("database", request.database), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def batch_create_sessions(self, - request: Optional[Union[spanner.BatchCreateSessionsRequest, dict]] = None, - *, - database: Optional[str] = None, - session_count: Optional[int] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner.BatchCreateSessionsResponse: - r"""Creates multiple new sessions. - This API can be used to initialize a session cache on - the clients. See https://goo.gl/TgSFN2 for best - practices on session cache management. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_batch_create_sessions(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.BatchCreateSessionsRequest( - database="database_value", - session_count=1420, - ) - - # Make the request - response = await client.batch_create_sessions(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.BatchCreateSessionsRequest, dict]]): - The request object. The request for - [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. - database (:class:`str`): - Required. The database in which the - new sessions are created. - - This corresponds to the ``database`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - session_count (:class:`int`): - Required. The number of sessions to be created in this - batch call. The API may return fewer than the requested - number of sessions. If a specific number of sessions are - desired, the client can make additional calls to - BatchCreateSessions (adjusting - [session_count][google.spanner.v1.BatchCreateSessionsRequest.session_count] - as necessary). - - This corresponds to the ``session_count`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.BatchCreateSessionsResponse: - The response for - [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([database, session_count]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner.BatchCreateSessionsRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if database is not None: - request.database = database - if session_count is not None: - request.session_count = session_count - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.batch_create_sessions, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("database", request.database), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def get_session(self, - request: Optional[Union[spanner.GetSessionRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner.Session: - r"""Gets a session. Returns ``NOT_FOUND`` if the session does not - exist. This is mainly useful for determining whether a session - is still alive. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_get_session(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.GetSessionRequest( - name="name_value", - ) - - # Make the request - response = await client.get_session(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.GetSessionRequest, dict]]): - The request object. The request for - [GetSession][google.spanner.v1.Spanner.GetSession]. - name (:class:`str`): - Required. The name of the session to - retrieve. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.Session: - A session in the Cloud Spanner API. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner.GetSessionRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_session, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def list_sessions(self, - request: Optional[Union[spanner.ListSessionsRequest, dict]] = None, - *, - database: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListSessionsAsyncPager: - r"""Lists all sessions in a given database. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_list_sessions(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.ListSessionsRequest( - database="database_value", - ) - - # Make the request - page_result = client.list_sessions(request=request) - - # Handle the response - async for response in page_result: - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.ListSessionsRequest, dict]]): - The request object. The request for - [ListSessions][google.spanner.v1.Spanner.ListSessions]. - database (:class:`str`): - Required. The database in which to - list sessions. - - This corresponds to the ``database`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.services.spanner.pagers.ListSessionsAsyncPager: - The response for - [ListSessions][google.spanner.v1.Spanner.ListSessions]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([database]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner.ListSessionsRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if database is not None: - request.database = database - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_sessions, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("database", request.database), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListSessionsAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def delete_session(self, - request: Optional[Union[spanner.DeleteSessionRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Ends a session, releasing server resources associated - with it. This will asynchronously trigger cancellation - of any operations that are running with this session. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_delete_session(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.DeleteSessionRequest( - name="name_value", - ) - - # Make the request - await client.delete_session(request=request) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.DeleteSessionRequest, dict]]): - The request object. The request for - [DeleteSession][google.spanner.v1.Spanner.DeleteSession]. - name (:class:`str`): - Required. The name of the session to - delete. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner.DeleteSessionRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.delete_session, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def execute_sql(self, - request: Optional[Union[spanner.ExecuteSqlRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> result_set.ResultSet: - r"""Executes an SQL statement, returning all results in a single - reply. This method cannot be used to return a result set larger - than 10 MiB; if the query yields more data than that, the query - fails with a ``FAILED_PRECONDITION`` error. - - Operations inside read-write transactions might return - ``ABORTED``. If this occurs, the application should restart the - transaction from the beginning. See - [Transaction][google.spanner.v1.Transaction] for more details. - - Larger result sets can be fetched in streaming fashion by - calling - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] - instead. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_execute_sql(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.ExecuteSqlRequest( - session="session_value", - sql="sql_value", - ) - - # Make the request - response = await client.execute_sql(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.ExecuteSqlRequest, dict]]): - The request object. The request for - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.ResultSet: - Results from [Read][google.spanner.v1.Spanner.Read] or - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. - - """ - # Create or coerce a protobuf request object. - request = spanner.ExecuteSqlRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.execute_sql, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def execute_streaming_sql(self, - request: Optional[Union[spanner.ExecuteSqlRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> Awaitable[AsyncIterable[result_set.PartialResultSet]]: - r"""Like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except - returns the result set as a stream. Unlike - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there is no - limit on the size of the returned result set. However, no - individual row in the result set can exceed 100 MiB, and no - column value can exceed 10 MiB. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_execute_streaming_sql(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.ExecuteSqlRequest( - session="session_value", - sql="sql_value", - ) - - # Make the request - stream = await client.execute_streaming_sql(request=request) - - # Handle the response - async for response in stream: - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.ExecuteSqlRequest, dict]]): - The request object. The request for - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - AsyncIterable[google.cloud.spanner_v1.types.PartialResultSet]: - Partial results from a streaming read - or SQL query. Streaming reads and SQL - queries better tolerate large result - sets, large rows, and large values, but - are a little trickier to consume. - - """ - # Create or coerce a protobuf request object. - request = spanner.ExecuteSqlRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.execute_streaming_sql, - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def execute_batch_dml(self, - request: Optional[Union[spanner.ExecuteBatchDmlRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner.ExecuteBatchDmlResponse: - r"""Executes a batch of SQL DML statements. This method allows many - statements to be run with lower latency than submitting them - sequentially with - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. - - Statements are executed in sequential order. A request can - succeed even if a statement fails. The - [ExecuteBatchDmlResponse.status][google.spanner.v1.ExecuteBatchDmlResponse.status] - field in the response provides information about the statement - that failed. Clients must inspect this field to determine - whether an error occurred. - - Execution stops after the first failed statement; the remaining - statements are not executed. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_execute_batch_dml(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - statements = spanner_v1.Statement() - statements.sql = "sql_value" - - request = spanner_v1.ExecuteBatchDmlRequest( - session="session_value", - statements=statements, - seqno=550, - ) - - # Make the request - response = await client.execute_batch_dml(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.ExecuteBatchDmlRequest, dict]]): - The request object. The request for - [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.ExecuteBatchDmlResponse: - The response for [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. Contains a list - of [ResultSet][google.spanner.v1.ResultSet] messages, - one for each DML statement that has successfully - executed, in the same order as the statements in the - request. If a statement fails, the status in the - response body identifies the cause of the failure. - - To check for DML statements that failed, use the - following approach: - - 1. Check the status in the response message. The - [google.rpc.Code][google.rpc.Code] enum value OK - indicates that all statements were executed - successfully. - 2. If the status was not OK, check the number of - result sets in the response. If the response - contains N - [ResultSet][google.spanner.v1.ResultSet] messages, - then statement N+1 in the request failed. - - Example 1: - - - Request: 5 DML statements, all executed - successfully. - - Response: 5 - [ResultSet][google.spanner.v1.ResultSet] messages, - with the status OK. - - Example 2: - - - Request: 5 DML statements. The third statement has - a syntax error. - - Response: 2 - [ResultSet][google.spanner.v1.ResultSet] messages, - and a syntax error (INVALID_ARGUMENT) status. The - number of [ResultSet][google.spanner.v1.ResultSet] - messages indicates that the third statement - failed, and the fourth and fifth statements were - not executed. - - """ - # Create or coerce a protobuf request object. - request = spanner.ExecuteBatchDmlRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.execute_batch_dml, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def read(self, - request: Optional[Union[spanner.ReadRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> result_set.ResultSet: - r"""Reads rows from the database using key lookups and scans, as a - simple key/value style alternative to - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method - cannot be used to return a result set larger than 10 MiB; if the - read matches more data than that, the read fails with a - ``FAILED_PRECONDITION`` error. - - Reads inside read-write transactions might return ``ABORTED``. - If this occurs, the application should restart the transaction - from the beginning. See - [Transaction][google.spanner.v1.Transaction] for more details. - - Larger result sets can be yielded in streaming fashion by - calling [StreamingRead][google.spanner.v1.Spanner.StreamingRead] - instead. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_read(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.ReadRequest( - session="session_value", - table="table_value", - columns=['columns_value1', 'columns_value2'], - ) - - # Make the request - response = await client.read(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.ReadRequest, dict]]): - The request object. The request for [Read][google.spanner.v1.Spanner.Read] - and - [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.ResultSet: - Results from [Read][google.spanner.v1.Spanner.Read] or - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. - - """ - # Create or coerce a protobuf request object. - request = spanner.ReadRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.read, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def streaming_read(self, - request: Optional[Union[spanner.ReadRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> Awaitable[AsyncIterable[result_set.PartialResultSet]]: - r"""Like [Read][google.spanner.v1.Spanner.Read], except returns the - result set as a stream. Unlike - [Read][google.spanner.v1.Spanner.Read], there is no limit on the - size of the returned result set. However, no individual row in - the result set can exceed 100 MiB, and no column value can - exceed 10 MiB. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_streaming_read(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.ReadRequest( - session="session_value", - table="table_value", - columns=['columns_value1', 'columns_value2'], - ) - - # Make the request - stream = await client.streaming_read(request=request) - - # Handle the response - async for response in stream: - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.ReadRequest, dict]]): - The request object. The request for [Read][google.spanner.v1.Spanner.Read] - and - [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - AsyncIterable[google.cloud.spanner_v1.types.PartialResultSet]: - Partial results from a streaming read - or SQL query. Streaming reads and SQL - queries better tolerate large result - sets, large rows, and large values, but - are a little trickier to consume. - - """ - # Create or coerce a protobuf request object. - request = spanner.ReadRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.streaming_read, - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def begin_transaction(self, - request: Optional[Union[spanner.BeginTransactionRequest, dict]] = None, - *, - session: Optional[str] = None, - options: Optional[transaction.TransactionOptions] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> transaction.Transaction: - r"""Begins a new transaction. This step can often be skipped: - [Read][google.spanner.v1.Spanner.Read], - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and - [Commit][google.spanner.v1.Spanner.Commit] can begin a new - transaction as a side-effect. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_begin_transaction(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.BeginTransactionRequest( - session="session_value", - ) - - # Make the request - response = await client.begin_transaction(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.BeginTransactionRequest, dict]]): - The request object. The request for - [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction]. - session (:class:`str`): - Required. The session in which the - transaction runs. - - This corresponds to the ``session`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - options (:class:`google.cloud.spanner_v1.types.TransactionOptions`): - Required. Options for the new - transaction. - - This corresponds to the ``options`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.Transaction: - A transaction. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([session, options]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner.BeginTransactionRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if session is not None: - request.session = session - if options is not None: - request.options = options - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.begin_transaction, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def commit(self, - request: Optional[Union[spanner.CommitRequest, dict]] = None, - *, - session: Optional[str] = None, - transaction_id: Optional[bytes] = None, - mutations: Optional[MutableSequence[mutation.Mutation]] = None, - single_use_transaction: Optional[transaction.TransactionOptions] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> commit_response.CommitResponse: - r"""Commits a transaction. The request includes the mutations to be - applied to rows in the database. - - ``Commit`` might return an ``ABORTED`` error. This can occur at - any time; commonly, the cause is conflicts with concurrent - transactions. However, it can also happen for a variety of other - reasons. If ``Commit`` returns ``ABORTED``, the caller should - re-attempt the transaction from the beginning, re-using the same - session. - - On very rare occasions, ``Commit`` might return ``UNKNOWN``. - This can happen, for example, if the client job experiences a 1+ - hour networking failure. At that point, Cloud Spanner has lost - track of the transaction outcome and we recommend that you - perform another read from the database to see the state of - things as they are now. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_commit(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.CommitRequest( - transaction_id=b'transaction_id_blob', - session="session_value", - ) - - # Make the request - response = await client.commit(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.CommitRequest, dict]]): - The request object. The request for - [Commit][google.spanner.v1.Spanner.Commit]. - session (:class:`str`): - Required. The session in which the - transaction to be committed is running. - - This corresponds to the ``session`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - transaction_id (:class:`bytes`): - Commit a previously-started - transaction. - - This corresponds to the ``transaction_id`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - mutations (:class:`MutableSequence[google.cloud.spanner_v1.types.Mutation]`): - The mutations to be executed when - this transaction commits. All mutations - are applied atomically, in the order - they appear in this list. - - This corresponds to the ``mutations`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - single_use_transaction (:class:`google.cloud.spanner_v1.types.TransactionOptions`): - Execute mutations in a temporary transaction. Note that - unlike commit of a previously-started transaction, - commit with a temporary transaction is non-idempotent. - That is, if the ``CommitRequest`` is sent to Cloud - Spanner more than once (for instance, due to retries in - the application, or in the transport library), it is - possible that the mutations are executed more than once. - If this is undesirable, use - [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction] - and [Commit][google.spanner.v1.Spanner.Commit] instead. - - This corresponds to the ``single_use_transaction`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.CommitResponse: - The response for - [Commit][google.spanner.v1.Spanner.Commit]. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([session, transaction_id, mutations, single_use_transaction]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner.CommitRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if session is not None: - request.session = session - if transaction_id is not None: - request.transaction_id = transaction_id - if single_use_transaction is not None: - request.single_use_transaction = single_use_transaction - if mutations: - request.mutations.extend(mutations) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.commit, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def rollback(self, - request: Optional[Union[spanner.RollbackRequest, dict]] = None, - *, - session: Optional[str] = None, - transaction_id: Optional[bytes] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Rolls back a transaction, releasing any locks it holds. It is a - good idea to call this for any transaction that includes one or - more [Read][google.spanner.v1.Spanner.Read] or - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and - ultimately decides not to commit. - - ``Rollback`` returns ``OK`` if it successfully aborts the - transaction, the transaction was already aborted, or the - transaction is not found. ``Rollback`` never returns - ``ABORTED``. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_rollback(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.RollbackRequest( - session="session_value", - transaction_id=b'transaction_id_blob', - ) - - # Make the request - await client.rollback(request=request) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.RollbackRequest, dict]]): - The request object. The request for - [Rollback][google.spanner.v1.Spanner.Rollback]. - session (:class:`str`): - Required. The session in which the - transaction to roll back is running. - - This corresponds to the ``session`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - transaction_id (:class:`bytes`): - Required. The transaction to roll - back. - - This corresponds to the ``transaction_id`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([session, transaction_id]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner.RollbackRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if session is not None: - request.session = session - if transaction_id is not None: - request.transaction_id = transaction_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.rollback, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def partition_query(self, - request: Optional[Union[spanner.PartitionQueryRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner.PartitionResponse: - r"""Creates a set of partition tokens that can be used to execute a - query operation in parallel. Each of the returned partition - tokens can be used by - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] - to specify a subset of the query result to read. The same - session and read-only transaction must be used by the - PartitionQueryRequest used to create the partition tokens and - the ExecuteSqlRequests that use the partition tokens. - - Partition tokens become invalid when the session used to create - them is deleted, is idle for too long, begins a new transaction, - or becomes too old. When any of these happen, it is not possible - to resume the query, and the whole operation must be restarted - from the beginning. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_partition_query(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.PartitionQueryRequest( - session="session_value", - sql="sql_value", - ) - - # Make the request - response = await client.partition_query(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.PartitionQueryRequest, dict]]): - The request object. The request for - [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.PartitionResponse: - The response for [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] - or - [PartitionRead][google.spanner.v1.Spanner.PartitionRead] - - """ - # Create or coerce a protobuf request object. - request = spanner.PartitionQueryRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.partition_query, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def partition_read(self, - request: Optional[Union[spanner.PartitionReadRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner.PartitionResponse: - r"""Creates a set of partition tokens that can be used to execute a - read operation in parallel. Each of the returned partition - tokens can be used by - [StreamingRead][google.spanner.v1.Spanner.StreamingRead] to - specify a subset of the read result to read. The same session - and read-only transaction must be used by the - PartitionReadRequest used to create the partition tokens and the - ReadRequests that use the partition tokens. There are no - ordering guarantees on rows returned among the returned - partition tokens, or even within each individual StreamingRead - call issued with a partition_token. - - Partition tokens become invalid when the session used to create - them is deleted, is idle for too long, begins a new transaction, - or becomes too old. When any of these happen, it is not possible - to resume the read, and the whole operation must be restarted - from the beginning. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - async def sample_partition_read(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.PartitionReadRequest( - session="session_value", - table="table_value", - ) - - # Make the request - response = await client.partition_read(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_v1.types.PartitionReadRequest, dict]]): - The request object. The request for - [PartitionRead][google.spanner.v1.Spanner.PartitionRead] - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.PartitionResponse: - The response for [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] - or - [PartitionRead][google.spanner.v1.Spanner.PartitionRead] - - """ - # Create or coerce a protobuf request object. - request = spanner.PartitionReadRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.partition_read, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def __aenter__(self): - return self - - async def __aexit__(self, exc_type, exc, tb): - await self.transport.close() - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - - -__all__ = ( - "SpannerAsyncClient", -) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/client.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/client.py deleted file mode 100644 index c867967c7d..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/client.py +++ /dev/null @@ -1,2062 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -import os -import re -from typing import Dict, Mapping, MutableMapping, MutableSequence, Optional, Iterable, Sequence, Tuple, Type, Union, cast - -from google.cloud.spanner_v1 import gapic_version as package_version - -from google.api_core import client_options as client_options_lib -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport import mtls # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore -from google.oauth2 import service_account # type: ignore - -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object] # type: ignore - -from google.cloud.spanner_v1.services.spanner import pagers -from google.cloud.spanner_v1.types import commit_response -from google.cloud.spanner_v1.types import mutation -from google.cloud.spanner_v1.types import result_set -from google.cloud.spanner_v1.types import spanner -from google.cloud.spanner_v1.types import transaction -from google.protobuf import struct_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from .transports.base import SpannerTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import SpannerGrpcTransport -from .transports.grpc_asyncio import SpannerGrpcAsyncIOTransport -from .transports.rest import SpannerRestTransport - - -class SpannerClientMeta(type): - """Metaclass for the Spanner client. - - This provides class-level methods for building and retrieving - support objects (e.g. transport) without polluting the client instance - objects. - """ - _transport_registry = OrderedDict() # type: Dict[str, Type[SpannerTransport]] - _transport_registry["grpc"] = SpannerGrpcTransport - _transport_registry["grpc_asyncio"] = SpannerGrpcAsyncIOTransport - _transport_registry["rest"] = SpannerRestTransport - - def get_transport_class(cls, - label: Optional[str] = None, - ) -> Type[SpannerTransport]: - """Returns an appropriate transport class. - - Args: - label: The name of the desired transport. If none is - provided, then the first transport in the registry is used. - - Returns: - The transport class to use. - """ - # If a specific transport is requested, return that one. - if label: - return cls._transport_registry[label] - - # No transport is requested; return the default (that is, the first one - # in the dictionary). - return next(iter(cls._transport_registry.values())) - - -class SpannerClient(metaclass=SpannerClientMeta): - """Cloud Spanner API - The Cloud Spanner API can be used to manage sessions and execute - transactions on data stored in Cloud Spanner databases. - """ - - @staticmethod - def _get_default_mtls_endpoint(api_endpoint): - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - str: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - DEFAULT_ENDPOINT = "spanner.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - SpannerClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_info(info) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - SpannerClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_file( - filename) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> SpannerTransport: - """Returns the transport used by the client instance. - - Returns: - SpannerTransport: The transport used by the client - instance. - """ - return self._transport - - @staticmethod - def database_path(project: str,instance: str,database: str,) -> str: - """Returns a fully-qualified database string.""" - return "projects/{project}/instances/{instance}/databases/{database}".format(project=project, instance=instance, database=database, ) - - @staticmethod - def parse_database_path(path: str) -> Dict[str,str]: - """Parses a database path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)/databases/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def session_path(project: str,instance: str,database: str,session: str,) -> str: - """Returns a fully-qualified session string.""" - return "projects/{project}/instances/{instance}/databases/{database}/sessions/{session}".format(project=project, instance=instance, database=database, session=session, ) - - @staticmethod - def parse_session_path(path: str) -> Dict[str,str]: - """Parses a session path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)/databases/(?P.+?)/sessions/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_billing_account_path(billing_account: str, ) -> str: - """Returns a fully-qualified billing_account string.""" - return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - - @staticmethod - def parse_common_billing_account_path(path: str) -> Dict[str,str]: - """Parse a billing_account path into its component segments.""" - m = re.match(r"^billingAccounts/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_folder_path(folder: str, ) -> str: - """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder, ) - - @staticmethod - def parse_common_folder_path(path: str) -> Dict[str,str]: - """Parse a folder path into its component segments.""" - m = re.match(r"^folders/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_organization_path(organization: str, ) -> str: - """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization, ) - - @staticmethod - def parse_common_organization_path(path: str) -> Dict[str,str]: - """Parse a organization path into its component segments.""" - m = re.match(r"^organizations/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_project_path(project: str, ) -> str: - """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project, ) - - @staticmethod - def parse_common_project_path(path: str) -> Dict[str,str]: - """Parse a project path into its component segments.""" - m = re.match(r"^projects/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_location_path(project: str, location: str, ) -> str: - """Returns a fully-qualified location string.""" - return "projects/{project}/locations/{location}".format(project=project, location=location, ) - - @staticmethod - def parse_common_location_path(path: str) -> Dict[str,str]: - """Parse a location path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) - return m.groupdict() if m else {} - - @classmethod - def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_options_lib.ClientOptions] = None): - """Return the API endpoint and client cert source for mutual TLS. - - The client cert source is determined in the following order: - (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the - client cert source is None. - (2) if `client_options.client_cert_source` is provided, use the provided one; if the - default client cert source exists, use the default one; otherwise the client cert - source is None. - - The API endpoint is determined in the following order: - (1) if `client_options.api_endpoint` if provided, use the provided one. - (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the - default mTLS endpoint; if the environment variable is "never", use the default API - endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise - use the default API endpoint. - - More details can be found at https://google.aip.dev/auth/4114. - - Args: - client_options (google.api_core.client_options.ClientOptions): Custom options for the - client. Only the `api_endpoint` and `client_cert_source` properties may be used - in this method. - - Returns: - Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the - client cert source to use. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If any errors happen. - """ - if client_options is None: - client_options = client_options_lib.ClientOptions() - use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_client_cert not in ("true", "false"): - raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") - - # Figure out the client cert source to use. - client_cert_source = None - if use_client_cert == "true": - if client_options.client_cert_source: - client_cert_source = client_options.client_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): - api_endpoint = cls.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = cls.DEFAULT_ENDPOINT - - return api_endpoint, client_cert_source - - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Optional[Union[str, SpannerTransport]] = None, - client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the spanner client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Union[str, SpannerTransport]): The - transport to use. If set to None, a transport is chosen - automatically. - client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the - client. It won't take effect if a ``transport`` instance is provided. - (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT - environment variable can also be used to override the endpoint: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto switch to the - default mTLS endpoint if client certificate is present, this is - the default value). However, the ``api_endpoint`` property takes - precedence if provided. - (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide client certificate for mutual TLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - """ - if isinstance(client_options, dict): - client_options = client_options_lib.from_dict(client_options) - if client_options is None: - client_options = client_options_lib.ClientOptions() - client_options = cast(client_options_lib.ClientOptions, client_options) - - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source(client_options) - - api_key_value = getattr(client_options, "api_key", None) - if api_key_value and credentials: - raise ValueError("client_options.api_key and credentials are mutually exclusive") - - # Save or instantiate the transport. - # Ordinarily, we provide the transport, but allowing a custom transport - # instance provides an extensibility point for unusual situations. - if isinstance(transport, SpannerTransport): - # transport is a SpannerTransport instance. - if credentials or client_options.credentials_file or api_key_value: - raise ValueError("When providing a transport instance, " - "provide its credentials directly.") - if client_options.scopes: - raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." - ) - self._transport = transport - else: - import google.auth._default # type: ignore - - if api_key_value and hasattr(google.auth._default, "get_api_key_credentials"): - credentials = google.auth._default.get_api_key_credentials(api_key_value) - - Transport = type(self).get_transport_class(transport) - self._transport = Transport( - credentials=credentials, - credentials_file=client_options.credentials_file, - host=api_endpoint, - scopes=client_options.scopes, - client_cert_source_for_mtls=client_cert_source_func, - quota_project_id=client_options.quota_project_id, - client_info=client_info, - always_use_jwt_access=True, - api_audience=client_options.api_audience, - ) - - def create_session(self, - request: Optional[Union[spanner.CreateSessionRequest, dict]] = None, - *, - database: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner.Session: - r"""Creates a new session. A session can be used to perform - transactions that read and/or modify data in a Cloud Spanner - database. Sessions are meant to be reused for many consecutive - transactions. - - Sessions can only execute one transaction at a time. To execute - multiple concurrent read-write/write-only transactions, create - multiple sessions. Note that standalone reads and queries use a - transaction internally, and count toward the one transaction - limit. - - Active sessions use additional server resources, so it is a good - idea to delete idle and unneeded sessions. Aside from explicit - deletes, Cloud Spanner may delete sessions for which no - operations are sent for more than an hour. If a session is - deleted, requests to it return ``NOT_FOUND``. - - Idle sessions can be kept alive by sending a trivial SQL query - periodically, e.g., ``"SELECT 1"``. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_create_session(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.CreateSessionRequest( - database="database_value", - ) - - # Make the request - response = client.create_session(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_v1.types.CreateSessionRequest, dict]): - The request object. The request for - [CreateSession][google.spanner.v1.Spanner.CreateSession]. - database (str): - Required. The database in which the - new session is created. - - This corresponds to the ``database`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.Session: - A session in the Cloud Spanner API. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([database]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner.CreateSessionRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.CreateSessionRequest): - request = spanner.CreateSessionRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if database is not None: - request.database = database - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_session] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("database", request.database), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def batch_create_sessions(self, - request: Optional[Union[spanner.BatchCreateSessionsRequest, dict]] = None, - *, - database: Optional[str] = None, - session_count: Optional[int] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner.BatchCreateSessionsResponse: - r"""Creates multiple new sessions. - This API can be used to initialize a session cache on - the clients. See https://goo.gl/TgSFN2 for best - practices on session cache management. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_batch_create_sessions(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.BatchCreateSessionsRequest( - database="database_value", - session_count=1420, - ) - - # Make the request - response = client.batch_create_sessions(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_v1.types.BatchCreateSessionsRequest, dict]): - The request object. The request for - [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. - database (str): - Required. The database in which the - new sessions are created. - - This corresponds to the ``database`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - session_count (int): - Required. The number of sessions to be created in this - batch call. The API may return fewer than the requested - number of sessions. If a specific number of sessions are - desired, the client can make additional calls to - BatchCreateSessions (adjusting - [session_count][google.spanner.v1.BatchCreateSessionsRequest.session_count] - as necessary). - - This corresponds to the ``session_count`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.BatchCreateSessionsResponse: - The response for - [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([database, session_count]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner.BatchCreateSessionsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.BatchCreateSessionsRequest): - request = spanner.BatchCreateSessionsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if database is not None: - request.database = database - if session_count is not None: - request.session_count = session_count - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.batch_create_sessions] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("database", request.database), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def get_session(self, - request: Optional[Union[spanner.GetSessionRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner.Session: - r"""Gets a session. Returns ``NOT_FOUND`` if the session does not - exist. This is mainly useful for determining whether a session - is still alive. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_get_session(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.GetSessionRequest( - name="name_value", - ) - - # Make the request - response = client.get_session(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_v1.types.GetSessionRequest, dict]): - The request object. The request for - [GetSession][google.spanner.v1.Spanner.GetSession]. - name (str): - Required. The name of the session to - retrieve. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.Session: - A session in the Cloud Spanner API. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner.GetSessionRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.GetSessionRequest): - request = spanner.GetSessionRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.get_session] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def list_sessions(self, - request: Optional[Union[spanner.ListSessionsRequest, dict]] = None, - *, - database: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListSessionsPager: - r"""Lists all sessions in a given database. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_list_sessions(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.ListSessionsRequest( - database="database_value", - ) - - # Make the request - page_result = client.list_sessions(request=request) - - # Handle the response - for response in page_result: - print(response) - - Args: - request (Union[google.cloud.spanner_v1.types.ListSessionsRequest, dict]): - The request object. The request for - [ListSessions][google.spanner.v1.Spanner.ListSessions]. - database (str): - Required. The database in which to - list sessions. - - This corresponds to the ``database`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.services.spanner.pagers.ListSessionsPager: - The response for - [ListSessions][google.spanner.v1.Spanner.ListSessions]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([database]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner.ListSessionsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.ListSessionsRequest): - request = spanner.ListSessionsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if database is not None: - request.database = database - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_sessions] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("database", request.database), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListSessionsPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def delete_session(self, - request: Optional[Union[spanner.DeleteSessionRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Ends a session, releasing server resources associated - with it. This will asynchronously trigger cancellation - of any operations that are running with this session. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_delete_session(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.DeleteSessionRequest( - name="name_value", - ) - - # Make the request - client.delete_session(request=request) - - Args: - request (Union[google.cloud.spanner_v1.types.DeleteSessionRequest, dict]): - The request object. The request for - [DeleteSession][google.spanner.v1.Spanner.DeleteSession]. - name (str): - Required. The name of the session to - delete. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner.DeleteSessionRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.DeleteSessionRequest): - request = spanner.DeleteSessionRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.delete_session] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def execute_sql(self, - request: Optional[Union[spanner.ExecuteSqlRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> result_set.ResultSet: - r"""Executes an SQL statement, returning all results in a single - reply. This method cannot be used to return a result set larger - than 10 MiB; if the query yields more data than that, the query - fails with a ``FAILED_PRECONDITION`` error. - - Operations inside read-write transactions might return - ``ABORTED``. If this occurs, the application should restart the - transaction from the beginning. See - [Transaction][google.spanner.v1.Transaction] for more details. - - Larger result sets can be fetched in streaming fashion by - calling - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] - instead. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_execute_sql(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.ExecuteSqlRequest( - session="session_value", - sql="sql_value", - ) - - # Make the request - response = client.execute_sql(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_v1.types.ExecuteSqlRequest, dict]): - The request object. The request for - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.ResultSet: - Results from [Read][google.spanner.v1.Spanner.Read] or - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. - - """ - # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a spanner.ExecuteSqlRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.ExecuteSqlRequest): - request = spanner.ExecuteSqlRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.execute_sql] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def execute_streaming_sql(self, - request: Optional[Union[spanner.ExecuteSqlRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> Iterable[result_set.PartialResultSet]: - r"""Like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except - returns the result set as a stream. Unlike - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there is no - limit on the size of the returned result set. However, no - individual row in the result set can exceed 100 MiB, and no - column value can exceed 10 MiB. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_execute_streaming_sql(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.ExecuteSqlRequest( - session="session_value", - sql="sql_value", - ) - - # Make the request - stream = client.execute_streaming_sql(request=request) - - # Handle the response - for response in stream: - print(response) - - Args: - request (Union[google.cloud.spanner_v1.types.ExecuteSqlRequest, dict]): - The request object. The request for - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - Iterable[google.cloud.spanner_v1.types.PartialResultSet]: - Partial results from a streaming read - or SQL query. Streaming reads and SQL - queries better tolerate large result - sets, large rows, and large values, but - are a little trickier to consume. - - """ - # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a spanner.ExecuteSqlRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.ExecuteSqlRequest): - request = spanner.ExecuteSqlRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.execute_streaming_sql] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def execute_batch_dml(self, - request: Optional[Union[spanner.ExecuteBatchDmlRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner.ExecuteBatchDmlResponse: - r"""Executes a batch of SQL DML statements. This method allows many - statements to be run with lower latency than submitting them - sequentially with - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. - - Statements are executed in sequential order. A request can - succeed even if a statement fails. The - [ExecuteBatchDmlResponse.status][google.spanner.v1.ExecuteBatchDmlResponse.status] - field in the response provides information about the statement - that failed. Clients must inspect this field to determine - whether an error occurred. - - Execution stops after the first failed statement; the remaining - statements are not executed. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_execute_batch_dml(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - statements = spanner_v1.Statement() - statements.sql = "sql_value" - - request = spanner_v1.ExecuteBatchDmlRequest( - session="session_value", - statements=statements, - seqno=550, - ) - - # Make the request - response = client.execute_batch_dml(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_v1.types.ExecuteBatchDmlRequest, dict]): - The request object. The request for - [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.ExecuteBatchDmlResponse: - The response for [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. Contains a list - of [ResultSet][google.spanner.v1.ResultSet] messages, - one for each DML statement that has successfully - executed, in the same order as the statements in the - request. If a statement fails, the status in the - response body identifies the cause of the failure. - - To check for DML statements that failed, use the - following approach: - - 1. Check the status in the response message. The - [google.rpc.Code][google.rpc.Code] enum value OK - indicates that all statements were executed - successfully. - 2. If the status was not OK, check the number of - result sets in the response. If the response - contains N - [ResultSet][google.spanner.v1.ResultSet] messages, - then statement N+1 in the request failed. - - Example 1: - - - Request: 5 DML statements, all executed - successfully. - - Response: 5 - [ResultSet][google.spanner.v1.ResultSet] messages, - with the status OK. - - Example 2: - - - Request: 5 DML statements. The third statement has - a syntax error. - - Response: 2 - [ResultSet][google.spanner.v1.ResultSet] messages, - and a syntax error (INVALID_ARGUMENT) status. The - number of [ResultSet][google.spanner.v1.ResultSet] - messages indicates that the third statement - failed, and the fourth and fifth statements were - not executed. - - """ - # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a spanner.ExecuteBatchDmlRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.ExecuteBatchDmlRequest): - request = spanner.ExecuteBatchDmlRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.execute_batch_dml] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def read(self, - request: Optional[Union[spanner.ReadRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> result_set.ResultSet: - r"""Reads rows from the database using key lookups and scans, as a - simple key/value style alternative to - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method - cannot be used to return a result set larger than 10 MiB; if the - read matches more data than that, the read fails with a - ``FAILED_PRECONDITION`` error. - - Reads inside read-write transactions might return ``ABORTED``. - If this occurs, the application should restart the transaction - from the beginning. See - [Transaction][google.spanner.v1.Transaction] for more details. - - Larger result sets can be yielded in streaming fashion by - calling [StreamingRead][google.spanner.v1.Spanner.StreamingRead] - instead. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_read(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.ReadRequest( - session="session_value", - table="table_value", - columns=['columns_value1', 'columns_value2'], - ) - - # Make the request - response = client.read(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_v1.types.ReadRequest, dict]): - The request object. The request for [Read][google.spanner.v1.Spanner.Read] - and - [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.ResultSet: - Results from [Read][google.spanner.v1.Spanner.Read] or - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. - - """ - # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a spanner.ReadRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.ReadRequest): - request = spanner.ReadRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.read] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def streaming_read(self, - request: Optional[Union[spanner.ReadRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> Iterable[result_set.PartialResultSet]: - r"""Like [Read][google.spanner.v1.Spanner.Read], except returns the - result set as a stream. Unlike - [Read][google.spanner.v1.Spanner.Read], there is no limit on the - size of the returned result set. However, no individual row in - the result set can exceed 100 MiB, and no column value can - exceed 10 MiB. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_streaming_read(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.ReadRequest( - session="session_value", - table="table_value", - columns=['columns_value1', 'columns_value2'], - ) - - # Make the request - stream = client.streaming_read(request=request) - - # Handle the response - for response in stream: - print(response) - - Args: - request (Union[google.cloud.spanner_v1.types.ReadRequest, dict]): - The request object. The request for [Read][google.spanner.v1.Spanner.Read] - and - [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - Iterable[google.cloud.spanner_v1.types.PartialResultSet]: - Partial results from a streaming read - or SQL query. Streaming reads and SQL - queries better tolerate large result - sets, large rows, and large values, but - are a little trickier to consume. - - """ - # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a spanner.ReadRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.ReadRequest): - request = spanner.ReadRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.streaming_read] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def begin_transaction(self, - request: Optional[Union[spanner.BeginTransactionRequest, dict]] = None, - *, - session: Optional[str] = None, - options: Optional[transaction.TransactionOptions] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> transaction.Transaction: - r"""Begins a new transaction. This step can often be skipped: - [Read][google.spanner.v1.Spanner.Read], - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and - [Commit][google.spanner.v1.Spanner.Commit] can begin a new - transaction as a side-effect. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_begin_transaction(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.BeginTransactionRequest( - session="session_value", - ) - - # Make the request - response = client.begin_transaction(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_v1.types.BeginTransactionRequest, dict]): - The request object. The request for - [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction]. - session (str): - Required. The session in which the - transaction runs. - - This corresponds to the ``session`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - options (google.cloud.spanner_v1.types.TransactionOptions): - Required. Options for the new - transaction. - - This corresponds to the ``options`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.Transaction: - A transaction. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([session, options]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner.BeginTransactionRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.BeginTransactionRequest): - request = spanner.BeginTransactionRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if session is not None: - request.session = session - if options is not None: - request.options = options - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.begin_transaction] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def commit(self, - request: Optional[Union[spanner.CommitRequest, dict]] = None, - *, - session: Optional[str] = None, - transaction_id: Optional[bytes] = None, - mutations: Optional[MutableSequence[mutation.Mutation]] = None, - single_use_transaction: Optional[transaction.TransactionOptions] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> commit_response.CommitResponse: - r"""Commits a transaction. The request includes the mutations to be - applied to rows in the database. - - ``Commit`` might return an ``ABORTED`` error. This can occur at - any time; commonly, the cause is conflicts with concurrent - transactions. However, it can also happen for a variety of other - reasons. If ``Commit`` returns ``ABORTED``, the caller should - re-attempt the transaction from the beginning, re-using the same - session. - - On very rare occasions, ``Commit`` might return ``UNKNOWN``. - This can happen, for example, if the client job experiences a 1+ - hour networking failure. At that point, Cloud Spanner has lost - track of the transaction outcome and we recommend that you - perform another read from the database to see the state of - things as they are now. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_commit(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.CommitRequest( - transaction_id=b'transaction_id_blob', - session="session_value", - ) - - # Make the request - response = client.commit(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_v1.types.CommitRequest, dict]): - The request object. The request for - [Commit][google.spanner.v1.Spanner.Commit]. - session (str): - Required. The session in which the - transaction to be committed is running. - - This corresponds to the ``session`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - transaction_id (bytes): - Commit a previously-started - transaction. - - This corresponds to the ``transaction_id`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - mutations (MutableSequence[google.cloud.spanner_v1.types.Mutation]): - The mutations to be executed when - this transaction commits. All mutations - are applied atomically, in the order - they appear in this list. - - This corresponds to the ``mutations`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - single_use_transaction (google.cloud.spanner_v1.types.TransactionOptions): - Execute mutations in a temporary transaction. Note that - unlike commit of a previously-started transaction, - commit with a temporary transaction is non-idempotent. - That is, if the ``CommitRequest`` is sent to Cloud - Spanner more than once (for instance, due to retries in - the application, or in the transport library), it is - possible that the mutations are executed more than once. - If this is undesirable, use - [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction] - and [Commit][google.spanner.v1.Spanner.Commit] instead. - - This corresponds to the ``single_use_transaction`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.CommitResponse: - The response for - [Commit][google.spanner.v1.Spanner.Commit]. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([session, transaction_id, mutations, single_use_transaction]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner.CommitRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.CommitRequest): - request = spanner.CommitRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if session is not None: - request.session = session - if transaction_id is not None: - request.transaction_id = transaction_id - if mutations is not None: - request.mutations = mutations - if single_use_transaction is not None: - request.single_use_transaction = single_use_transaction - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.commit] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def rollback(self, - request: Optional[Union[spanner.RollbackRequest, dict]] = None, - *, - session: Optional[str] = None, - transaction_id: Optional[bytes] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Rolls back a transaction, releasing any locks it holds. It is a - good idea to call this for any transaction that includes one or - more [Read][google.spanner.v1.Spanner.Read] or - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and - ultimately decides not to commit. - - ``Rollback`` returns ``OK`` if it successfully aborts the - transaction, the transaction was already aborted, or the - transaction is not found. ``Rollback`` never returns - ``ABORTED``. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_rollback(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.RollbackRequest( - session="session_value", - transaction_id=b'transaction_id_blob', - ) - - # Make the request - client.rollback(request=request) - - Args: - request (Union[google.cloud.spanner_v1.types.RollbackRequest, dict]): - The request object. The request for - [Rollback][google.spanner.v1.Spanner.Rollback]. - session (str): - Required. The session in which the - transaction to roll back is running. - - This corresponds to the ``session`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - transaction_id (bytes): - Required. The transaction to roll - back. - - This corresponds to the ``transaction_id`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([session, transaction_id]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner.RollbackRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.RollbackRequest): - request = spanner.RollbackRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if session is not None: - request.session = session - if transaction_id is not None: - request.transaction_id = transaction_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.rollback] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def partition_query(self, - request: Optional[Union[spanner.PartitionQueryRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner.PartitionResponse: - r"""Creates a set of partition tokens that can be used to execute a - query operation in parallel. Each of the returned partition - tokens can be used by - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] - to specify a subset of the query result to read. The same - session and read-only transaction must be used by the - PartitionQueryRequest used to create the partition tokens and - the ExecuteSqlRequests that use the partition tokens. - - Partition tokens become invalid when the session used to create - them is deleted, is idle for too long, begins a new transaction, - or becomes too old. When any of these happen, it is not possible - to resume the query, and the whole operation must be restarted - from the beginning. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_partition_query(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.PartitionQueryRequest( - session="session_value", - sql="sql_value", - ) - - # Make the request - response = client.partition_query(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_v1.types.PartitionQueryRequest, dict]): - The request object. The request for - [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.PartitionResponse: - The response for [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] - or - [PartitionRead][google.spanner.v1.Spanner.PartitionRead] - - """ - # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a spanner.PartitionQueryRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.PartitionQueryRequest): - request = spanner.PartitionQueryRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.partition_query] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def partition_read(self, - request: Optional[Union[spanner.PartitionReadRequest, dict]] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner.PartitionResponse: - r"""Creates a set of partition tokens that can be used to execute a - read operation in parallel. Each of the returned partition - tokens can be used by - [StreamingRead][google.spanner.v1.Spanner.StreamingRead] to - specify a subset of the read result to read. The same session - and read-only transaction must be used by the - PartitionReadRequest used to create the partition tokens and the - ReadRequests that use the partition tokens. There are no - ordering guarantees on rows returned among the returned - partition tokens, or even within each individual StreamingRead - call issued with a partition_token. - - Partition tokens become invalid when the session used to create - them is deleted, is idle for too long, begins a new transaction, - or becomes too old. When any of these happen, it is not possible - to resume the read, and the whole operation must be restarted - from the beginning. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_v1 - - def sample_partition_read(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.PartitionReadRequest( - session="session_value", - table="table_value", - ) - - # Make the request - response = client.partition_read(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_v1.types.PartitionReadRequest, dict]): - The request object. The request for - [PartitionRead][google.spanner.v1.Spanner.PartitionRead] - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_v1.types.PartitionResponse: - The response for [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] - or - [PartitionRead][google.spanner.v1.Spanner.PartitionRead] - - """ - # Create or coerce a protobuf request object. - # Minor optimization to avoid making a copy if the user passes - # in a spanner.PartitionReadRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner.PartitionReadRequest): - request = spanner.PartitionReadRequest(request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.partition_read] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("session", request.session), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def __enter__(self) -> "SpannerClient": - return self - - def __exit__(self, type, value, traceback): - """Releases underlying transport's resources. - - .. warning:: - ONLY use as a context manager if the transport is NOT shared - with other clients! Exiting the with block will CLOSE the transport - and may cause errors in other clients! - """ - self.transport.close() - - - - - - - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - - -__all__ = ( - "SpannerClient", -) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/pagers.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/pagers.py deleted file mode 100644 index 6036124ab4..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/pagers.py +++ /dev/null @@ -1,139 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from typing import Any, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator - -from google.cloud.spanner_v1.types import spanner - - -class ListSessionsPager: - """A pager for iterating through ``list_sessions`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_v1.types.ListSessionsResponse` object, and - provides an ``__iter__`` method to iterate through its - ``sessions`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListSessions`` requests and continue to iterate - through the ``sessions`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_v1.types.ListSessionsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., spanner.ListSessionsResponse], - request: spanner.ListSessionsRequest, - response: spanner.ListSessionsResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_v1.types.ListSessionsRequest): - The initial request object. - response (google.cloud.spanner_v1.types.ListSessionsResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = spanner.ListSessionsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[spanner.ListSessionsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, metadata=self._metadata) - yield self._response - - def __iter__(self) -> Iterator[spanner.Session]: - for page in self.pages: - yield from page.sessions - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListSessionsAsyncPager: - """A pager for iterating through ``list_sessions`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_v1.types.ListSessionsResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``sessions`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListSessions`` requests and continue to iterate - through the ``sessions`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_v1.types.ListSessionsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., Awaitable[spanner.ListSessionsResponse]], - request: spanner.ListSessionsRequest, - response: spanner.ListSessionsResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiates the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_v1.types.ListSessionsRequest): - The initial request object. - response (google.cloud.spanner_v1.types.ListSessionsResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = spanner.ListSessionsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[spanner.ListSessionsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, metadata=self._metadata) - yield self._response - def __aiter__(self) -> AsyncIterator[spanner.Session]: - async def async_generator(): - async for page in self.pages: - for response in page.sessions: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/__init__.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/__init__.py deleted file mode 100644 index 8451357b75..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/__init__.py +++ /dev/null @@ -1,38 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -from typing import Dict, Type - -from .base import SpannerTransport -from .grpc import SpannerGrpcTransport -from .grpc_asyncio import SpannerGrpcAsyncIOTransport -from .rest import SpannerRestTransport -from .rest import SpannerRestInterceptor - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[SpannerTransport]] -_transport_registry['grpc'] = SpannerGrpcTransport -_transport_registry['grpc_asyncio'] = SpannerGrpcAsyncIOTransport -_transport_registry['rest'] = SpannerRestTransport - -__all__ = ( - 'SpannerTransport', - 'SpannerGrpcTransport', - 'SpannerGrpcAsyncIOTransport', - 'SpannerRestTransport', - 'SpannerRestInterceptor', -) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/base.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/base.py deleted file mode 100644 index fa0f6b008d..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/base.py +++ /dev/null @@ -1,427 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union - -from google.cloud.spanner_v1 import gapic_version as package_version - -import google.auth # type: ignore -import google.api_core -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore - -from google.cloud.spanner_v1.types import commit_response -from google.cloud.spanner_v1.types import result_set -from google.cloud.spanner_v1.types import spanner -from google.cloud.spanner_v1.types import transaction -from google.protobuf import empty_pb2 # type: ignore - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - - -class SpannerTransport(abc.ABC): - """Abstract transport class for Spanner.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.data', - ) - - DEFAULT_HOST: str = 'spanner.googleapis.com' - def __init__( - self, *, - host: str = DEFAULT_HOST, - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - **kwargs, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A list of scopes. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - """ - - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - - # Save the scopes. - self._scopes = scopes - - # If no credentials are provided, then determine the appropriate - # defaults. - if credentials and credentials_file: - raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") - - if credentials_file is not None: - credentials, _ = google.auth.load_credentials_from_file( - credentials_file, - **scopes_kwargs, - quota_project_id=quota_project_id - ) - elif credentials is None: - credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) - # Don't apply audience if the credentials file passed from user. - if hasattr(credentials, "with_gdch_audience"): - credentials = credentials.with_gdch_audience(api_audience if api_audience else host) - - # If the credentials are service account credentials, then always try to use self signed JWT. - if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): - credentials = credentials.with_always_use_jwt_access(True) - - # Save the credentials. - self._credentials = credentials - - # Save the hostname. Default to port 443 (HTTPS) if none is specified. - if ':' not in host: - host += ':443' - self._host = host - - def _prep_wrapped_messages(self, client_info): - # Precompute the wrapped methods. - self._wrapped_methods = { - self.create_session: gapic_v1.method.wrap_method( - self.create_session, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=client_info, - ), - self.batch_create_sessions: gapic_v1.method.wrap_method( - self.batch_create_sessions, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=60.0, - ), - default_timeout=60.0, - client_info=client_info, - ), - self.get_session: gapic_v1.method.wrap_method( - self.get_session, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=client_info, - ), - self.list_sessions: gapic_v1.method.wrap_method( - self.list_sessions, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.delete_session: gapic_v1.method.wrap_method( - self.delete_session, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=client_info, - ), - self.execute_sql: gapic_v1.method.wrap_method( - self.execute_sql, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=client_info, - ), - self.execute_streaming_sql: gapic_v1.method.wrap_method( - self.execute_streaming_sql, - default_timeout=3600.0, - client_info=client_info, - ), - self.execute_batch_dml: gapic_v1.method.wrap_method( - self.execute_batch_dml, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=client_info, - ), - self.read: gapic_v1.method.wrap_method( - self.read, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=client_info, - ), - self.streaming_read: gapic_v1.method.wrap_method( - self.streaming_read, - default_timeout=3600.0, - client_info=client_info, - ), - self.begin_transaction: gapic_v1.method.wrap_method( - self.begin_transaction, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=client_info, - ), - self.commit: gapic_v1.method.wrap_method( - self.commit, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.rollback: gapic_v1.method.wrap_method( - self.rollback, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=client_info, - ), - self.partition_query: gapic_v1.method.wrap_method( - self.partition_query, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=client_info, - ), - self.partition_read: gapic_v1.method.wrap_method( - self.partition_read, - default_retry=retries.Retry( -initial=0.25,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=client_info, - ), - } - - def close(self): - """Closes resources associated with the transport. - - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! - """ - raise NotImplementedError() - - @property - def create_session(self) -> Callable[ - [spanner.CreateSessionRequest], - Union[ - spanner.Session, - Awaitable[spanner.Session] - ]]: - raise NotImplementedError() - - @property - def batch_create_sessions(self) -> Callable[ - [spanner.BatchCreateSessionsRequest], - Union[ - spanner.BatchCreateSessionsResponse, - Awaitable[spanner.BatchCreateSessionsResponse] - ]]: - raise NotImplementedError() - - @property - def get_session(self) -> Callable[ - [spanner.GetSessionRequest], - Union[ - spanner.Session, - Awaitable[spanner.Session] - ]]: - raise NotImplementedError() - - @property - def list_sessions(self) -> Callable[ - [spanner.ListSessionsRequest], - Union[ - spanner.ListSessionsResponse, - Awaitable[spanner.ListSessionsResponse] - ]]: - raise NotImplementedError() - - @property - def delete_session(self) -> Callable[ - [spanner.DeleteSessionRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def execute_sql(self) -> Callable[ - [spanner.ExecuteSqlRequest], - Union[ - result_set.ResultSet, - Awaitable[result_set.ResultSet] - ]]: - raise NotImplementedError() - - @property - def execute_streaming_sql(self) -> Callable[ - [spanner.ExecuteSqlRequest], - Union[ - result_set.PartialResultSet, - Awaitable[result_set.PartialResultSet] - ]]: - raise NotImplementedError() - - @property - def execute_batch_dml(self) -> Callable[ - [spanner.ExecuteBatchDmlRequest], - Union[ - spanner.ExecuteBatchDmlResponse, - Awaitable[spanner.ExecuteBatchDmlResponse] - ]]: - raise NotImplementedError() - - @property - def read(self) -> Callable[ - [spanner.ReadRequest], - Union[ - result_set.ResultSet, - Awaitable[result_set.ResultSet] - ]]: - raise NotImplementedError() - - @property - def streaming_read(self) -> Callable[ - [spanner.ReadRequest], - Union[ - result_set.PartialResultSet, - Awaitable[result_set.PartialResultSet] - ]]: - raise NotImplementedError() - - @property - def begin_transaction(self) -> Callable[ - [spanner.BeginTransactionRequest], - Union[ - transaction.Transaction, - Awaitable[transaction.Transaction] - ]]: - raise NotImplementedError() - - @property - def commit(self) -> Callable[ - [spanner.CommitRequest], - Union[ - commit_response.CommitResponse, - Awaitable[commit_response.CommitResponse] - ]]: - raise NotImplementedError() - - @property - def rollback(self) -> Callable[ - [spanner.RollbackRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def partition_query(self) -> Callable[ - [spanner.PartitionQueryRequest], - Union[ - spanner.PartitionResponse, - Awaitable[spanner.PartitionResponse] - ]]: - raise NotImplementedError() - - @property - def partition_read(self) -> Callable[ - [spanner.PartitionReadRequest], - Union[ - spanner.PartitionResponse, - Awaitable[spanner.PartitionResponse] - ]]: - raise NotImplementedError() - - @property - def kind(self) -> str: - raise NotImplementedError() - - -__all__ = ( - 'SpannerTransport', -) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc.py deleted file mode 100644 index 491151f614..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc.py +++ /dev/null @@ -1,766 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import grpc_helpers -from google.api_core import gapic_v1 -import google.auth # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore - -import grpc # type: ignore - -from google.cloud.spanner_v1.types import commit_response -from google.cloud.spanner_v1.types import result_set -from google.cloud.spanner_v1.types import spanner -from google.cloud.spanner_v1.types import transaction -from google.protobuf import empty_pb2 # type: ignore -from .base import SpannerTransport, DEFAULT_CLIENT_INFO - - -class SpannerGrpcTransport(SpannerTransport): - """gRPC backend transport for Spanner. - - Cloud Spanner API - The Cloud Spanner API can be used to manage sessions and execute - transactions on data stored in Cloud Spanner databases. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - _stubs: Dict[str, Callable] - - def __init__(self, *, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: Optional[grpc.Channel] = None, - api_mtls_endpoint: Optional[str] = None, - client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, - client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if ``channel`` is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - channel (Optional[grpc.Channel]): A ``Channel`` instance through - which to make calls. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or application default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if ``channel`` is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if channel: - # Ignore credentials if a channel was passed. - credentials = False - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience, - ) - - if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( - self._host, - # use the credentials which are saved - credentials=self._credentials, - # Set ``credentials_file`` to ``None`` here as - # the credentials that we saved earlier should be used. - credentials_file=None, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Wrap messages. This must be done after self._grpc_channel exists - self._prep_wrapped_messages(client_info) - - @classmethod - def create_channel(cls, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> grpc.Channel: - """Create and return a gRPC channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - grpc.Channel: A gRPC channel object. - - Raises: - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - - return grpc_helpers.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - @property - def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ - return self._grpc_channel - - @property - def create_session(self) -> Callable[ - [spanner.CreateSessionRequest], - spanner.Session]: - r"""Return a callable for the create session method over gRPC. - - Creates a new session. A session can be used to perform - transactions that read and/or modify data in a Cloud Spanner - database. Sessions are meant to be reused for many consecutive - transactions. - - Sessions can only execute one transaction at a time. To execute - multiple concurrent read-write/write-only transactions, create - multiple sessions. Note that standalone reads and queries use a - transaction internally, and count toward the one transaction - limit. - - Active sessions use additional server resources, so it is a good - idea to delete idle and unneeded sessions. Aside from explicit - deletes, Cloud Spanner may delete sessions for which no - operations are sent for more than an hour. If a session is - deleted, requests to it return ``NOT_FOUND``. - - Idle sessions can be kept alive by sending a trivial SQL query - periodically, e.g., ``"SELECT 1"``. - - Returns: - Callable[[~.CreateSessionRequest], - ~.Session]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'create_session' not in self._stubs: - self._stubs['create_session'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/CreateSession', - request_serializer=spanner.CreateSessionRequest.serialize, - response_deserializer=spanner.Session.deserialize, - ) - return self._stubs['create_session'] - - @property - def batch_create_sessions(self) -> Callable[ - [spanner.BatchCreateSessionsRequest], - spanner.BatchCreateSessionsResponse]: - r"""Return a callable for the batch create sessions method over gRPC. - - Creates multiple new sessions. - This API can be used to initialize a session cache on - the clients. See https://goo.gl/TgSFN2 for best - practices on session cache management. - - Returns: - Callable[[~.BatchCreateSessionsRequest], - ~.BatchCreateSessionsResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'batch_create_sessions' not in self._stubs: - self._stubs['batch_create_sessions'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/BatchCreateSessions', - request_serializer=spanner.BatchCreateSessionsRequest.serialize, - response_deserializer=spanner.BatchCreateSessionsResponse.deserialize, - ) - return self._stubs['batch_create_sessions'] - - @property - def get_session(self) -> Callable[ - [spanner.GetSessionRequest], - spanner.Session]: - r"""Return a callable for the get session method over gRPC. - - Gets a session. Returns ``NOT_FOUND`` if the session does not - exist. This is mainly useful for determining whether a session - is still alive. - - Returns: - Callable[[~.GetSessionRequest], - ~.Session]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_session' not in self._stubs: - self._stubs['get_session'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/GetSession', - request_serializer=spanner.GetSessionRequest.serialize, - response_deserializer=spanner.Session.deserialize, - ) - return self._stubs['get_session'] - - @property - def list_sessions(self) -> Callable[ - [spanner.ListSessionsRequest], - spanner.ListSessionsResponse]: - r"""Return a callable for the list sessions method over gRPC. - - Lists all sessions in a given database. - - Returns: - Callable[[~.ListSessionsRequest], - ~.ListSessionsResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_sessions' not in self._stubs: - self._stubs['list_sessions'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/ListSessions', - request_serializer=spanner.ListSessionsRequest.serialize, - response_deserializer=spanner.ListSessionsResponse.deserialize, - ) - return self._stubs['list_sessions'] - - @property - def delete_session(self) -> Callable[ - [spanner.DeleteSessionRequest], - empty_pb2.Empty]: - r"""Return a callable for the delete session method over gRPC. - - Ends a session, releasing server resources associated - with it. This will asynchronously trigger cancellation - of any operations that are running with this session. - - Returns: - Callable[[~.DeleteSessionRequest], - ~.Empty]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'delete_session' not in self._stubs: - self._stubs['delete_session'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/DeleteSession', - request_serializer=spanner.DeleteSessionRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_session'] - - @property - def execute_sql(self) -> Callable[ - [spanner.ExecuteSqlRequest], - result_set.ResultSet]: - r"""Return a callable for the execute sql method over gRPC. - - Executes an SQL statement, returning all results in a single - reply. This method cannot be used to return a result set larger - than 10 MiB; if the query yields more data than that, the query - fails with a ``FAILED_PRECONDITION`` error. - - Operations inside read-write transactions might return - ``ABORTED``. If this occurs, the application should restart the - transaction from the beginning. See - [Transaction][google.spanner.v1.Transaction] for more details. - - Larger result sets can be fetched in streaming fashion by - calling - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] - instead. - - Returns: - Callable[[~.ExecuteSqlRequest], - ~.ResultSet]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'execute_sql' not in self._stubs: - self._stubs['execute_sql'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/ExecuteSql', - request_serializer=spanner.ExecuteSqlRequest.serialize, - response_deserializer=result_set.ResultSet.deserialize, - ) - return self._stubs['execute_sql'] - - @property - def execute_streaming_sql(self) -> Callable[ - [spanner.ExecuteSqlRequest], - result_set.PartialResultSet]: - r"""Return a callable for the execute streaming sql method over gRPC. - - Like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except - returns the result set as a stream. Unlike - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there is no - limit on the size of the returned result set. However, no - individual row in the result set can exceed 100 MiB, and no - column value can exceed 10 MiB. - - Returns: - Callable[[~.ExecuteSqlRequest], - ~.PartialResultSet]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'execute_streaming_sql' not in self._stubs: - self._stubs['execute_streaming_sql'] = self.grpc_channel.unary_stream( - '/google.spanner.v1.Spanner/ExecuteStreamingSql', - request_serializer=spanner.ExecuteSqlRequest.serialize, - response_deserializer=result_set.PartialResultSet.deserialize, - ) - return self._stubs['execute_streaming_sql'] - - @property - def execute_batch_dml(self) -> Callable[ - [spanner.ExecuteBatchDmlRequest], - spanner.ExecuteBatchDmlResponse]: - r"""Return a callable for the execute batch dml method over gRPC. - - Executes a batch of SQL DML statements. This method allows many - statements to be run with lower latency than submitting them - sequentially with - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. - - Statements are executed in sequential order. A request can - succeed even if a statement fails. The - [ExecuteBatchDmlResponse.status][google.spanner.v1.ExecuteBatchDmlResponse.status] - field in the response provides information about the statement - that failed. Clients must inspect this field to determine - whether an error occurred. - - Execution stops after the first failed statement; the remaining - statements are not executed. - - Returns: - Callable[[~.ExecuteBatchDmlRequest], - ~.ExecuteBatchDmlResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'execute_batch_dml' not in self._stubs: - self._stubs['execute_batch_dml'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/ExecuteBatchDml', - request_serializer=spanner.ExecuteBatchDmlRequest.serialize, - response_deserializer=spanner.ExecuteBatchDmlResponse.deserialize, - ) - return self._stubs['execute_batch_dml'] - - @property - def read(self) -> Callable[ - [spanner.ReadRequest], - result_set.ResultSet]: - r"""Return a callable for the read method over gRPC. - - Reads rows from the database using key lookups and scans, as a - simple key/value style alternative to - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method - cannot be used to return a result set larger than 10 MiB; if the - read matches more data than that, the read fails with a - ``FAILED_PRECONDITION`` error. - - Reads inside read-write transactions might return ``ABORTED``. - If this occurs, the application should restart the transaction - from the beginning. See - [Transaction][google.spanner.v1.Transaction] for more details. - - Larger result sets can be yielded in streaming fashion by - calling [StreamingRead][google.spanner.v1.Spanner.StreamingRead] - instead. - - Returns: - Callable[[~.ReadRequest], - ~.ResultSet]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'read' not in self._stubs: - self._stubs['read'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/Read', - request_serializer=spanner.ReadRequest.serialize, - response_deserializer=result_set.ResultSet.deserialize, - ) - return self._stubs['read'] - - @property - def streaming_read(self) -> Callable[ - [spanner.ReadRequest], - result_set.PartialResultSet]: - r"""Return a callable for the streaming read method over gRPC. - - Like [Read][google.spanner.v1.Spanner.Read], except returns the - result set as a stream. Unlike - [Read][google.spanner.v1.Spanner.Read], there is no limit on the - size of the returned result set. However, no individual row in - the result set can exceed 100 MiB, and no column value can - exceed 10 MiB. - - Returns: - Callable[[~.ReadRequest], - ~.PartialResultSet]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'streaming_read' not in self._stubs: - self._stubs['streaming_read'] = self.grpc_channel.unary_stream( - '/google.spanner.v1.Spanner/StreamingRead', - request_serializer=spanner.ReadRequest.serialize, - response_deserializer=result_set.PartialResultSet.deserialize, - ) - return self._stubs['streaming_read'] - - @property - def begin_transaction(self) -> Callable[ - [spanner.BeginTransactionRequest], - transaction.Transaction]: - r"""Return a callable for the begin transaction method over gRPC. - - Begins a new transaction. This step can often be skipped: - [Read][google.spanner.v1.Spanner.Read], - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and - [Commit][google.spanner.v1.Spanner.Commit] can begin a new - transaction as a side-effect. - - Returns: - Callable[[~.BeginTransactionRequest], - ~.Transaction]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'begin_transaction' not in self._stubs: - self._stubs['begin_transaction'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/BeginTransaction', - request_serializer=spanner.BeginTransactionRequest.serialize, - response_deserializer=transaction.Transaction.deserialize, - ) - return self._stubs['begin_transaction'] - - @property - def commit(self) -> Callable[ - [spanner.CommitRequest], - commit_response.CommitResponse]: - r"""Return a callable for the commit method over gRPC. - - Commits a transaction. The request includes the mutations to be - applied to rows in the database. - - ``Commit`` might return an ``ABORTED`` error. This can occur at - any time; commonly, the cause is conflicts with concurrent - transactions. However, it can also happen for a variety of other - reasons. If ``Commit`` returns ``ABORTED``, the caller should - re-attempt the transaction from the beginning, re-using the same - session. - - On very rare occasions, ``Commit`` might return ``UNKNOWN``. - This can happen, for example, if the client job experiences a 1+ - hour networking failure. At that point, Cloud Spanner has lost - track of the transaction outcome and we recommend that you - perform another read from the database to see the state of - things as they are now. - - Returns: - Callable[[~.CommitRequest], - ~.CommitResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'commit' not in self._stubs: - self._stubs['commit'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/Commit', - request_serializer=spanner.CommitRequest.serialize, - response_deserializer=commit_response.CommitResponse.deserialize, - ) - return self._stubs['commit'] - - @property - def rollback(self) -> Callable[ - [spanner.RollbackRequest], - empty_pb2.Empty]: - r"""Return a callable for the rollback method over gRPC. - - Rolls back a transaction, releasing any locks it holds. It is a - good idea to call this for any transaction that includes one or - more [Read][google.spanner.v1.Spanner.Read] or - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and - ultimately decides not to commit. - - ``Rollback`` returns ``OK`` if it successfully aborts the - transaction, the transaction was already aborted, or the - transaction is not found. ``Rollback`` never returns - ``ABORTED``. - - Returns: - Callable[[~.RollbackRequest], - ~.Empty]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'rollback' not in self._stubs: - self._stubs['rollback'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/Rollback', - request_serializer=spanner.RollbackRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['rollback'] - - @property - def partition_query(self) -> Callable[ - [spanner.PartitionQueryRequest], - spanner.PartitionResponse]: - r"""Return a callable for the partition query method over gRPC. - - Creates a set of partition tokens that can be used to execute a - query operation in parallel. Each of the returned partition - tokens can be used by - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] - to specify a subset of the query result to read. The same - session and read-only transaction must be used by the - PartitionQueryRequest used to create the partition tokens and - the ExecuteSqlRequests that use the partition tokens. - - Partition tokens become invalid when the session used to create - them is deleted, is idle for too long, begins a new transaction, - or becomes too old. When any of these happen, it is not possible - to resume the query, and the whole operation must be restarted - from the beginning. - - Returns: - Callable[[~.PartitionQueryRequest], - ~.PartitionResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'partition_query' not in self._stubs: - self._stubs['partition_query'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/PartitionQuery', - request_serializer=spanner.PartitionQueryRequest.serialize, - response_deserializer=spanner.PartitionResponse.deserialize, - ) - return self._stubs['partition_query'] - - @property - def partition_read(self) -> Callable[ - [spanner.PartitionReadRequest], - spanner.PartitionResponse]: - r"""Return a callable for the partition read method over gRPC. - - Creates a set of partition tokens that can be used to execute a - read operation in parallel. Each of the returned partition - tokens can be used by - [StreamingRead][google.spanner.v1.Spanner.StreamingRead] to - specify a subset of the read result to read. The same session - and read-only transaction must be used by the - PartitionReadRequest used to create the partition tokens and the - ReadRequests that use the partition tokens. There are no - ordering guarantees on rows returned among the returned - partition tokens, or even within each individual StreamingRead - call issued with a partition_token. - - Partition tokens become invalid when the session used to create - them is deleted, is idle for too long, begins a new transaction, - or becomes too old. When any of these happen, it is not possible - to resume the read, and the whole operation must be restarted - from the beginning. - - Returns: - Callable[[~.PartitionReadRequest], - ~.PartitionResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'partition_read' not in self._stubs: - self._stubs['partition_read'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/PartitionRead', - request_serializer=spanner.PartitionReadRequest.serialize, - response_deserializer=spanner.PartitionResponse.deserialize, - ) - return self._stubs['partition_read'] - - def close(self): - self.grpc_channel.close() - - @property - def kind(self) -> str: - return "grpc" - - -__all__ = ( - 'SpannerGrpcTransport', -) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py deleted file mode 100644 index 1c749a4772..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py +++ /dev/null @@ -1,765 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers_async -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore - -import grpc # type: ignore -from grpc.experimental import aio # type: ignore - -from google.cloud.spanner_v1.types import commit_response -from google.cloud.spanner_v1.types import result_set -from google.cloud.spanner_v1.types import spanner -from google.cloud.spanner_v1.types import transaction -from google.protobuf import empty_pb2 # type: ignore -from .base import SpannerTransport, DEFAULT_CLIENT_INFO -from .grpc import SpannerGrpcTransport - - -class SpannerGrpcAsyncIOTransport(SpannerTransport): - """gRPC AsyncIO backend transport for Spanner. - - Cloud Spanner API - The Cloud Spanner API can be used to manage sessions and execute - transactions on data stored in Cloud Spanner databases. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - - _grpc_channel: aio.Channel - _stubs: Dict[str, Callable] = {} - - @classmethod - def create_channel(cls, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> aio.Channel: - """Create and return a gRPC AsyncIO channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - aio.Channel: A gRPC AsyncIO channel object. - """ - - return grpc_helpers_async.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - def __init__(self, *, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: Optional[aio.Channel] = None, - api_mtls_endpoint: Optional[str] = None, - client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, - client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if ``channel`` is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - channel (Optional[aio.Channel]): A ``Channel`` instance through - which to make calls. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or application default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if ``channel`` is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if channel: - # Ignore credentials if a channel was passed. - credentials = False - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience, - ) - - if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( - self._host, - # use the credentials which are saved - credentials=self._credentials, - # Set ``credentials_file`` to ``None`` here as - # the credentials that we saved earlier should be used. - credentials_file=None, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Wrap messages. This must be done after self._grpc_channel exists - self._prep_wrapped_messages(client_info) - - @property - def grpc_channel(self) -> aio.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. - """ - # Return the channel from cache. - return self._grpc_channel - - @property - def create_session(self) -> Callable[ - [spanner.CreateSessionRequest], - Awaitable[spanner.Session]]: - r"""Return a callable for the create session method over gRPC. - - Creates a new session. A session can be used to perform - transactions that read and/or modify data in a Cloud Spanner - database. Sessions are meant to be reused for many consecutive - transactions. - - Sessions can only execute one transaction at a time. To execute - multiple concurrent read-write/write-only transactions, create - multiple sessions. Note that standalone reads and queries use a - transaction internally, and count toward the one transaction - limit. - - Active sessions use additional server resources, so it is a good - idea to delete idle and unneeded sessions. Aside from explicit - deletes, Cloud Spanner may delete sessions for which no - operations are sent for more than an hour. If a session is - deleted, requests to it return ``NOT_FOUND``. - - Idle sessions can be kept alive by sending a trivial SQL query - periodically, e.g., ``"SELECT 1"``. - - Returns: - Callable[[~.CreateSessionRequest], - Awaitable[~.Session]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'create_session' not in self._stubs: - self._stubs['create_session'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/CreateSession', - request_serializer=spanner.CreateSessionRequest.serialize, - response_deserializer=spanner.Session.deserialize, - ) - return self._stubs['create_session'] - - @property - def batch_create_sessions(self) -> Callable[ - [spanner.BatchCreateSessionsRequest], - Awaitable[spanner.BatchCreateSessionsResponse]]: - r"""Return a callable for the batch create sessions method over gRPC. - - Creates multiple new sessions. - This API can be used to initialize a session cache on - the clients. See https://goo.gl/TgSFN2 for best - practices on session cache management. - - Returns: - Callable[[~.BatchCreateSessionsRequest], - Awaitable[~.BatchCreateSessionsResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'batch_create_sessions' not in self._stubs: - self._stubs['batch_create_sessions'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/BatchCreateSessions', - request_serializer=spanner.BatchCreateSessionsRequest.serialize, - response_deserializer=spanner.BatchCreateSessionsResponse.deserialize, - ) - return self._stubs['batch_create_sessions'] - - @property - def get_session(self) -> Callable[ - [spanner.GetSessionRequest], - Awaitable[spanner.Session]]: - r"""Return a callable for the get session method over gRPC. - - Gets a session. Returns ``NOT_FOUND`` if the session does not - exist. This is mainly useful for determining whether a session - is still alive. - - Returns: - Callable[[~.GetSessionRequest], - Awaitable[~.Session]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_session' not in self._stubs: - self._stubs['get_session'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/GetSession', - request_serializer=spanner.GetSessionRequest.serialize, - response_deserializer=spanner.Session.deserialize, - ) - return self._stubs['get_session'] - - @property - def list_sessions(self) -> Callable[ - [spanner.ListSessionsRequest], - Awaitable[spanner.ListSessionsResponse]]: - r"""Return a callable for the list sessions method over gRPC. - - Lists all sessions in a given database. - - Returns: - Callable[[~.ListSessionsRequest], - Awaitable[~.ListSessionsResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_sessions' not in self._stubs: - self._stubs['list_sessions'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/ListSessions', - request_serializer=spanner.ListSessionsRequest.serialize, - response_deserializer=spanner.ListSessionsResponse.deserialize, - ) - return self._stubs['list_sessions'] - - @property - def delete_session(self) -> Callable[ - [spanner.DeleteSessionRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the delete session method over gRPC. - - Ends a session, releasing server resources associated - with it. This will asynchronously trigger cancellation - of any operations that are running with this session. - - Returns: - Callable[[~.DeleteSessionRequest], - Awaitable[~.Empty]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'delete_session' not in self._stubs: - self._stubs['delete_session'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/DeleteSession', - request_serializer=spanner.DeleteSessionRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_session'] - - @property - def execute_sql(self) -> Callable[ - [spanner.ExecuteSqlRequest], - Awaitable[result_set.ResultSet]]: - r"""Return a callable for the execute sql method over gRPC. - - Executes an SQL statement, returning all results in a single - reply. This method cannot be used to return a result set larger - than 10 MiB; if the query yields more data than that, the query - fails with a ``FAILED_PRECONDITION`` error. - - Operations inside read-write transactions might return - ``ABORTED``. If this occurs, the application should restart the - transaction from the beginning. See - [Transaction][google.spanner.v1.Transaction] for more details. - - Larger result sets can be fetched in streaming fashion by - calling - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] - instead. - - Returns: - Callable[[~.ExecuteSqlRequest], - Awaitable[~.ResultSet]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'execute_sql' not in self._stubs: - self._stubs['execute_sql'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/ExecuteSql', - request_serializer=spanner.ExecuteSqlRequest.serialize, - response_deserializer=result_set.ResultSet.deserialize, - ) - return self._stubs['execute_sql'] - - @property - def execute_streaming_sql(self) -> Callable[ - [spanner.ExecuteSqlRequest], - Awaitable[result_set.PartialResultSet]]: - r"""Return a callable for the execute streaming sql method over gRPC. - - Like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except - returns the result set as a stream. Unlike - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there is no - limit on the size of the returned result set. However, no - individual row in the result set can exceed 100 MiB, and no - column value can exceed 10 MiB. - - Returns: - Callable[[~.ExecuteSqlRequest], - Awaitable[~.PartialResultSet]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'execute_streaming_sql' not in self._stubs: - self._stubs['execute_streaming_sql'] = self.grpc_channel.unary_stream( - '/google.spanner.v1.Spanner/ExecuteStreamingSql', - request_serializer=spanner.ExecuteSqlRequest.serialize, - response_deserializer=result_set.PartialResultSet.deserialize, - ) - return self._stubs['execute_streaming_sql'] - - @property - def execute_batch_dml(self) -> Callable[ - [spanner.ExecuteBatchDmlRequest], - Awaitable[spanner.ExecuteBatchDmlResponse]]: - r"""Return a callable for the execute batch dml method over gRPC. - - Executes a batch of SQL DML statements. This method allows many - statements to be run with lower latency than submitting them - sequentially with - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. - - Statements are executed in sequential order. A request can - succeed even if a statement fails. The - [ExecuteBatchDmlResponse.status][google.spanner.v1.ExecuteBatchDmlResponse.status] - field in the response provides information about the statement - that failed. Clients must inspect this field to determine - whether an error occurred. - - Execution stops after the first failed statement; the remaining - statements are not executed. - - Returns: - Callable[[~.ExecuteBatchDmlRequest], - Awaitable[~.ExecuteBatchDmlResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'execute_batch_dml' not in self._stubs: - self._stubs['execute_batch_dml'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/ExecuteBatchDml', - request_serializer=spanner.ExecuteBatchDmlRequest.serialize, - response_deserializer=spanner.ExecuteBatchDmlResponse.deserialize, - ) - return self._stubs['execute_batch_dml'] - - @property - def read(self) -> Callable[ - [spanner.ReadRequest], - Awaitable[result_set.ResultSet]]: - r"""Return a callable for the read method over gRPC. - - Reads rows from the database using key lookups and scans, as a - simple key/value style alternative to - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method - cannot be used to return a result set larger than 10 MiB; if the - read matches more data than that, the read fails with a - ``FAILED_PRECONDITION`` error. - - Reads inside read-write transactions might return ``ABORTED``. - If this occurs, the application should restart the transaction - from the beginning. See - [Transaction][google.spanner.v1.Transaction] for more details. - - Larger result sets can be yielded in streaming fashion by - calling [StreamingRead][google.spanner.v1.Spanner.StreamingRead] - instead. - - Returns: - Callable[[~.ReadRequest], - Awaitable[~.ResultSet]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'read' not in self._stubs: - self._stubs['read'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/Read', - request_serializer=spanner.ReadRequest.serialize, - response_deserializer=result_set.ResultSet.deserialize, - ) - return self._stubs['read'] - - @property - def streaming_read(self) -> Callable[ - [spanner.ReadRequest], - Awaitable[result_set.PartialResultSet]]: - r"""Return a callable for the streaming read method over gRPC. - - Like [Read][google.spanner.v1.Spanner.Read], except returns the - result set as a stream. Unlike - [Read][google.spanner.v1.Spanner.Read], there is no limit on the - size of the returned result set. However, no individual row in - the result set can exceed 100 MiB, and no column value can - exceed 10 MiB. - - Returns: - Callable[[~.ReadRequest], - Awaitable[~.PartialResultSet]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'streaming_read' not in self._stubs: - self._stubs['streaming_read'] = self.grpc_channel.unary_stream( - '/google.spanner.v1.Spanner/StreamingRead', - request_serializer=spanner.ReadRequest.serialize, - response_deserializer=result_set.PartialResultSet.deserialize, - ) - return self._stubs['streaming_read'] - - @property - def begin_transaction(self) -> Callable[ - [spanner.BeginTransactionRequest], - Awaitable[transaction.Transaction]]: - r"""Return a callable for the begin transaction method over gRPC. - - Begins a new transaction. This step can often be skipped: - [Read][google.spanner.v1.Spanner.Read], - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and - [Commit][google.spanner.v1.Spanner.Commit] can begin a new - transaction as a side-effect. - - Returns: - Callable[[~.BeginTransactionRequest], - Awaitable[~.Transaction]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'begin_transaction' not in self._stubs: - self._stubs['begin_transaction'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/BeginTransaction', - request_serializer=spanner.BeginTransactionRequest.serialize, - response_deserializer=transaction.Transaction.deserialize, - ) - return self._stubs['begin_transaction'] - - @property - def commit(self) -> Callable[ - [spanner.CommitRequest], - Awaitable[commit_response.CommitResponse]]: - r"""Return a callable for the commit method over gRPC. - - Commits a transaction. The request includes the mutations to be - applied to rows in the database. - - ``Commit`` might return an ``ABORTED`` error. This can occur at - any time; commonly, the cause is conflicts with concurrent - transactions. However, it can also happen for a variety of other - reasons. If ``Commit`` returns ``ABORTED``, the caller should - re-attempt the transaction from the beginning, re-using the same - session. - - On very rare occasions, ``Commit`` might return ``UNKNOWN``. - This can happen, for example, if the client job experiences a 1+ - hour networking failure. At that point, Cloud Spanner has lost - track of the transaction outcome and we recommend that you - perform another read from the database to see the state of - things as they are now. - - Returns: - Callable[[~.CommitRequest], - Awaitable[~.CommitResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'commit' not in self._stubs: - self._stubs['commit'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/Commit', - request_serializer=spanner.CommitRequest.serialize, - response_deserializer=commit_response.CommitResponse.deserialize, - ) - return self._stubs['commit'] - - @property - def rollback(self) -> Callable[ - [spanner.RollbackRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the rollback method over gRPC. - - Rolls back a transaction, releasing any locks it holds. It is a - good idea to call this for any transaction that includes one or - more [Read][google.spanner.v1.Spanner.Read] or - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and - ultimately decides not to commit. - - ``Rollback`` returns ``OK`` if it successfully aborts the - transaction, the transaction was already aborted, or the - transaction is not found. ``Rollback`` never returns - ``ABORTED``. - - Returns: - Callable[[~.RollbackRequest], - Awaitable[~.Empty]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'rollback' not in self._stubs: - self._stubs['rollback'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/Rollback', - request_serializer=spanner.RollbackRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['rollback'] - - @property - def partition_query(self) -> Callable[ - [spanner.PartitionQueryRequest], - Awaitable[spanner.PartitionResponse]]: - r"""Return a callable for the partition query method over gRPC. - - Creates a set of partition tokens that can be used to execute a - query operation in parallel. Each of the returned partition - tokens can be used by - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] - to specify a subset of the query result to read. The same - session and read-only transaction must be used by the - PartitionQueryRequest used to create the partition tokens and - the ExecuteSqlRequests that use the partition tokens. - - Partition tokens become invalid when the session used to create - them is deleted, is idle for too long, begins a new transaction, - or becomes too old. When any of these happen, it is not possible - to resume the query, and the whole operation must be restarted - from the beginning. - - Returns: - Callable[[~.PartitionQueryRequest], - Awaitable[~.PartitionResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'partition_query' not in self._stubs: - self._stubs['partition_query'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/PartitionQuery', - request_serializer=spanner.PartitionQueryRequest.serialize, - response_deserializer=spanner.PartitionResponse.deserialize, - ) - return self._stubs['partition_query'] - - @property - def partition_read(self) -> Callable[ - [spanner.PartitionReadRequest], - Awaitable[spanner.PartitionResponse]]: - r"""Return a callable for the partition read method over gRPC. - - Creates a set of partition tokens that can be used to execute a - read operation in parallel. Each of the returned partition - tokens can be used by - [StreamingRead][google.spanner.v1.Spanner.StreamingRead] to - specify a subset of the read result to read. The same session - and read-only transaction must be used by the - PartitionReadRequest used to create the partition tokens and the - ReadRequests that use the partition tokens. There are no - ordering guarantees on rows returned among the returned - partition tokens, or even within each individual StreamingRead - call issued with a partition_token. - - Partition tokens become invalid when the session used to create - them is deleted, is idle for too long, begins a new transaction, - or becomes too old. When any of these happen, it is not possible - to resume the read, and the whole operation must be restarted - from the beginning. - - Returns: - Callable[[~.PartitionReadRequest], - Awaitable[~.PartitionResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'partition_read' not in self._stubs: - self._stubs['partition_read'] = self.grpc_channel.unary_unary( - '/google.spanner.v1.Spanner/PartitionRead', - request_serializer=spanner.PartitionReadRequest.serialize, - response_deserializer=spanner.PartitionResponse.deserialize, - ) - return self._stubs['partition_read'] - - def close(self): - return self.grpc_channel.close() - - -__all__ = ( - 'SpannerGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/rest.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/rest.py deleted file mode 100644 index d7bff17364..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/services/spanner/transports/rest.py +++ /dev/null @@ -1,1973 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from google.auth.transport.requests import AuthorizedSession # type: ignore -import json # type: ignore -import grpc # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.api_core import exceptions as core_exceptions -from google.api_core import retry as retries -from google.api_core import rest_helpers -from google.api_core import rest_streaming -from google.api_core import path_template -from google.api_core import gapic_v1 - -from google.protobuf import json_format -from requests import __version__ as requests_version -import dataclasses -import re -from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union -import warnings - -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object] # type: ignore - - -from google.cloud.spanner_v1.types import commit_response -from google.cloud.spanner_v1.types import result_set -from google.cloud.spanner_v1.types import spanner -from google.cloud.spanner_v1.types import transaction -from google.protobuf import empty_pb2 # type: ignore - -from .base import SpannerTransport, DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO - - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, - grpc_version=None, - rest_version=requests_version, -) - - -class SpannerRestInterceptor: - """Interceptor for Spanner. - - Interceptors are used to manipulate requests, request metadata, and responses - in arbitrary ways. - Example use cases include: - * Logging - * Verifying requests according to service or custom semantics - * Stripping extraneous information from responses - - These use cases and more can be enabled by injecting an - instance of a custom subclass when constructing the SpannerRestTransport. - - .. code-block:: python - class MyCustomSpannerInterceptor(SpannerRestInterceptor): - def pre_batch_create_sessions(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_batch_create_sessions(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_begin_transaction(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_begin_transaction(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_commit(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_commit(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_create_session(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_create_session(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_delete_session(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def pre_execute_batch_dml(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_execute_batch_dml(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_execute_sql(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_execute_sql(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_execute_streaming_sql(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_execute_streaming_sql(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_get_session(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_get_session(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_list_sessions(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_list_sessions(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_partition_query(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_partition_query(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_partition_read(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_partition_read(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_read(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_read(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_rollback(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def pre_streaming_read(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_streaming_read(self, response): - logging.log(f"Received response: {response}") - return response - - transport = SpannerRestTransport(interceptor=MyCustomSpannerInterceptor()) - client = SpannerClient(transport=transport) - - - """ - def pre_batch_create_sessions(self, request: spanner.BatchCreateSessionsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.BatchCreateSessionsRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for batch_create_sessions - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def post_batch_create_sessions(self, response: spanner.BatchCreateSessionsResponse) -> spanner.BatchCreateSessionsResponse: - """Post-rpc interceptor for batch_create_sessions - - Override in a subclass to manipulate the response - after it is returned by the Spanner server but before - it is returned to user code. - """ - return response - def pre_begin_transaction(self, request: spanner.BeginTransactionRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.BeginTransactionRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for begin_transaction - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def post_begin_transaction(self, response: transaction.Transaction) -> transaction.Transaction: - """Post-rpc interceptor for begin_transaction - - Override in a subclass to manipulate the response - after it is returned by the Spanner server but before - it is returned to user code. - """ - return response - def pre_commit(self, request: spanner.CommitRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.CommitRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for commit - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def post_commit(self, response: commit_response.CommitResponse) -> commit_response.CommitResponse: - """Post-rpc interceptor for commit - - Override in a subclass to manipulate the response - after it is returned by the Spanner server but before - it is returned to user code. - """ - return response - def pre_create_session(self, request: spanner.CreateSessionRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.CreateSessionRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for create_session - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def post_create_session(self, response: spanner.Session) -> spanner.Session: - """Post-rpc interceptor for create_session - - Override in a subclass to manipulate the response - after it is returned by the Spanner server but before - it is returned to user code. - """ - return response - def pre_delete_session(self, request: spanner.DeleteSessionRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.DeleteSessionRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for delete_session - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def pre_execute_batch_dml(self, request: spanner.ExecuteBatchDmlRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.ExecuteBatchDmlRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for execute_batch_dml - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def post_execute_batch_dml(self, response: spanner.ExecuteBatchDmlResponse) -> spanner.ExecuteBatchDmlResponse: - """Post-rpc interceptor for execute_batch_dml - - Override in a subclass to manipulate the response - after it is returned by the Spanner server but before - it is returned to user code. - """ - return response - def pre_execute_sql(self, request: spanner.ExecuteSqlRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.ExecuteSqlRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for execute_sql - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def post_execute_sql(self, response: result_set.ResultSet) -> result_set.ResultSet: - """Post-rpc interceptor for execute_sql - - Override in a subclass to manipulate the response - after it is returned by the Spanner server but before - it is returned to user code. - """ - return response - def pre_execute_streaming_sql(self, request: spanner.ExecuteSqlRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.ExecuteSqlRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for execute_streaming_sql - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def post_execute_streaming_sql(self, response: rest_streaming.ResponseIterator) -> rest_streaming.ResponseIterator: - """Post-rpc interceptor for execute_streaming_sql - - Override in a subclass to manipulate the response - after it is returned by the Spanner server but before - it is returned to user code. - """ - return response - def pre_get_session(self, request: spanner.GetSessionRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.GetSessionRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for get_session - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def post_get_session(self, response: spanner.Session) -> spanner.Session: - """Post-rpc interceptor for get_session - - Override in a subclass to manipulate the response - after it is returned by the Spanner server but before - it is returned to user code. - """ - return response - def pre_list_sessions(self, request: spanner.ListSessionsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.ListSessionsRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for list_sessions - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def post_list_sessions(self, response: spanner.ListSessionsResponse) -> spanner.ListSessionsResponse: - """Post-rpc interceptor for list_sessions - - Override in a subclass to manipulate the response - after it is returned by the Spanner server but before - it is returned to user code. - """ - return response - def pre_partition_query(self, request: spanner.PartitionQueryRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.PartitionQueryRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for partition_query - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def post_partition_query(self, response: spanner.PartitionResponse) -> spanner.PartitionResponse: - """Post-rpc interceptor for partition_query - - Override in a subclass to manipulate the response - after it is returned by the Spanner server but before - it is returned to user code. - """ - return response - def pre_partition_read(self, request: spanner.PartitionReadRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.PartitionReadRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for partition_read - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def post_partition_read(self, response: spanner.PartitionResponse) -> spanner.PartitionResponse: - """Post-rpc interceptor for partition_read - - Override in a subclass to manipulate the response - after it is returned by the Spanner server but before - it is returned to user code. - """ - return response - def pre_read(self, request: spanner.ReadRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.ReadRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for read - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def post_read(self, response: result_set.ResultSet) -> result_set.ResultSet: - """Post-rpc interceptor for read - - Override in a subclass to manipulate the response - after it is returned by the Spanner server but before - it is returned to user code. - """ - return response - def pre_rollback(self, request: spanner.RollbackRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.RollbackRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for rollback - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def pre_streaming_read(self, request: spanner.ReadRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner.ReadRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for streaming_read - - Override in a subclass to manipulate the request or metadata - before they are sent to the Spanner server. - """ - return request, metadata - - def post_streaming_read(self, response: rest_streaming.ResponseIterator) -> rest_streaming.ResponseIterator: - """Post-rpc interceptor for streaming_read - - Override in a subclass to manipulate the response - after it is returned by the Spanner server but before - it is returned to user code. - """ - return response - - -@dataclasses.dataclass -class SpannerRestStub: - _session: AuthorizedSession - _host: str - _interceptor: SpannerRestInterceptor - - -class SpannerRestTransport(SpannerTransport): - """REST backend transport for Spanner. - - Cloud Spanner API - The Cloud Spanner API can be used to manage sessions and execute - transactions on data stored in Cloud Spanner databases. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends JSON representations of protocol buffers over HTTP/1.1 - - """ - - def __init__(self, *, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - client_cert_source_for_mtls: Optional[Callable[[ - ], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - url_scheme: str = 'https', - interceptor: Optional[SpannerRestInterceptor] = None, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client - certificate to configure mutual TLS HTTP channel. It is ignored - if ``channel`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you are developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - url_scheme: the protocol scheme for the API endpoint. Normally - "https", but for testing or local servers, - "http" can be specified. - """ - # Run the base constructor - # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. - # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the - # credentials object - maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) - if maybe_url_match is None: - raise ValueError(f"Unexpected hostname structure: {host}") # pragma: NO COVER - - url_match_items = maybe_url_match.groupdict() - - host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host - - super().__init__( - host=host, - credentials=credentials, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience - ) - self._session = AuthorizedSession( - self._credentials, default_host=self.DEFAULT_HOST) - if client_cert_source_for_mtls: - self._session.configure_mtls_channel(client_cert_source_for_mtls) - self._interceptor = interceptor or SpannerRestInterceptor() - self._prep_wrapped_messages(client_info) - - class _BatchCreateSessions(SpannerRestStub): - def __hash__(self): - return hash("BatchCreateSessions") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.BatchCreateSessionsRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner.BatchCreateSessionsResponse: - r"""Call the batch create sessions method over HTTP. - - Args: - request (~.spanner.BatchCreateSessionsRequest): - The request object. The request for - [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner.BatchCreateSessionsResponse: - The response for - [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{database=projects/*/instances/*/databases/*}/sessions:batchCreate', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_batch_create_sessions(request, metadata) - pb_request = spanner.BatchCreateSessionsRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner.BatchCreateSessionsResponse() - pb_resp = spanner.BatchCreateSessionsResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_batch_create_sessions(resp) - return resp - - class _BeginTransaction(SpannerRestStub): - def __hash__(self): - return hash("BeginTransaction") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.BeginTransactionRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> transaction.Transaction: - r"""Call the begin transaction method over HTTP. - - Args: - request (~.spanner.BeginTransactionRequest): - The request object. The request for - [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.transaction.Transaction: - A transaction. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:beginTransaction', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_begin_transaction(request, metadata) - pb_request = spanner.BeginTransactionRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = transaction.Transaction() - pb_resp = transaction.Transaction.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_begin_transaction(resp) - return resp - - class _Commit(SpannerRestStub): - def __hash__(self): - return hash("Commit") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.CommitRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> commit_response.CommitResponse: - r"""Call the commit method over HTTP. - - Args: - request (~.spanner.CommitRequest): - The request object. The request for - [Commit][google.spanner.v1.Spanner.Commit]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.commit_response.CommitResponse: - The response for - [Commit][google.spanner.v1.Spanner.Commit]. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:commit', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_commit(request, metadata) - pb_request = spanner.CommitRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = commit_response.CommitResponse() - pb_resp = commit_response.CommitResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_commit(resp) - return resp - - class _CreateSession(SpannerRestStub): - def __hash__(self): - return hash("CreateSession") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.CreateSessionRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner.Session: - r"""Call the create session method over HTTP. - - Args: - request (~.spanner.CreateSessionRequest): - The request object. The request for - [CreateSession][google.spanner.v1.Spanner.CreateSession]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner.Session: - A session in the Cloud Spanner API. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{database=projects/*/instances/*/databases/*}/sessions', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_create_session(request, metadata) - pb_request = spanner.CreateSessionRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner.Session() - pb_resp = spanner.Session.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_create_session(resp) - return resp - - class _DeleteSession(SpannerRestStub): - def __hash__(self): - return hash("DeleteSession") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.DeleteSessionRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ): - r"""Call the delete session method over HTTP. - - Args: - request (~.spanner.DeleteSessionRequest): - The request object. The request for - [DeleteSession][google.spanner.v1.Spanner.DeleteSession]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'delete', - 'uri': '/v1/{name=projects/*/instances/*/databases/*/sessions/*}', - }, - ] - request, metadata = self._interceptor.pre_delete_session(request, metadata) - pb_request = spanner.DeleteSessionRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - class _ExecuteBatchDml(SpannerRestStub): - def __hash__(self): - return hash("ExecuteBatchDml") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.ExecuteBatchDmlRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner.ExecuteBatchDmlResponse: - r"""Call the execute batch dml method over HTTP. - - Args: - request (~.spanner.ExecuteBatchDmlRequest): - The request object. The request for - [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner.ExecuteBatchDmlResponse: - The response for - [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. - Contains a list of - [ResultSet][google.spanner.v1.ResultSet] messages, one - for each DML statement that has successfully executed, - in the same order as the statements in the request. If a - statement fails, the status in the response body - identifies the cause of the failure. - - To check for DML statements that failed, use the - following approach: - - 1. Check the status in the response message. The - [google.rpc.Code][google.rpc.Code] enum value ``OK`` - indicates that all statements were executed - successfully. - 2. If the status was not ``OK``, check the number of - result sets in the response. If the response contains - ``N`` [ResultSet][google.spanner.v1.ResultSet] - messages, then statement ``N+1`` in the request - failed. - - Example 1: - - - Request: 5 DML statements, all executed successfully. - - Response: 5 [ResultSet][google.spanner.v1.ResultSet] - messages, with the status ``OK``. - - Example 2: - - - Request: 5 DML statements. The third statement has a - syntax error. - - Response: 2 [ResultSet][google.spanner.v1.ResultSet] - messages, and a syntax error (``INVALID_ARGUMENT``) - status. The number of - [ResultSet][google.spanner.v1.ResultSet] messages - indicates that the third statement failed, and the - fourth and fifth statements were not executed. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeBatchDml', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_execute_batch_dml(request, metadata) - pb_request = spanner.ExecuteBatchDmlRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner.ExecuteBatchDmlResponse() - pb_resp = spanner.ExecuteBatchDmlResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_execute_batch_dml(resp) - return resp - - class _ExecuteSql(SpannerRestStub): - def __hash__(self): - return hash("ExecuteSql") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.ExecuteSqlRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> result_set.ResultSet: - r"""Call the execute sql method over HTTP. - - Args: - request (~.spanner.ExecuteSqlRequest): - The request object. The request for - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.result_set.ResultSet: - Results from [Read][google.spanner.v1.Spanner.Read] or - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeSql', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_execute_sql(request, metadata) - pb_request = spanner.ExecuteSqlRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = result_set.ResultSet() - pb_resp = result_set.ResultSet.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_execute_sql(resp) - return resp - - class _ExecuteStreamingSql(SpannerRestStub): - def __hash__(self): - return hash("ExecuteStreamingSql") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.ExecuteSqlRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> rest_streaming.ResponseIterator: - r"""Call the execute streaming sql method over HTTP. - - Args: - request (~.spanner.ExecuteSqlRequest): - The request object. The request for - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.result_set.PartialResultSet: - Partial results from a streaming read - or SQL query. Streaming reads and SQL - queries better tolerate large result - sets, large rows, and large values, but - are a little trickier to consume. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeStreamingSql', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_execute_streaming_sql(request, metadata) - pb_request = spanner.ExecuteSqlRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = rest_streaming.ResponseIterator(response, result_set.PartialResultSet) - resp = self._interceptor.post_execute_streaming_sql(resp) - return resp - - class _GetSession(SpannerRestStub): - def __hash__(self): - return hash("GetSession") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.GetSessionRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner.Session: - r"""Call the get session method over HTTP. - - Args: - request (~.spanner.GetSessionRequest): - The request object. The request for - [GetSession][google.spanner.v1.Spanner.GetSession]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner.Session: - A session in the Cloud Spanner API. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/databases/*/sessions/*}', - }, - ] - request, metadata = self._interceptor.pre_get_session(request, metadata) - pb_request = spanner.GetSessionRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner.Session() - pb_resp = spanner.Session.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_session(resp) - return resp - - class _ListSessions(SpannerRestStub): - def __hash__(self): - return hash("ListSessions") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.ListSessionsRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner.ListSessionsResponse: - r"""Call the list sessions method over HTTP. - - Args: - request (~.spanner.ListSessionsRequest): - The request object. The request for - [ListSessions][google.spanner.v1.Spanner.ListSessions]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner.ListSessionsResponse: - The response for - [ListSessions][google.spanner.v1.Spanner.ListSessions]. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{database=projects/*/instances/*/databases/*}/sessions', - }, - ] - request, metadata = self._interceptor.pre_list_sessions(request, metadata) - pb_request = spanner.ListSessionsRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner.ListSessionsResponse() - pb_resp = spanner.ListSessionsResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_sessions(resp) - return resp - - class _PartitionQuery(SpannerRestStub): - def __hash__(self): - return hash("PartitionQuery") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.PartitionQueryRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner.PartitionResponse: - r"""Call the partition query method over HTTP. - - Args: - request (~.spanner.PartitionQueryRequest): - The request object. The request for - [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner.PartitionResponse: - The response for - [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] - or - [PartitionRead][google.spanner.v1.Spanner.PartitionRead] - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:partitionQuery', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_partition_query(request, metadata) - pb_request = spanner.PartitionQueryRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner.PartitionResponse() - pb_resp = spanner.PartitionResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_partition_query(resp) - return resp - - class _PartitionRead(SpannerRestStub): - def __hash__(self): - return hash("PartitionRead") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.PartitionReadRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner.PartitionResponse: - r"""Call the partition read method over HTTP. - - Args: - request (~.spanner.PartitionReadRequest): - The request object. The request for - [PartitionRead][google.spanner.v1.Spanner.PartitionRead] - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner.PartitionResponse: - The response for - [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] - or - [PartitionRead][google.spanner.v1.Spanner.PartitionRead] - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:partitionRead', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_partition_read(request, metadata) - pb_request = spanner.PartitionReadRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner.PartitionResponse() - pb_resp = spanner.PartitionResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_partition_read(resp) - return resp - - class _Read(SpannerRestStub): - def __hash__(self): - return hash("Read") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.ReadRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> result_set.ResultSet: - r"""Call the read method over HTTP. - - Args: - request (~.spanner.ReadRequest): - The request object. The request for [Read][google.spanner.v1.Spanner.Read] - and - [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.result_set.ResultSet: - Results from [Read][google.spanner.v1.Spanner.Read] or - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:read', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_read(request, metadata) - pb_request = spanner.ReadRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = result_set.ResultSet() - pb_resp = result_set.ResultSet.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_read(resp) - return resp - - class _Rollback(SpannerRestStub): - def __hash__(self): - return hash("Rollback") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.RollbackRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ): - r"""Call the rollback method over HTTP. - - Args: - request (~.spanner.RollbackRequest): - The request object. The request for - [Rollback][google.spanner.v1.Spanner.Rollback]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:rollback', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_rollback(request, metadata) - pb_request = spanner.RollbackRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - class _StreamingRead(SpannerRestStub): - def __hash__(self): - return hash("StreamingRead") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner.ReadRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> rest_streaming.ResponseIterator: - r"""Call the streaming read method over HTTP. - - Args: - request (~.spanner.ReadRequest): - The request object. The request for [Read][google.spanner.v1.Spanner.Read] - and - [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.result_set.PartialResultSet: - Partial results from a streaming read - or SQL query. Streaming reads and SQL - queries better tolerate large result - sets, large rows, and large values, but - are a little trickier to consume. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{session=projects/*/instances/*/databases/*/sessions/*}:streamingRead', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_streaming_read(request, metadata) - pb_request = spanner.ReadRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = rest_streaming.ResponseIterator(response, result_set.PartialResultSet) - resp = self._interceptor.post_streaming_read(resp) - return resp - - @property - def batch_create_sessions(self) -> Callable[ - [spanner.BatchCreateSessionsRequest], - spanner.BatchCreateSessionsResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._BatchCreateSessions(self._session, self._host, self._interceptor) # type: ignore - - @property - def begin_transaction(self) -> Callable[ - [spanner.BeginTransactionRequest], - transaction.Transaction]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._BeginTransaction(self._session, self._host, self._interceptor) # type: ignore - - @property - def commit(self) -> Callable[ - [spanner.CommitRequest], - commit_response.CommitResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._Commit(self._session, self._host, self._interceptor) # type: ignore - - @property - def create_session(self) -> Callable[ - [spanner.CreateSessionRequest], - spanner.Session]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._CreateSession(self._session, self._host, self._interceptor) # type: ignore - - @property - def delete_session(self) -> Callable[ - [spanner.DeleteSessionRequest], - empty_pb2.Empty]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._DeleteSession(self._session, self._host, self._interceptor) # type: ignore - - @property - def execute_batch_dml(self) -> Callable[ - [spanner.ExecuteBatchDmlRequest], - spanner.ExecuteBatchDmlResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._ExecuteBatchDml(self._session, self._host, self._interceptor) # type: ignore - - @property - def execute_sql(self) -> Callable[ - [spanner.ExecuteSqlRequest], - result_set.ResultSet]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._ExecuteSql(self._session, self._host, self._interceptor) # type: ignore - - @property - def execute_streaming_sql(self) -> Callable[ - [spanner.ExecuteSqlRequest], - result_set.PartialResultSet]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._ExecuteStreamingSql(self._session, self._host, self._interceptor) # type: ignore - - @property - def get_session(self) -> Callable[ - [spanner.GetSessionRequest], - spanner.Session]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._GetSession(self._session, self._host, self._interceptor) # type: ignore - - @property - def list_sessions(self) -> Callable[ - [spanner.ListSessionsRequest], - spanner.ListSessionsResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._ListSessions(self._session, self._host, self._interceptor) # type: ignore - - @property - def partition_query(self) -> Callable[ - [spanner.PartitionQueryRequest], - spanner.PartitionResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._PartitionQuery(self._session, self._host, self._interceptor) # type: ignore - - @property - def partition_read(self) -> Callable[ - [spanner.PartitionReadRequest], - spanner.PartitionResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._PartitionRead(self._session, self._host, self._interceptor) # type: ignore - - @property - def read(self) -> Callable[ - [spanner.ReadRequest], - result_set.ResultSet]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._Read(self._session, self._host, self._interceptor) # type: ignore - - @property - def rollback(self) -> Callable[ - [spanner.RollbackRequest], - empty_pb2.Empty]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._Rollback(self._session, self._host, self._interceptor) # type: ignore - - @property - def streaming_read(self) -> Callable[ - [spanner.ReadRequest], - result_set.PartialResultSet]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._StreamingRead(self._session, self._host, self._interceptor) # type: ignore - - @property - def kind(self) -> str: - return "rest" - - def close(self): - self._session.close() - - -__all__=( - 'SpannerRestTransport', -) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/__init__.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/__init__.py deleted file mode 100644 index b4d0d630da..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/__init__.py +++ /dev/null @@ -1,110 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .commit_response import ( - CommitResponse, -) -from .keys import ( - KeyRange, - KeySet, -) -from .mutation import ( - Mutation, -) -from .query_plan import ( - PlanNode, - QueryPlan, -) -from .result_set import ( - PartialResultSet, - ResultSet, - ResultSetMetadata, - ResultSetStats, -) -from .spanner import ( - BatchCreateSessionsRequest, - BatchCreateSessionsResponse, - BeginTransactionRequest, - CommitRequest, - CreateSessionRequest, - DeleteSessionRequest, - ExecuteBatchDmlRequest, - ExecuteBatchDmlResponse, - ExecuteSqlRequest, - GetSessionRequest, - ListSessionsRequest, - ListSessionsResponse, - Partition, - PartitionOptions, - PartitionQueryRequest, - PartitionReadRequest, - PartitionResponse, - ReadRequest, - RequestOptions, - RollbackRequest, - Session, -) -from .transaction import ( - Transaction, - TransactionOptions, - TransactionSelector, -) -from .type import ( - StructType, - Type, - TypeAnnotationCode, - TypeCode, -) - -__all__ = ( - 'CommitResponse', - 'KeyRange', - 'KeySet', - 'Mutation', - 'PlanNode', - 'QueryPlan', - 'PartialResultSet', - 'ResultSet', - 'ResultSetMetadata', - 'ResultSetStats', - 'BatchCreateSessionsRequest', - 'BatchCreateSessionsResponse', - 'BeginTransactionRequest', - 'CommitRequest', - 'CreateSessionRequest', - 'DeleteSessionRequest', - 'ExecuteBatchDmlRequest', - 'ExecuteBatchDmlResponse', - 'ExecuteSqlRequest', - 'GetSessionRequest', - 'ListSessionsRequest', - 'ListSessionsResponse', - 'Partition', - 'PartitionOptions', - 'PartitionQueryRequest', - 'PartitionReadRequest', - 'PartitionResponse', - 'ReadRequest', - 'RequestOptions', - 'RollbackRequest', - 'Session', - 'Transaction', - 'TransactionOptions', - 'TransactionSelector', - 'StructType', - 'Type', - 'TypeAnnotationCode', - 'TypeCode', -) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/commit_response.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/commit_response.py deleted file mode 100644 index 086a93d37e..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/commit_response.py +++ /dev/null @@ -1,79 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.protobuf import timestamp_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.spanner.v1', - manifest={ - 'CommitResponse', - }, -) - - -class CommitResponse(proto.Message): - r"""The response for [Commit][google.spanner.v1.Spanner.Commit]. - - Attributes: - commit_timestamp (google.protobuf.timestamp_pb2.Timestamp): - The Cloud Spanner timestamp at which the - transaction committed. - commit_stats (google.cloud.spanner_v1.types.CommitResponse.CommitStats): - The statistics about this Commit. Not returned by default. - For more information, see - [CommitRequest.return_commit_stats][google.spanner.v1.CommitRequest.return_commit_stats]. - """ - - class CommitStats(proto.Message): - r"""Additional statistics about a commit. - - Attributes: - mutation_count (int): - The total number of mutations for the transaction. Knowing - the ``mutation_count`` value can help you maximize the - number of mutations in a transaction and minimize the number - of API round trips. You can also monitor this value to - prevent transactions from exceeding the system - `limit `__. - If the number of mutations exceeds the limit, the server - returns - `INVALID_ARGUMENT `__. - """ - - mutation_count: int = proto.Field( - proto.INT64, - number=1, - ) - - commit_timestamp: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=1, - message=timestamp_pb2.Timestamp, - ) - commit_stats: CommitStats = proto.Field( - proto.MESSAGE, - number=2, - message=CommitStats, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/keys.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/keys.py deleted file mode 100644 index ad0814437d..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/keys.py +++ /dev/null @@ -1,248 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.protobuf import struct_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.spanner.v1', - manifest={ - 'KeyRange', - 'KeySet', - }, -) - - -class KeyRange(proto.Message): - r"""KeyRange represents a range of rows in a table or index. - - A range has a start key and an end key. These keys can be open or - closed, indicating if the range includes rows with that key. - - Keys are represented by lists, where the ith value in the list - corresponds to the ith component of the table or index primary key. - Individual values are encoded as described - [here][google.spanner.v1.TypeCode]. - - For example, consider the following table definition: - - :: - - CREATE TABLE UserEvents ( - UserName STRING(MAX), - EventDate STRING(10) - ) PRIMARY KEY(UserName, EventDate); - - The following keys name rows in this table: - - :: - - ["Bob", "2014-09-23"] - ["Alfred", "2015-06-12"] - - Since the ``UserEvents`` table's ``PRIMARY KEY`` clause names two - columns, each ``UserEvents`` key has two elements; the first is the - ``UserName``, and the second is the ``EventDate``. - - Key ranges with multiple components are interpreted - lexicographically by component using the table or index key's - declared sort order. For example, the following range returns all - events for user ``"Bob"`` that occurred in the year 2015: - - :: - - "start_closed": ["Bob", "2015-01-01"] - "end_closed": ["Bob", "2015-12-31"] - - Start and end keys can omit trailing key components. This affects - the inclusion and exclusion of rows that exactly match the provided - key components: if the key is closed, then rows that exactly match - the provided components are included; if the key is open, then rows - that exactly match are not included. - - For example, the following range includes all events for ``"Bob"`` - that occurred during and after the year 2000: - - :: - - "start_closed": ["Bob", "2000-01-01"] - "end_closed": ["Bob"] - - The next example retrieves all events for ``"Bob"``: - - :: - - "start_closed": ["Bob"] - "end_closed": ["Bob"] - - To retrieve events before the year 2000: - - :: - - "start_closed": ["Bob"] - "end_open": ["Bob", "2000-01-01"] - - The following range includes all rows in the table: - - :: - - "start_closed": [] - "end_closed": [] - - This range returns all users whose ``UserName`` begins with any - character from A to C: - - :: - - "start_closed": ["A"] - "end_open": ["D"] - - This range returns all users whose ``UserName`` begins with B: - - :: - - "start_closed": ["B"] - "end_open": ["C"] - - Key ranges honor column sort order. For example, suppose a table is - defined as follows: - - :: - - CREATE TABLE DescendingSortedTable { - Key INT64, - ... - ) PRIMARY KEY(Key DESC); - - The following range retrieves all rows with key values between 1 and - 100 inclusive: - - :: - - "start_closed": ["100"] - "end_closed": ["1"] - - Note that 100 is passed as the start, and 1 is passed as the end, - because ``Key`` is a descending column in the schema. - - This message has `oneof`_ fields (mutually exclusive fields). - For each oneof, at most one member field can be set at the same time. - Setting any member of the oneof automatically clears all other - members. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - start_closed (google.protobuf.struct_pb2.ListValue): - If the start is closed, then the range includes all rows - whose first ``len(start_closed)`` key columns exactly match - ``start_closed``. - - This field is a member of `oneof`_ ``start_key_type``. - start_open (google.protobuf.struct_pb2.ListValue): - If the start is open, then the range excludes rows whose - first ``len(start_open)`` key columns exactly match - ``start_open``. - - This field is a member of `oneof`_ ``start_key_type``. - end_closed (google.protobuf.struct_pb2.ListValue): - If the end is closed, then the range includes all rows whose - first ``len(end_closed)`` key columns exactly match - ``end_closed``. - - This field is a member of `oneof`_ ``end_key_type``. - end_open (google.protobuf.struct_pb2.ListValue): - If the end is open, then the range excludes rows whose first - ``len(end_open)`` key columns exactly match ``end_open``. - - This field is a member of `oneof`_ ``end_key_type``. - """ - - start_closed: struct_pb2.ListValue = proto.Field( - proto.MESSAGE, - number=1, - oneof='start_key_type', - message=struct_pb2.ListValue, - ) - start_open: struct_pb2.ListValue = proto.Field( - proto.MESSAGE, - number=2, - oneof='start_key_type', - message=struct_pb2.ListValue, - ) - end_closed: struct_pb2.ListValue = proto.Field( - proto.MESSAGE, - number=3, - oneof='end_key_type', - message=struct_pb2.ListValue, - ) - end_open: struct_pb2.ListValue = proto.Field( - proto.MESSAGE, - number=4, - oneof='end_key_type', - message=struct_pb2.ListValue, - ) - - -class KeySet(proto.Message): - r"""``KeySet`` defines a collection of Cloud Spanner keys and/or key - ranges. All the keys are expected to be in the same table or index. - The keys need not be sorted in any particular way. - - If the same key is specified multiple times in the set (for example - if two ranges, two keys, or a key and a range overlap), Cloud - Spanner behaves as if the key were only specified once. - - Attributes: - keys (MutableSequence[google.protobuf.struct_pb2.ListValue]): - A list of specific keys. Entries in ``keys`` should have - exactly as many elements as there are columns in the primary - or index key with which this ``KeySet`` is used. Individual - key values are encoded as described - [here][google.spanner.v1.TypeCode]. - ranges (MutableSequence[google.cloud.spanner_v1.types.KeyRange]): - A list of key ranges. See - [KeyRange][google.spanner.v1.KeyRange] for more information - about key range specifications. - all_ (bool): - For convenience ``all`` can be set to ``true`` to indicate - that this ``KeySet`` matches all keys in the table or index. - Note that any keys specified in ``keys`` or ``ranges`` are - only yielded once. - """ - - keys: MutableSequence[struct_pb2.ListValue] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message=struct_pb2.ListValue, - ) - ranges: MutableSequence['KeyRange'] = proto.RepeatedField( - proto.MESSAGE, - number=2, - message='KeyRange', - ) - all_: bool = proto.Field( - proto.BOOL, - number=3, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/mutation.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/mutation.py deleted file mode 100644 index 8cfd519da0..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/mutation.py +++ /dev/null @@ -1,201 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.cloud.spanner_v1.types import keys -from google.protobuf import struct_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.spanner.v1', - manifest={ - 'Mutation', - }, -) - - -class Mutation(proto.Message): - r"""A modification to one or more Cloud Spanner rows. Mutations can be - applied to a Cloud Spanner database by sending them in a - [Commit][google.spanner.v1.Spanner.Commit] call. - - This message has `oneof`_ fields (mutually exclusive fields). - For each oneof, at most one member field can be set at the same time. - Setting any member of the oneof automatically clears all other - members. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - insert (google.cloud.spanner_v1.types.Mutation.Write): - Insert new rows in a table. If any of the rows already - exist, the write or transaction fails with error - ``ALREADY_EXISTS``. - - This field is a member of `oneof`_ ``operation``. - update (google.cloud.spanner_v1.types.Mutation.Write): - Update existing rows in a table. If any of the rows does not - already exist, the transaction fails with error - ``NOT_FOUND``. - - This field is a member of `oneof`_ ``operation``. - insert_or_update (google.cloud.spanner_v1.types.Mutation.Write): - Like [insert][google.spanner.v1.Mutation.insert], except - that if the row already exists, then its column values are - overwritten with the ones provided. Any column values not - explicitly written are preserved. - - When using - [insert_or_update][google.spanner.v1.Mutation.insert_or_update], - just as when using - [insert][google.spanner.v1.Mutation.insert], all - ``NOT NULL`` columns in the table must be given a value. - This holds true even when the row already exists and will - therefore actually be updated. - - This field is a member of `oneof`_ ``operation``. - replace (google.cloud.spanner_v1.types.Mutation.Write): - Like [insert][google.spanner.v1.Mutation.insert], except - that if the row already exists, it is deleted, and the - column values provided are inserted instead. Unlike - [insert_or_update][google.spanner.v1.Mutation.insert_or_update], - this means any values not explicitly written become - ``NULL``. - - In an interleaved table, if you create the child table with - the ``ON DELETE CASCADE`` annotation, then replacing a - parent row also deletes the child rows. Otherwise, you must - delete the child rows before you replace the parent row. - - This field is a member of `oneof`_ ``operation``. - delete (google.cloud.spanner_v1.types.Mutation.Delete): - Delete rows from a table. Succeeds whether or - not the named rows were present. - - This field is a member of `oneof`_ ``operation``. - """ - - class Write(proto.Message): - r"""Arguments to [insert][google.spanner.v1.Mutation.insert], - [update][google.spanner.v1.Mutation.update], - [insert_or_update][google.spanner.v1.Mutation.insert_or_update], and - [replace][google.spanner.v1.Mutation.replace] operations. - - Attributes: - table (str): - Required. The table whose rows will be - written. - columns (MutableSequence[str]): - The names of the columns in - [table][google.spanner.v1.Mutation.Write.table] to be - written. - - The list of columns must contain enough columns to allow - Cloud Spanner to derive values for all primary key columns - in the row(s) to be modified. - values (MutableSequence[google.protobuf.struct_pb2.ListValue]): - The values to be written. ``values`` can contain more than - one list of values. If it does, then multiple rows are - written, one for each entry in ``values``. Each list in - ``values`` must have exactly as many entries as there are - entries in - [columns][google.spanner.v1.Mutation.Write.columns] above. - Sending multiple lists is equivalent to sending multiple - ``Mutation``\ s, each containing one ``values`` entry and - repeating [table][google.spanner.v1.Mutation.Write.table] - and [columns][google.spanner.v1.Mutation.Write.columns]. - Individual values in each list are encoded as described - [here][google.spanner.v1.TypeCode]. - """ - - table: str = proto.Field( - proto.STRING, - number=1, - ) - columns: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=2, - ) - values: MutableSequence[struct_pb2.ListValue] = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=struct_pb2.ListValue, - ) - - class Delete(proto.Message): - r"""Arguments to [delete][google.spanner.v1.Mutation.delete] operations. - - Attributes: - table (str): - Required. The table whose rows will be - deleted. - key_set (google.cloud.spanner_v1.types.KeySet): - Required. The primary keys of the rows within - [table][google.spanner.v1.Mutation.Delete.table] to delete. - The primary keys must be specified in the order in which - they appear in the ``PRIMARY KEY()`` clause of the table's - equivalent DDL statement (the DDL statement used to create - the table). Delete is idempotent. The transaction will - succeed even if some or all rows do not exist. - """ - - table: str = proto.Field( - proto.STRING, - number=1, - ) - key_set: keys.KeySet = proto.Field( - proto.MESSAGE, - number=2, - message=keys.KeySet, - ) - - insert: Write = proto.Field( - proto.MESSAGE, - number=1, - oneof='operation', - message=Write, - ) - update: Write = proto.Field( - proto.MESSAGE, - number=2, - oneof='operation', - message=Write, - ) - insert_or_update: Write = proto.Field( - proto.MESSAGE, - number=3, - oneof='operation', - message=Write, - ) - replace: Write = proto.Field( - proto.MESSAGE, - number=4, - oneof='operation', - message=Write, - ) - delete: Delete = proto.Field( - proto.MESSAGE, - number=5, - oneof='operation', - message=Delete, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/query_plan.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/query_plan.py deleted file mode 100644 index 93994f76d1..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/query_plan.py +++ /dev/null @@ -1,219 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.protobuf import struct_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.spanner.v1', - manifest={ - 'PlanNode', - 'QueryPlan', - }, -) - - -class PlanNode(proto.Message): - r"""Node information for nodes appearing in a - [QueryPlan.plan_nodes][google.spanner.v1.QueryPlan.plan_nodes]. - - Attributes: - index (int): - The ``PlanNode``'s index in [node - list][google.spanner.v1.QueryPlan.plan_nodes]. - kind (google.cloud.spanner_v1.types.PlanNode.Kind): - Used to determine the type of node. May be needed for - visualizing different kinds of nodes differently. For - example, If the node is a - [SCALAR][google.spanner.v1.PlanNode.Kind.SCALAR] node, it - will have a condensed representation which can be used to - directly embed a description of the node in its parent. - display_name (str): - The display name for the node. - child_links (MutableSequence[google.cloud.spanner_v1.types.PlanNode.ChildLink]): - List of child node ``index``\ es and their relationship to - this parent. - short_representation (google.cloud.spanner_v1.types.PlanNode.ShortRepresentation): - Condensed representation for - [SCALAR][google.spanner.v1.PlanNode.Kind.SCALAR] nodes. - metadata (google.protobuf.struct_pb2.Struct): - Attributes relevant to the node contained in a group of - key-value pairs. For example, a Parameter Reference node - could have the following information in its metadata: - - :: - - { - "parameter_reference": "param1", - "parameter_type": "array" - } - execution_stats (google.protobuf.struct_pb2.Struct): - The execution statistics associated with the - node, contained in a group of key-value pairs. - Only present if the plan was returned as a - result of a profile query. For example, number - of executions, number of rows/time per execution - etc. - """ - class Kind(proto.Enum): - r"""The kind of [PlanNode][google.spanner.v1.PlanNode]. Distinguishes - between the two different kinds of nodes that can appear in a query - plan. - - Values: - KIND_UNSPECIFIED (0): - Not specified. - RELATIONAL (1): - Denotes a Relational operator node in the expression tree. - Relational operators represent iterative processing of rows - during query execution. For example, a ``TableScan`` - operation that reads rows from a table. - SCALAR (2): - Denotes a Scalar node in the expression tree. - Scalar nodes represent non-iterable entities in - the query plan. For example, constants or - arithmetic operators appearing inside predicate - expressions or references to column names. - """ - KIND_UNSPECIFIED = 0 - RELATIONAL = 1 - SCALAR = 2 - - class ChildLink(proto.Message): - r"""Metadata associated with a parent-child relationship appearing in a - [PlanNode][google.spanner.v1.PlanNode]. - - Attributes: - child_index (int): - The node to which the link points. - type_ (str): - The type of the link. For example, in Hash - Joins this could be used to distinguish between - the build child and the probe child, or in the - case of the child being an output variable, to - represent the tag associated with the output - variable. - variable (str): - Only present if the child node is - [SCALAR][google.spanner.v1.PlanNode.Kind.SCALAR] and - corresponds to an output variable of the parent node. The - field carries the name of the output variable. For example, - a ``TableScan`` operator that reads rows from a table will - have child links to the ``SCALAR`` nodes representing the - output variables created for each column that is read by the - operator. The corresponding ``variable`` fields will be set - to the variable names assigned to the columns. - """ - - child_index: int = proto.Field( - proto.INT32, - number=1, - ) - type_: str = proto.Field( - proto.STRING, - number=2, - ) - variable: str = proto.Field( - proto.STRING, - number=3, - ) - - class ShortRepresentation(proto.Message): - r"""Condensed representation of a node and its subtree. Only present for - ``SCALAR`` [PlanNode(s)][google.spanner.v1.PlanNode]. - - Attributes: - description (str): - A string representation of the expression - subtree rooted at this node. - subqueries (MutableMapping[str, int]): - A mapping of (subquery variable name) -> (subquery node id) - for cases where the ``description`` string of this node - references a ``SCALAR`` subquery contained in the expression - subtree rooted at this node. The referenced ``SCALAR`` - subquery may not necessarily be a direct child of this node. - """ - - description: str = proto.Field( - proto.STRING, - number=1, - ) - subqueries: MutableMapping[str, int] = proto.MapField( - proto.STRING, - proto.INT32, - number=2, - ) - - index: int = proto.Field( - proto.INT32, - number=1, - ) - kind: Kind = proto.Field( - proto.ENUM, - number=2, - enum=Kind, - ) - display_name: str = proto.Field( - proto.STRING, - number=3, - ) - child_links: MutableSequence[ChildLink] = proto.RepeatedField( - proto.MESSAGE, - number=4, - message=ChildLink, - ) - short_representation: ShortRepresentation = proto.Field( - proto.MESSAGE, - number=5, - message=ShortRepresentation, - ) - metadata: struct_pb2.Struct = proto.Field( - proto.MESSAGE, - number=6, - message=struct_pb2.Struct, - ) - execution_stats: struct_pb2.Struct = proto.Field( - proto.MESSAGE, - number=7, - message=struct_pb2.Struct, - ) - - -class QueryPlan(proto.Message): - r"""Contains an ordered list of nodes appearing in the query - plan. - - Attributes: - plan_nodes (MutableSequence[google.cloud.spanner_v1.types.PlanNode]): - The nodes in the query plan. Plan nodes are returned in - pre-order starting with the plan root. Each - [PlanNode][google.spanner.v1.PlanNode]'s ``id`` corresponds - to its index in ``plan_nodes``. - """ - - plan_nodes: MutableSequence['PlanNode'] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='PlanNode', - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/result_set.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/result_set.py deleted file mode 100644 index cf085ee9a9..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/result_set.py +++ /dev/null @@ -1,341 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.cloud.spanner_v1.types import query_plan as gs_query_plan -from google.cloud.spanner_v1.types import transaction as gs_transaction -from google.cloud.spanner_v1.types import type as gs_type -from google.protobuf import struct_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.spanner.v1', - manifest={ - 'ResultSet', - 'PartialResultSet', - 'ResultSetMetadata', - 'ResultSetStats', - }, -) - - -class ResultSet(proto.Message): - r"""Results from [Read][google.spanner.v1.Spanner.Read] or - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. - - Attributes: - metadata (google.cloud.spanner_v1.types.ResultSetMetadata): - Metadata about the result set, such as row - type information. - rows (MutableSequence[google.protobuf.struct_pb2.ListValue]): - Each element in ``rows`` is a row whose format is defined by - [metadata.row_type][google.spanner.v1.ResultSetMetadata.row_type]. - The ith element in each row matches the ith field in - [metadata.row_type][google.spanner.v1.ResultSetMetadata.row_type]. - Elements are encoded based on type as described - [here][google.spanner.v1.TypeCode]. - stats (google.cloud.spanner_v1.types.ResultSetStats): - Query plan and execution statistics for the SQL statement - that produced this result set. These can be requested by - setting - [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode]. - DML statements always produce stats containing the number of - rows modified, unless executed using the - [ExecuteSqlRequest.QueryMode.PLAN][google.spanner.v1.ExecuteSqlRequest.QueryMode.PLAN] - [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode]. - Other fields may or may not be populated, based on the - [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode]. - """ - - metadata: 'ResultSetMetadata' = proto.Field( - proto.MESSAGE, - number=1, - message='ResultSetMetadata', - ) - rows: MutableSequence[struct_pb2.ListValue] = proto.RepeatedField( - proto.MESSAGE, - number=2, - message=struct_pb2.ListValue, - ) - stats: 'ResultSetStats' = proto.Field( - proto.MESSAGE, - number=3, - message='ResultSetStats', - ) - - -class PartialResultSet(proto.Message): - r"""Partial results from a streaming read or SQL query. Streaming - reads and SQL queries better tolerate large result sets, large - rows, and large values, but are a little trickier to consume. - - Attributes: - metadata (google.cloud.spanner_v1.types.ResultSetMetadata): - Metadata about the result set, such as row - type information. Only present in the first - response. - values (MutableSequence[google.protobuf.struct_pb2.Value]): - A streamed result set consists of a stream of values, which - might be split into many ``PartialResultSet`` messages to - accommodate large rows and/or large values. Every N complete - values defines a row, where N is equal to the number of - entries in - [metadata.row_type.fields][google.spanner.v1.StructType.fields]. - - Most values are encoded based on type as described - [here][google.spanner.v1.TypeCode]. - - It is possible that the last value in values is "chunked", - meaning that the rest of the value is sent in subsequent - ``PartialResultSet``\ (s). This is denoted by the - [chunked_value][google.spanner.v1.PartialResultSet.chunked_value] - field. Two or more chunked values can be merged to form a - complete value as follows: - - - ``bool/number/null``: cannot be chunked - - ``string``: concatenate the strings - - ``list``: concatenate the lists. If the last element in a - list is a ``string``, ``list``, or ``object``, merge it - with the first element in the next list by applying these - rules recursively. - - ``object``: concatenate the (field name, field value) - pairs. If a field name is duplicated, then apply these - rules recursively to merge the field values. - - Some examples of merging: - - :: - - # Strings are concatenated. - "foo", "bar" => "foobar" - - # Lists of non-strings are concatenated. - [2, 3], [4] => [2, 3, 4] - - # Lists are concatenated, but the last and first elements are merged - # because they are strings. - ["a", "b"], ["c", "d"] => ["a", "bc", "d"] - - # Lists are concatenated, but the last and first elements are merged - # because they are lists. Recursively, the last and first elements - # of the inner lists are merged because they are strings. - ["a", ["b", "c"]], [["d"], "e"] => ["a", ["b", "cd"], "e"] - - # Non-overlapping object fields are combined. - {"a": "1"}, {"b": "2"} => {"a": "1", "b": 2"} - - # Overlapping object fields are merged. - {"a": "1"}, {"a": "2"} => {"a": "12"} - - # Examples of merging objects containing lists of strings. - {"a": ["1"]}, {"a": ["2"]} => {"a": ["12"]} - - For a more complete example, suppose a streaming SQL query - is yielding a result set whose rows contain a single string - field. The following ``PartialResultSet``\ s might be - yielded: - - :: - - { - "metadata": { ... } - "values": ["Hello", "W"] - "chunked_value": true - "resume_token": "Af65..." - } - { - "values": ["orl"] - "chunked_value": true - "resume_token": "Bqp2..." - } - { - "values": ["d"] - "resume_token": "Zx1B..." - } - - This sequence of ``PartialResultSet``\ s encodes two rows, - one containing the field value ``"Hello"``, and a second - containing the field value ``"World" = "W" + "orl" + "d"``. - chunked_value (bool): - If true, then the final value in - [values][google.spanner.v1.PartialResultSet.values] is - chunked, and must be combined with more values from - subsequent ``PartialResultSet``\ s to obtain a complete - field value. - resume_token (bytes): - Streaming calls might be interrupted for a variety of - reasons, such as TCP connection loss. If this occurs, the - stream of results can be resumed by re-sending the original - request and including ``resume_token``. Note that executing - any other transaction in the same session invalidates the - token. - stats (google.cloud.spanner_v1.types.ResultSetStats): - Query plan and execution statistics for the statement that - produced this streaming result set. These can be requested - by setting - [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode] - and are sent only once with the last response in the stream. - This field will also be present in the last response for DML - statements. - """ - - metadata: 'ResultSetMetadata' = proto.Field( - proto.MESSAGE, - number=1, - message='ResultSetMetadata', - ) - values: MutableSequence[struct_pb2.Value] = proto.RepeatedField( - proto.MESSAGE, - number=2, - message=struct_pb2.Value, - ) - chunked_value: bool = proto.Field( - proto.BOOL, - number=3, - ) - resume_token: bytes = proto.Field( - proto.BYTES, - number=4, - ) - stats: 'ResultSetStats' = proto.Field( - proto.MESSAGE, - number=5, - message='ResultSetStats', - ) - - -class ResultSetMetadata(proto.Message): - r"""Metadata about a [ResultSet][google.spanner.v1.ResultSet] or - [PartialResultSet][google.spanner.v1.PartialResultSet]. - - Attributes: - row_type (google.cloud.spanner_v1.types.StructType): - Indicates the field names and types for the rows in the - result set. For example, a SQL query like - ``"SELECT UserId, UserName FROM Users"`` could return a - ``row_type`` value like: - - :: - - "fields": [ - { "name": "UserId", "type": { "code": "INT64" } }, - { "name": "UserName", "type": { "code": "STRING" } }, - ] - transaction (google.cloud.spanner_v1.types.Transaction): - If the read or SQL query began a transaction - as a side-effect, the information about the new - transaction is yielded here. - undeclared_parameters (google.cloud.spanner_v1.types.StructType): - A SQL query can be parameterized. In PLAN mode, these - parameters can be undeclared. This indicates the field names - and types for those undeclared parameters in the SQL query. - For example, a SQL query like - ``"SELECT * FROM Users where UserId = @userId and UserName = @userName "`` - could return a ``undeclared_parameters`` value like: - - :: - - "fields": [ - { "name": "UserId", "type": { "code": "INT64" } }, - { "name": "UserName", "type": { "code": "STRING" } }, - ] - """ - - row_type: gs_type.StructType = proto.Field( - proto.MESSAGE, - number=1, - message=gs_type.StructType, - ) - transaction: gs_transaction.Transaction = proto.Field( - proto.MESSAGE, - number=2, - message=gs_transaction.Transaction, - ) - undeclared_parameters: gs_type.StructType = proto.Field( - proto.MESSAGE, - number=3, - message=gs_type.StructType, - ) - - -class ResultSetStats(proto.Message): - r"""Additional statistics about a - [ResultSet][google.spanner.v1.ResultSet] or - [PartialResultSet][google.spanner.v1.PartialResultSet]. - - This message has `oneof`_ fields (mutually exclusive fields). - For each oneof, at most one member field can be set at the same time. - Setting any member of the oneof automatically clears all other - members. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - query_plan (google.cloud.spanner_v1.types.QueryPlan): - [QueryPlan][google.spanner.v1.QueryPlan] for the query - associated with this result. - query_stats (google.protobuf.struct_pb2.Struct): - Aggregated statistics from the execution of the query. Only - present when the query is profiled. For example, a query - could return the statistics as follows: - - :: - - { - "rows_returned": "3", - "elapsed_time": "1.22 secs", - "cpu_time": "1.19 secs" - } - row_count_exact (int): - Standard DML returns an exact count of rows - that were modified. - - This field is a member of `oneof`_ ``row_count``. - row_count_lower_bound (int): - Partitioned DML does not offer exactly-once - semantics, so it returns a lower bound of the - rows modified. - - This field is a member of `oneof`_ ``row_count``. - """ - - query_plan: gs_query_plan.QueryPlan = proto.Field( - proto.MESSAGE, - number=1, - message=gs_query_plan.QueryPlan, - ) - query_stats: struct_pb2.Struct = proto.Field( - proto.MESSAGE, - number=2, - message=struct_pb2.Struct, - ) - row_count_exact: int = proto.Field( - proto.INT64, - number=3, - oneof='row_count', - ) - row_count_lower_bound: int = proto.Field( - proto.INT64, - number=4, - oneof='row_count', - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/spanner.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/spanner.py deleted file mode 100644 index 995fb6e126..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/spanner.py +++ /dev/null @@ -1,1327 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.cloud.spanner_v1.types import keys -from google.cloud.spanner_v1.types import mutation -from google.cloud.spanner_v1.types import result_set -from google.cloud.spanner_v1.types import transaction as gs_transaction -from google.cloud.spanner_v1.types import type as gs_type -from google.protobuf import struct_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.spanner.v1', - manifest={ - 'CreateSessionRequest', - 'BatchCreateSessionsRequest', - 'BatchCreateSessionsResponse', - 'Session', - 'GetSessionRequest', - 'ListSessionsRequest', - 'ListSessionsResponse', - 'DeleteSessionRequest', - 'RequestOptions', - 'ExecuteSqlRequest', - 'ExecuteBatchDmlRequest', - 'ExecuteBatchDmlResponse', - 'PartitionOptions', - 'PartitionQueryRequest', - 'PartitionReadRequest', - 'Partition', - 'PartitionResponse', - 'ReadRequest', - 'BeginTransactionRequest', - 'CommitRequest', - 'RollbackRequest', - }, -) - - -class CreateSessionRequest(proto.Message): - r"""The request for - [CreateSession][google.spanner.v1.Spanner.CreateSession]. - - Attributes: - database (str): - Required. The database in which the new - session is created. - session (google.cloud.spanner_v1.types.Session): - Required. The session to create. - """ - - database: str = proto.Field( - proto.STRING, - number=1, - ) - session: 'Session' = proto.Field( - proto.MESSAGE, - number=2, - message='Session', - ) - - -class BatchCreateSessionsRequest(proto.Message): - r"""The request for - [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. - - Attributes: - database (str): - Required. The database in which the new - sessions are created. - session_template (google.cloud.spanner_v1.types.Session): - Parameters to be applied to each created - session. - session_count (int): - Required. The number of sessions to be created in this batch - call. The API may return fewer than the requested number of - sessions. If a specific number of sessions are desired, the - client can make additional calls to BatchCreateSessions - (adjusting - [session_count][google.spanner.v1.BatchCreateSessionsRequest.session_count] - as necessary). - """ - - database: str = proto.Field( - proto.STRING, - number=1, - ) - session_template: 'Session' = proto.Field( - proto.MESSAGE, - number=2, - message='Session', - ) - session_count: int = proto.Field( - proto.INT32, - number=3, - ) - - -class BatchCreateSessionsResponse(proto.Message): - r"""The response for - [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions]. - - Attributes: - session (MutableSequence[google.cloud.spanner_v1.types.Session]): - The freshly created sessions. - """ - - session: MutableSequence['Session'] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Session', - ) - - -class Session(proto.Message): - r"""A session in the Cloud Spanner API. - - Attributes: - name (str): - Output only. The name of the session. This is - always system-assigned. - labels (MutableMapping[str, str]): - The labels for the session. - - - Label keys must be between 1 and 63 characters long and - must conform to the following regular expression: - ``[a-z]([-a-z0-9]*[a-z0-9])?``. - - Label values must be between 0 and 63 characters long and - must conform to the regular expression - ``([a-z]([-a-z0-9]*[a-z0-9])?)?``. - - No more than 64 labels can be associated with a given - session. - - See https://goo.gl/xmQnxf for more information on and - examples of labels. - create_time (google.protobuf.timestamp_pb2.Timestamp): - Output only. The timestamp when the session - is created. - approximate_last_use_time (google.protobuf.timestamp_pb2.Timestamp): - Output only. The approximate timestamp when - the session is last used. It is typically - earlier than the actual last use time. - creator_role (str): - The database role which created this session. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - labels: MutableMapping[str, str] = proto.MapField( - proto.STRING, - proto.STRING, - number=2, - ) - create_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - approximate_last_use_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp_pb2.Timestamp, - ) - creator_role: str = proto.Field( - proto.STRING, - number=5, - ) - - -class GetSessionRequest(proto.Message): - r"""The request for [GetSession][google.spanner.v1.Spanner.GetSession]. - - Attributes: - name (str): - Required. The name of the session to - retrieve. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - - -class ListSessionsRequest(proto.Message): - r"""The request for - [ListSessions][google.spanner.v1.Spanner.ListSessions]. - - Attributes: - database (str): - Required. The database in which to list - sessions. - page_size (int): - Number of sessions to be returned in the - response. If 0 or less, defaults to the server's - maximum allowed page size. - page_token (str): - If non-empty, ``page_token`` should contain a - [next_page_token][google.spanner.v1.ListSessionsResponse.next_page_token] - from a previous - [ListSessionsResponse][google.spanner.v1.ListSessionsResponse]. - filter (str): - An expression for filtering the results of the request. - Filter rules are case insensitive. The fields eligible for - filtering are: - - - ``labels.key`` where key is the name of a label - - Some examples of using filters are: - - - ``labels.env:*`` --> The session has the label "env". - - ``labels.env:dev`` --> The session has the label "env" - and the value of the label contains the string "dev". - """ - - database: str = proto.Field( - proto.STRING, - number=1, - ) - page_size: int = proto.Field( - proto.INT32, - number=2, - ) - page_token: str = proto.Field( - proto.STRING, - number=3, - ) - filter: str = proto.Field( - proto.STRING, - number=4, - ) - - -class ListSessionsResponse(proto.Message): - r"""The response for - [ListSessions][google.spanner.v1.Spanner.ListSessions]. - - Attributes: - sessions (MutableSequence[google.cloud.spanner_v1.types.Session]): - The list of requested sessions. - next_page_token (str): - ``next_page_token`` can be sent in a subsequent - [ListSessions][google.spanner.v1.Spanner.ListSessions] call - to fetch more of the matching sessions. - """ - - @property - def raw_page(self): - return self - - sessions: MutableSequence['Session'] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Session', - ) - next_page_token: str = proto.Field( - proto.STRING, - number=2, - ) - - -class DeleteSessionRequest(proto.Message): - r"""The request for - [DeleteSession][google.spanner.v1.Spanner.DeleteSession]. - - Attributes: - name (str): - Required. The name of the session to delete. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - - -class RequestOptions(proto.Message): - r"""Common request options for various APIs. - - Attributes: - priority (google.cloud.spanner_v1.types.RequestOptions.Priority): - Priority for the request. - request_tag (str): - A per-request tag which can be applied to queries or reads, - used for statistics collection. Both request_tag and - transaction_tag can be specified for a read or query that - belongs to a transaction. This field is ignored for requests - where it's not applicable (e.g. CommitRequest). Legal - characters for ``request_tag`` values are all printable - characters (ASCII 32 - 126) and the length of a request_tag - is limited to 50 characters. Values that exceed this limit - are truncated. Any leading underscore (_) characters will be - removed from the string. - transaction_tag (str): - A tag used for statistics collection about this transaction. - Both request_tag and transaction_tag can be specified for a - read or query that belongs to a transaction. The value of - transaction_tag should be the same for all requests - belonging to the same transaction. If this request doesn't - belong to any transaction, transaction_tag will be ignored. - Legal characters for ``transaction_tag`` values are all - printable characters (ASCII 32 - 126) and the length of a - transaction_tag is limited to 50 characters. Values that - exceed this limit are truncated. Any leading underscore (_) - characters will be removed from the string. - """ - class Priority(proto.Enum): - r"""The relative priority for requests. Note that priority is not - applicable for - [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction]. - - The priority acts as a hint to the Cloud Spanner scheduler and does - not guarantee priority or order of execution. For example: - - - Some parts of a write operation always execute at - ``PRIORITY_HIGH``, regardless of the specified priority. This may - cause you to see an increase in high priority workload even when - executing a low priority request. This can also potentially cause - a priority inversion where a lower priority request will be - fulfilled ahead of a higher priority request. - - If a transaction contains multiple operations with different - priorities, Cloud Spanner does not guarantee to process the - higher priority operations first. There may be other constraints - to satisfy, such as order of operations. - - Values: - PRIORITY_UNSPECIFIED (0): - ``PRIORITY_UNSPECIFIED`` is equivalent to ``PRIORITY_HIGH``. - PRIORITY_LOW (1): - This specifies that the request is low - priority. - PRIORITY_MEDIUM (2): - This specifies that the request is medium - priority. - PRIORITY_HIGH (3): - This specifies that the request is high - priority. - """ - PRIORITY_UNSPECIFIED = 0 - PRIORITY_LOW = 1 - PRIORITY_MEDIUM = 2 - PRIORITY_HIGH = 3 - - priority: Priority = proto.Field( - proto.ENUM, - number=1, - enum=Priority, - ) - request_tag: str = proto.Field( - proto.STRING, - number=2, - ) - transaction_tag: str = proto.Field( - proto.STRING, - number=3, - ) - - -class ExecuteSqlRequest(proto.Message): - r"""The request for [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] - and - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql]. - - Attributes: - session (str): - Required. The session in which the SQL query - should be performed. - transaction (google.cloud.spanner_v1.types.TransactionSelector): - The transaction to use. - For queries, if none is provided, the default is - a temporary read-only transaction with strong - concurrency. - - Standard DML statements require a read-write - transaction. To protect against replays, - single-use transactions are not supported. The - caller must either supply an existing - transaction ID or begin a new transaction. - Partitioned DML requires an existing Partitioned - DML transaction ID. - sql (str): - Required. The SQL string. - params (google.protobuf.struct_pb2.Struct): - Parameter names and values that bind to placeholders in the - SQL string. - - A parameter placeholder consists of the ``@`` character - followed by the parameter name (for example, - ``@firstName``). Parameter names must conform to the naming - requirements of identifiers as specified at - https://cloud.google.com/spanner/docs/lexical#identifiers. - - Parameters can appear anywhere that a literal value is - expected. The same parameter name can be used more than - once, for example: - - ``"WHERE id > @msg_id AND id < @msg_id + 100"`` - - It is an error to execute a SQL statement with unbound - parameters. - param_types (MutableMapping[str, google.cloud.spanner_v1.types.Type]): - It is not always possible for Cloud Spanner to infer the - right SQL type from a JSON value. For example, values of - type ``BYTES`` and values of type ``STRING`` both appear in - [params][google.spanner.v1.ExecuteSqlRequest.params] as JSON - strings. - - In these cases, ``param_types`` can be used to specify the - exact SQL type for some or all of the SQL statement - parameters. See the definition of - [Type][google.spanner.v1.Type] for more information about - SQL types. - resume_token (bytes): - If this request is resuming a previously interrupted SQL - statement execution, ``resume_token`` should be copied from - the last - [PartialResultSet][google.spanner.v1.PartialResultSet] - yielded before the interruption. Doing this enables the new - SQL statement execution to resume where the last one left - off. The rest of the request parameters must exactly match - the request that yielded this token. - query_mode (google.cloud.spanner_v1.types.ExecuteSqlRequest.QueryMode): - Used to control the amount of debugging information returned - in [ResultSetStats][google.spanner.v1.ResultSetStats]. If - [partition_token][google.spanner.v1.ExecuteSqlRequest.partition_token] - is set, - [query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode] - can only be set to - [QueryMode.NORMAL][google.spanner.v1.ExecuteSqlRequest.QueryMode.NORMAL]. - partition_token (bytes): - If present, results will be restricted to the specified - partition previously created using PartitionQuery(). There - must be an exact match for the values of fields common to - this message and the PartitionQueryRequest message used to - create this partition_token. - seqno (int): - A per-transaction sequence number used to - identify this request. This field makes each - request idempotent such that if the request is - received multiple times, at most one will - succeed. - - The sequence number must be monotonically - increasing within the transaction. If a request - arrives for the first time with an out-of-order - sequence number, the transaction may be aborted. - Replays of previously handled requests will - yield the same response as the first execution. - Required for DML statements. Ignored for - queries. - query_options (google.cloud.spanner_v1.types.ExecuteSqlRequest.QueryOptions): - Query optimizer configuration to use for the - given query. - request_options (google.cloud.spanner_v1.types.RequestOptions): - Common options for this request. - data_boost_enabled (bool): - If this is for a partitioned query and this field is set to - ``true``, the request will be executed via Spanner - independent compute resources. - - If the field is set to ``true`` but the request does not set - ``partition_token``, the API will return an - ``INVALID_ARGUMENT`` error. - """ - class QueryMode(proto.Enum): - r"""Mode in which the statement must be processed. - - Values: - NORMAL (0): - The default mode. Only the statement results - are returned. - PLAN (1): - This mode returns only the query plan, - without any results or execution statistics - information. - PROFILE (2): - This mode returns both the query plan and the - execution statistics along with the results. - """ - NORMAL = 0 - PLAN = 1 - PROFILE = 2 - - class QueryOptions(proto.Message): - r"""Query optimizer configuration. - - Attributes: - optimizer_version (str): - An option to control the selection of optimizer version. - - This parameter allows individual queries to pick different - query optimizer versions. - - Specifying ``latest`` as a value instructs Cloud Spanner to - use the latest supported query optimizer version. If not - specified, Cloud Spanner uses the optimizer version set at - the database level options. Any other positive integer (from - the list of supported optimizer versions) overrides the - default optimizer version for query execution. - - The list of supported optimizer versions can be queried from - SPANNER_SYS.SUPPORTED_OPTIMIZER_VERSIONS. - - Executing a SQL statement with an invalid optimizer version - fails with an ``INVALID_ARGUMENT`` error. - - See - https://cloud.google.com/spanner/docs/query-optimizer/manage-query-optimizer - for more information on managing the query optimizer. - - The ``optimizer_version`` statement hint has precedence over - this setting. - optimizer_statistics_package (str): - An option to control the selection of optimizer statistics - package. - - This parameter allows individual queries to use a different - query optimizer statistics package. - - Specifying ``latest`` as a value instructs Cloud Spanner to - use the latest generated statistics package. If not - specified, Cloud Spanner uses the statistics package set at - the database level options, or the latest package if the - database option is not set. - - The statistics package requested by the query has to be - exempt from garbage collection. This can be achieved with - the following DDL statement: - - :: - - ALTER STATISTICS SET OPTIONS (allow_gc=false) - - The list of available statistics packages can be queried - from ``INFORMATION_SCHEMA.SPANNER_STATISTICS``. - - Executing a SQL statement with an invalid optimizer - statistics package or with a statistics package that allows - garbage collection fails with an ``INVALID_ARGUMENT`` error. - """ - - optimizer_version: str = proto.Field( - proto.STRING, - number=1, - ) - optimizer_statistics_package: str = proto.Field( - proto.STRING, - number=2, - ) - - session: str = proto.Field( - proto.STRING, - number=1, - ) - transaction: gs_transaction.TransactionSelector = proto.Field( - proto.MESSAGE, - number=2, - message=gs_transaction.TransactionSelector, - ) - sql: str = proto.Field( - proto.STRING, - number=3, - ) - params: struct_pb2.Struct = proto.Field( - proto.MESSAGE, - number=4, - message=struct_pb2.Struct, - ) - param_types: MutableMapping[str, gs_type.Type] = proto.MapField( - proto.STRING, - proto.MESSAGE, - number=5, - message=gs_type.Type, - ) - resume_token: bytes = proto.Field( - proto.BYTES, - number=6, - ) - query_mode: QueryMode = proto.Field( - proto.ENUM, - number=7, - enum=QueryMode, - ) - partition_token: bytes = proto.Field( - proto.BYTES, - number=8, - ) - seqno: int = proto.Field( - proto.INT64, - number=9, - ) - query_options: QueryOptions = proto.Field( - proto.MESSAGE, - number=10, - message=QueryOptions, - ) - request_options: 'RequestOptions' = proto.Field( - proto.MESSAGE, - number=11, - message='RequestOptions', - ) - data_boost_enabled: bool = proto.Field( - proto.BOOL, - number=16, - ) - - -class ExecuteBatchDmlRequest(proto.Message): - r"""The request for - [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. - - Attributes: - session (str): - Required. The session in which the DML - statements should be performed. - transaction (google.cloud.spanner_v1.types.TransactionSelector): - Required. The transaction to use. Must be a - read-write transaction. - To protect against replays, single-use - transactions are not supported. The caller must - either supply an existing transaction ID or - begin a new transaction. - statements (MutableSequence[google.cloud.spanner_v1.types.ExecuteBatchDmlRequest.Statement]): - Required. The list of statements to execute in this batch. - Statements are executed serially, such that the effects of - statement ``i`` are visible to statement ``i+1``. Each - statement must be a DML statement. Execution stops at the - first failed statement; the remaining statements are not - executed. - - Callers must provide at least one statement. - seqno (int): - Required. A per-transaction sequence number - used to identify this request. This field makes - each request idempotent such that if the request - is received multiple times, at most one will - succeed. - - The sequence number must be monotonically - increasing within the transaction. If a request - arrives for the first time with an out-of-order - sequence number, the transaction may be aborted. - Replays of previously handled requests will - yield the same response as the first execution. - request_options (google.cloud.spanner_v1.types.RequestOptions): - Common options for this request. - """ - - class Statement(proto.Message): - r"""A single DML statement. - - Attributes: - sql (str): - Required. The DML string. - params (google.protobuf.struct_pb2.Struct): - Parameter names and values that bind to placeholders in the - DML string. - - A parameter placeholder consists of the ``@`` character - followed by the parameter name (for example, - ``@firstName``). Parameter names can contain letters, - numbers, and underscores. - - Parameters can appear anywhere that a literal value is - expected. The same parameter name can be used more than - once, for example: - - ``"WHERE id > @msg_id AND id < @msg_id + 100"`` - - It is an error to execute a SQL statement with unbound - parameters. - param_types (MutableMapping[str, google.cloud.spanner_v1.types.Type]): - It is not always possible for Cloud Spanner to infer the - right SQL type from a JSON value. For example, values of - type ``BYTES`` and values of type ``STRING`` both appear in - [params][google.spanner.v1.ExecuteBatchDmlRequest.Statement.params] - as JSON strings. - - In these cases, ``param_types`` can be used to specify the - exact SQL type for some or all of the SQL statement - parameters. See the definition of - [Type][google.spanner.v1.Type] for more information about - SQL types. - """ - - sql: str = proto.Field( - proto.STRING, - number=1, - ) - params: struct_pb2.Struct = proto.Field( - proto.MESSAGE, - number=2, - message=struct_pb2.Struct, - ) - param_types: MutableMapping[str, gs_type.Type] = proto.MapField( - proto.STRING, - proto.MESSAGE, - number=3, - message=gs_type.Type, - ) - - session: str = proto.Field( - proto.STRING, - number=1, - ) - transaction: gs_transaction.TransactionSelector = proto.Field( - proto.MESSAGE, - number=2, - message=gs_transaction.TransactionSelector, - ) - statements: MutableSequence[Statement] = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=Statement, - ) - seqno: int = proto.Field( - proto.INT64, - number=4, - ) - request_options: 'RequestOptions' = proto.Field( - proto.MESSAGE, - number=5, - message='RequestOptions', - ) - - -class ExecuteBatchDmlResponse(proto.Message): - r"""The response for - [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. - Contains a list of [ResultSet][google.spanner.v1.ResultSet] - messages, one for each DML statement that has successfully executed, - in the same order as the statements in the request. If a statement - fails, the status in the response body identifies the cause of the - failure. - - To check for DML statements that failed, use the following approach: - - 1. Check the status in the response message. The - [google.rpc.Code][google.rpc.Code] enum value ``OK`` indicates - that all statements were executed successfully. - 2. If the status was not ``OK``, check the number of result sets in - the response. If the response contains ``N`` - [ResultSet][google.spanner.v1.ResultSet] messages, then statement - ``N+1`` in the request failed. - - Example 1: - - - Request: 5 DML statements, all executed successfully. - - Response: 5 [ResultSet][google.spanner.v1.ResultSet] messages, - with the status ``OK``. - - Example 2: - - - Request: 5 DML statements. The third statement has a syntax - error. - - Response: 2 [ResultSet][google.spanner.v1.ResultSet] messages, - and a syntax error (``INVALID_ARGUMENT``) status. The number of - [ResultSet][google.spanner.v1.ResultSet] messages indicates that - the third statement failed, and the fourth and fifth statements - were not executed. - - Attributes: - result_sets (MutableSequence[google.cloud.spanner_v1.types.ResultSet]): - One [ResultSet][google.spanner.v1.ResultSet] for each - statement in the request that ran successfully, in the same - order as the statements in the request. Each - [ResultSet][google.spanner.v1.ResultSet] does not contain - any rows. The - [ResultSetStats][google.spanner.v1.ResultSetStats] in each - [ResultSet][google.spanner.v1.ResultSet] contain the number - of rows modified by the statement. - - Only the first [ResultSet][google.spanner.v1.ResultSet] in - the response contains valid - [ResultSetMetadata][google.spanner.v1.ResultSetMetadata]. - status (google.rpc.status_pb2.Status): - If all DML statements are executed successfully, the status - is ``OK``. Otherwise, the error status of the first failed - statement. - """ - - result_sets: MutableSequence[result_set.ResultSet] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message=result_set.ResultSet, - ) - status: status_pb2.Status = proto.Field( - proto.MESSAGE, - number=2, - message=status_pb2.Status, - ) - - -class PartitionOptions(proto.Message): - r"""Options for a PartitionQueryRequest and - PartitionReadRequest. - - Attributes: - partition_size_bytes (int): - **Note:** This hint is currently ignored by PartitionQuery - and PartitionRead requests. - - The desired data size for each partition generated. The - default for this option is currently 1 GiB. This is only a - hint. The actual size of each partition may be smaller or - larger than this size request. - max_partitions (int): - **Note:** This hint is currently ignored by PartitionQuery - and PartitionRead requests. - - The desired maximum number of partitions to return. For - example, this may be set to the number of workers available. - The default for this option is currently 10,000. The maximum - value is currently 200,000. This is only a hint. The actual - number of partitions returned may be smaller or larger than - this maximum count request. - """ - - partition_size_bytes: int = proto.Field( - proto.INT64, - number=1, - ) - max_partitions: int = proto.Field( - proto.INT64, - number=2, - ) - - -class PartitionQueryRequest(proto.Message): - r"""The request for - [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] - - Attributes: - session (str): - Required. The session used to create the - partitions. - transaction (google.cloud.spanner_v1.types.TransactionSelector): - Read only snapshot transactions are - supported, read/write and single use - transactions are not. - sql (str): - Required. The query request to generate partitions for. The - request will fail if the query is not root partitionable. - The query plan of a root partitionable query has a single - distributed union operator. A distributed union operator - conceptually divides one or more tables into multiple - splits, remotely evaluates a subquery independently on each - split, and then unions all results. - - This must not contain DML commands, such as INSERT, UPDATE, - or DELETE. Use - [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] - with a PartitionedDml transaction for large, - partition-friendly DML operations. - params (google.protobuf.struct_pb2.Struct): - Parameter names and values that bind to placeholders in the - SQL string. - - A parameter placeholder consists of the ``@`` character - followed by the parameter name (for example, - ``@firstName``). Parameter names can contain letters, - numbers, and underscores. - - Parameters can appear anywhere that a literal value is - expected. The same parameter name can be used more than - once, for example: - - ``"WHERE id > @msg_id AND id < @msg_id + 100"`` - - It is an error to execute a SQL statement with unbound - parameters. - param_types (MutableMapping[str, google.cloud.spanner_v1.types.Type]): - It is not always possible for Cloud Spanner to infer the - right SQL type from a JSON value. For example, values of - type ``BYTES`` and values of type ``STRING`` both appear in - [params][google.spanner.v1.PartitionQueryRequest.params] as - JSON strings. - - In these cases, ``param_types`` can be used to specify the - exact SQL type for some or all of the SQL query parameters. - See the definition of [Type][google.spanner.v1.Type] for - more information about SQL types. - partition_options (google.cloud.spanner_v1.types.PartitionOptions): - Additional options that affect how many - partitions are created. - """ - - session: str = proto.Field( - proto.STRING, - number=1, - ) - transaction: gs_transaction.TransactionSelector = proto.Field( - proto.MESSAGE, - number=2, - message=gs_transaction.TransactionSelector, - ) - sql: str = proto.Field( - proto.STRING, - number=3, - ) - params: struct_pb2.Struct = proto.Field( - proto.MESSAGE, - number=4, - message=struct_pb2.Struct, - ) - param_types: MutableMapping[str, gs_type.Type] = proto.MapField( - proto.STRING, - proto.MESSAGE, - number=5, - message=gs_type.Type, - ) - partition_options: 'PartitionOptions' = proto.Field( - proto.MESSAGE, - number=6, - message='PartitionOptions', - ) - - -class PartitionReadRequest(proto.Message): - r"""The request for - [PartitionRead][google.spanner.v1.Spanner.PartitionRead] - - Attributes: - session (str): - Required. The session used to create the - partitions. - transaction (google.cloud.spanner_v1.types.TransactionSelector): - Read only snapshot transactions are - supported, read/write and single use - transactions are not. - table (str): - Required. The name of the table in the - database to be read. - index (str): - If non-empty, the name of an index on - [table][google.spanner.v1.PartitionReadRequest.table]. This - index is used instead of the table primary key when - interpreting - [key_set][google.spanner.v1.PartitionReadRequest.key_set] - and sorting result rows. See - [key_set][google.spanner.v1.PartitionReadRequest.key_set] - for further information. - columns (MutableSequence[str]): - The columns of - [table][google.spanner.v1.PartitionReadRequest.table] to be - returned for each row matching this request. - key_set (google.cloud.spanner_v1.types.KeySet): - Required. ``key_set`` identifies the rows to be yielded. - ``key_set`` names the primary keys of the rows in - [table][google.spanner.v1.PartitionReadRequest.table] to be - yielded, unless - [index][google.spanner.v1.PartitionReadRequest.index] is - present. If - [index][google.spanner.v1.PartitionReadRequest.index] is - present, then - [key_set][google.spanner.v1.PartitionReadRequest.key_set] - instead names index keys in - [index][google.spanner.v1.PartitionReadRequest.index]. - - It is not an error for the ``key_set`` to name rows that do - not exist in the database. Read yields nothing for - nonexistent rows. - partition_options (google.cloud.spanner_v1.types.PartitionOptions): - Additional options that affect how many - partitions are created. - """ - - session: str = proto.Field( - proto.STRING, - number=1, - ) - transaction: gs_transaction.TransactionSelector = proto.Field( - proto.MESSAGE, - number=2, - message=gs_transaction.TransactionSelector, - ) - table: str = proto.Field( - proto.STRING, - number=3, - ) - index: str = proto.Field( - proto.STRING, - number=4, - ) - columns: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=5, - ) - key_set: keys.KeySet = proto.Field( - proto.MESSAGE, - number=6, - message=keys.KeySet, - ) - partition_options: 'PartitionOptions' = proto.Field( - proto.MESSAGE, - number=9, - message='PartitionOptions', - ) - - -class Partition(proto.Message): - r"""Information returned for each partition returned in a - PartitionResponse. - - Attributes: - partition_token (bytes): - This token can be passed to Read, - StreamingRead, ExecuteSql, or - ExecuteStreamingSql requests to restrict the - results to those identified by this partition - token. - """ - - partition_token: bytes = proto.Field( - proto.BYTES, - number=1, - ) - - -class PartitionResponse(proto.Message): - r"""The response for - [PartitionQuery][google.spanner.v1.Spanner.PartitionQuery] or - [PartitionRead][google.spanner.v1.Spanner.PartitionRead] - - Attributes: - partitions (MutableSequence[google.cloud.spanner_v1.types.Partition]): - Partitions created by this request. - transaction (google.cloud.spanner_v1.types.Transaction): - Transaction created by this request. - """ - - partitions: MutableSequence['Partition'] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Partition', - ) - transaction: gs_transaction.Transaction = proto.Field( - proto.MESSAGE, - number=2, - message=gs_transaction.Transaction, - ) - - -class ReadRequest(proto.Message): - r"""The request for [Read][google.spanner.v1.Spanner.Read] and - [StreamingRead][google.spanner.v1.Spanner.StreamingRead]. - - Attributes: - session (str): - Required. The session in which the read - should be performed. - transaction (google.cloud.spanner_v1.types.TransactionSelector): - The transaction to use. If none is provided, - the default is a temporary read-only transaction - with strong concurrency. - table (str): - Required. The name of the table in the - database to be read. - index (str): - If non-empty, the name of an index on - [table][google.spanner.v1.ReadRequest.table]. This index is - used instead of the table primary key when interpreting - [key_set][google.spanner.v1.ReadRequest.key_set] and sorting - result rows. See - [key_set][google.spanner.v1.ReadRequest.key_set] for further - information. - columns (MutableSequence[str]): - Required. The columns of - [table][google.spanner.v1.ReadRequest.table] to be returned - for each row matching this request. - key_set (google.cloud.spanner_v1.types.KeySet): - Required. ``key_set`` identifies the rows to be yielded. - ``key_set`` names the primary keys of the rows in - [table][google.spanner.v1.ReadRequest.table] to be yielded, - unless [index][google.spanner.v1.ReadRequest.index] is - present. If [index][google.spanner.v1.ReadRequest.index] is - present, then - [key_set][google.spanner.v1.ReadRequest.key_set] instead - names index keys in - [index][google.spanner.v1.ReadRequest.index]. - - If the - [partition_token][google.spanner.v1.ReadRequest.partition_token] - field is empty, rows are yielded in table primary key order - (if [index][google.spanner.v1.ReadRequest.index] is empty) - or index key order (if - [index][google.spanner.v1.ReadRequest.index] is non-empty). - If the - [partition_token][google.spanner.v1.ReadRequest.partition_token] - field is not empty, rows will be yielded in an unspecified - order. - - It is not an error for the ``key_set`` to name rows that do - not exist in the database. Read yields nothing for - nonexistent rows. - limit (int): - If greater than zero, only the first ``limit`` rows are - yielded. If ``limit`` is zero, the default is no limit. A - limit cannot be specified if ``partition_token`` is set. - resume_token (bytes): - If this request is resuming a previously interrupted read, - ``resume_token`` should be copied from the last - [PartialResultSet][google.spanner.v1.PartialResultSet] - yielded before the interruption. Doing this enables the new - read to resume where the last read left off. The rest of the - request parameters must exactly match the request that - yielded this token. - partition_token (bytes): - If present, results will be restricted to the specified - partition previously created using PartitionRead(). There - must be an exact match for the values of fields common to - this message and the PartitionReadRequest message used to - create this partition_token. - request_options (google.cloud.spanner_v1.types.RequestOptions): - Common options for this request. - data_boost_enabled (bool): - If this is for a partitioned read and this field is set to - ``true``, the request will be executed via Spanner - independent compute resources. - - If the field is set to ``true`` but the request does not set - ``partition_token``, the API will return an - ``INVALID_ARGUMENT`` error. - """ - - session: str = proto.Field( - proto.STRING, - number=1, - ) - transaction: gs_transaction.TransactionSelector = proto.Field( - proto.MESSAGE, - number=2, - message=gs_transaction.TransactionSelector, - ) - table: str = proto.Field( - proto.STRING, - number=3, - ) - index: str = proto.Field( - proto.STRING, - number=4, - ) - columns: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=5, - ) - key_set: keys.KeySet = proto.Field( - proto.MESSAGE, - number=6, - message=keys.KeySet, - ) - limit: int = proto.Field( - proto.INT64, - number=8, - ) - resume_token: bytes = proto.Field( - proto.BYTES, - number=9, - ) - partition_token: bytes = proto.Field( - proto.BYTES, - number=10, - ) - request_options: 'RequestOptions' = proto.Field( - proto.MESSAGE, - number=11, - message='RequestOptions', - ) - data_boost_enabled: bool = proto.Field( - proto.BOOL, - number=15, - ) - - -class BeginTransactionRequest(proto.Message): - r"""The request for - [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction]. - - Attributes: - session (str): - Required. The session in which the - transaction runs. - options (google.cloud.spanner_v1.types.TransactionOptions): - Required. Options for the new transaction. - request_options (google.cloud.spanner_v1.types.RequestOptions): - Common options for this request. Priority is ignored for - this request. Setting the priority in this request_options - struct will not do anything. To set the priority for a - transaction, set it on the reads and writes that are part of - this transaction instead. - """ - - session: str = proto.Field( - proto.STRING, - number=1, - ) - options: gs_transaction.TransactionOptions = proto.Field( - proto.MESSAGE, - number=2, - message=gs_transaction.TransactionOptions, - ) - request_options: 'RequestOptions' = proto.Field( - proto.MESSAGE, - number=3, - message='RequestOptions', - ) - - -class CommitRequest(proto.Message): - r"""The request for [Commit][google.spanner.v1.Spanner.Commit]. - - This message has `oneof`_ fields (mutually exclusive fields). - For each oneof, at most one member field can be set at the same time. - Setting any member of the oneof automatically clears all other - members. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - session (str): - Required. The session in which the - transaction to be committed is running. - transaction_id (bytes): - Commit a previously-started transaction. - - This field is a member of `oneof`_ ``transaction``. - single_use_transaction (google.cloud.spanner_v1.types.TransactionOptions): - Execute mutations in a temporary transaction. Note that - unlike commit of a previously-started transaction, commit - with a temporary transaction is non-idempotent. That is, if - the ``CommitRequest`` is sent to Cloud Spanner more than - once (for instance, due to retries in the application, or in - the transport library), it is possible that the mutations - are executed more than once. If this is undesirable, use - [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction] - and [Commit][google.spanner.v1.Spanner.Commit] instead. - - This field is a member of `oneof`_ ``transaction``. - mutations (MutableSequence[google.cloud.spanner_v1.types.Mutation]): - The mutations to be executed when this - transaction commits. All mutations are applied - atomically, in the order they appear in this - list. - return_commit_stats (bool): - If ``true``, then statistics related to the transaction will - be included in the - [CommitResponse][google.spanner.v1.CommitResponse.commit_stats]. - Default value is ``false``. - request_options (google.cloud.spanner_v1.types.RequestOptions): - Common options for this request. - """ - - session: str = proto.Field( - proto.STRING, - number=1, - ) - transaction_id: bytes = proto.Field( - proto.BYTES, - number=2, - oneof='transaction', - ) - single_use_transaction: gs_transaction.TransactionOptions = proto.Field( - proto.MESSAGE, - number=3, - oneof='transaction', - message=gs_transaction.TransactionOptions, - ) - mutations: MutableSequence[mutation.Mutation] = proto.RepeatedField( - proto.MESSAGE, - number=4, - message=mutation.Mutation, - ) - return_commit_stats: bool = proto.Field( - proto.BOOL, - number=5, - ) - request_options: 'RequestOptions' = proto.Field( - proto.MESSAGE, - number=6, - message='RequestOptions', - ) - - -class RollbackRequest(proto.Message): - r"""The request for [Rollback][google.spanner.v1.Spanner.Rollback]. - - Attributes: - session (str): - Required. The session in which the - transaction to roll back is running. - transaction_id (bytes): - Required. The transaction to roll back. - """ - - session: str = proto.Field( - proto.STRING, - number=1, - ) - transaction_id: bytes = proto.Field( - proto.BYTES, - number=2, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/transaction.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/transaction.py deleted file mode 100644 index d66d95a04d..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/transaction.py +++ /dev/null @@ -1,673 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.protobuf import duration_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.spanner.v1', - manifest={ - 'TransactionOptions', - 'Transaction', - 'TransactionSelector', - }, -) - - -class TransactionOptions(proto.Message): - r"""Transactions: - - Each session can have at most one active transaction at a time (note - that standalone reads and queries use a transaction internally and - do count towards the one transaction limit). After the active - transaction is completed, the session can immediately be re-used for - the next transaction. It is not necessary to create a new session - for each transaction. - - Transaction modes: - - Cloud Spanner supports three transaction modes: - - 1. Locking read-write. This type of transaction is the only way to - write data into Cloud Spanner. These transactions rely on - pessimistic locking and, if necessary, two-phase commit. Locking - read-write transactions may abort, requiring the application to - retry. - - 2. Snapshot read-only. Snapshot read-only transactions provide - guaranteed consistency across several reads, but do not allow - writes. Snapshot read-only transactions can be configured to read - at timestamps in the past, or configured to perform a strong read - (where Spanner will select a timestamp such that the read is - guaranteed to see the effects of all transactions that have - committed before the start of the read). Snapshot read-only - transactions do not need to be committed. - - Queries on change streams must be performed with the snapshot - read-only transaction mode, specifying a strong read. Please see - [TransactionOptions.ReadOnly.strong][google.spanner.v1.TransactionOptions.ReadOnly.strong] - for more details. - - 3. Partitioned DML. This type of transaction is used to execute a - single Partitioned DML statement. Partitioned DML partitions the - key space and runs the DML statement over each partition in - parallel using separate, internal transactions that commit - independently. Partitioned DML transactions do not need to be - committed. - - For transactions that only read, snapshot read-only transactions - provide simpler semantics and are almost always faster. In - particular, read-only transactions do not take locks, so they do not - conflict with read-write transactions. As a consequence of not - taking locks, they also do not abort, so retry loops are not needed. - - Transactions may only read-write data in a single database. They - may, however, read-write data in different tables within that - database. - - Locking read-write transactions: - - Locking transactions may be used to atomically read-modify-write - data anywhere in a database. This type of transaction is externally - consistent. - - Clients should attempt to minimize the amount of time a transaction - is active. Faster transactions commit with higher probability and - cause less contention. Cloud Spanner attempts to keep read locks - active as long as the transaction continues to do reads, and the - transaction has not been terminated by - [Commit][google.spanner.v1.Spanner.Commit] or - [Rollback][google.spanner.v1.Spanner.Rollback]. Long periods of - inactivity at the client may cause Cloud Spanner to release a - transaction's locks and abort it. - - Conceptually, a read-write transaction consists of zero or more - reads or SQL statements followed by - [Commit][google.spanner.v1.Spanner.Commit]. At any time before - [Commit][google.spanner.v1.Spanner.Commit], the client can send a - [Rollback][google.spanner.v1.Spanner.Rollback] request to abort the - transaction. - - Semantics: - - Cloud Spanner can commit the transaction if all read locks it - acquired are still valid at commit time, and it is able to acquire - write locks for all writes. Cloud Spanner can abort the transaction - for any reason. If a commit attempt returns ``ABORTED``, Cloud - Spanner guarantees that the transaction has not modified any user - data in Cloud Spanner. - - Unless the transaction commits, Cloud Spanner makes no guarantees - about how long the transaction's locks were held for. It is an error - to use Cloud Spanner locks for any sort of mutual exclusion other - than between Cloud Spanner transactions themselves. - - Retrying aborted transactions: - - When a transaction aborts, the application can choose to retry the - whole transaction again. To maximize the chances of successfully - committing the retry, the client should execute the retry in the - same session as the original attempt. The original session's lock - priority increases with each consecutive abort, meaning that each - attempt has a slightly better chance of success than the previous. - - Under some circumstances (for example, many transactions attempting - to modify the same row(s)), a transaction can abort many times in a - short period before successfully committing. Thus, it is not a good - idea to cap the number of retries a transaction can attempt; - instead, it is better to limit the total amount of time spent - retrying. - - Idle transactions: - - A transaction is considered idle if it has no outstanding reads or - SQL queries and has not started a read or SQL query within the last - 10 seconds. Idle transactions can be aborted by Cloud Spanner so - that they don't hold on to locks indefinitely. If an idle - transaction is aborted, the commit will fail with error ``ABORTED``. - - If this behavior is undesirable, periodically executing a simple SQL - query in the transaction (for example, ``SELECT 1``) prevents the - transaction from becoming idle. - - Snapshot read-only transactions: - - Snapshot read-only transactions provides a simpler method than - locking read-write transactions for doing several consistent reads. - However, this type of transaction does not support writes. - - Snapshot transactions do not take locks. Instead, they work by - choosing a Cloud Spanner timestamp, then executing all reads at that - timestamp. Since they do not acquire locks, they do not block - concurrent read-write transactions. - - Unlike locking read-write transactions, snapshot read-only - transactions never abort. They can fail if the chosen read timestamp - is garbage collected; however, the default garbage collection policy - is generous enough that most applications do not need to worry about - this in practice. - - Snapshot read-only transactions do not need to call - [Commit][google.spanner.v1.Spanner.Commit] or - [Rollback][google.spanner.v1.Spanner.Rollback] (and in fact are not - permitted to do so). - - To execute a snapshot transaction, the client specifies a timestamp - bound, which tells Cloud Spanner how to choose a read timestamp. - - The types of timestamp bound are: - - - Strong (the default). - - Bounded staleness. - - Exact staleness. - - If the Cloud Spanner database to be read is geographically - distributed, stale read-only transactions can execute more quickly - than strong or read-write transactions, because they are able to - execute far from the leader replica. - - Each type of timestamp bound is discussed in detail below. - - Strong: Strong reads are guaranteed to see the effects of all - transactions that have committed before the start of the read. - Furthermore, all rows yielded by a single read are consistent with - each other -- if any part of the read observes a transaction, all - parts of the read see the transaction. - - Strong reads are not repeatable: two consecutive strong read-only - transactions might return inconsistent results if there are - concurrent writes. If consistency across reads is required, the - reads should be executed within a transaction or at an exact read - timestamp. - - Queries on change streams (see below for more details) must also - specify the strong read timestamp bound. - - See - [TransactionOptions.ReadOnly.strong][google.spanner.v1.TransactionOptions.ReadOnly.strong]. - - Exact staleness: - - These timestamp bounds execute reads at a user-specified timestamp. - Reads at a timestamp are guaranteed to see a consistent prefix of - the global transaction history: they observe modifications done by - all transactions with a commit timestamp less than or equal to the - read timestamp, and observe none of the modifications done by - transactions with a larger commit timestamp. They will block until - all conflicting transactions that may be assigned commit timestamps - <= the read timestamp have finished. - - The timestamp can either be expressed as an absolute Cloud Spanner - commit timestamp or a staleness relative to the current time. - - These modes do not require a "negotiation phase" to pick a - timestamp. As a result, they execute slightly faster than the - equivalent boundedly stale concurrency modes. On the other hand, - boundedly stale reads usually return fresher results. - - See - [TransactionOptions.ReadOnly.read_timestamp][google.spanner.v1.TransactionOptions.ReadOnly.read_timestamp] - and - [TransactionOptions.ReadOnly.exact_staleness][google.spanner.v1.TransactionOptions.ReadOnly.exact_staleness]. - - Bounded staleness: - - Bounded staleness modes allow Cloud Spanner to pick the read - timestamp, subject to a user-provided staleness bound. Cloud Spanner - chooses the newest timestamp within the staleness bound that allows - execution of the reads at the closest available replica without - blocking. - - All rows yielded are consistent with each other -- if any part of - the read observes a transaction, all parts of the read see the - transaction. Boundedly stale reads are not repeatable: two stale - reads, even if they use the same staleness bound, can execute at - different timestamps and thus return inconsistent results. - - Boundedly stale reads execute in two phases: the first phase - negotiates a timestamp among all replicas needed to serve the read. - In the second phase, reads are executed at the negotiated timestamp. - - As a result of the two phase execution, bounded staleness reads are - usually a little slower than comparable exact staleness reads. - However, they are typically able to return fresher results, and are - more likely to execute at the closest replica. - - Because the timestamp negotiation requires up-front knowledge of - which rows will be read, it can only be used with single-use - read-only transactions. - - See - [TransactionOptions.ReadOnly.max_staleness][google.spanner.v1.TransactionOptions.ReadOnly.max_staleness] - and - [TransactionOptions.ReadOnly.min_read_timestamp][google.spanner.v1.TransactionOptions.ReadOnly.min_read_timestamp]. - - Old read timestamps and garbage collection: - - Cloud Spanner continuously garbage collects deleted and overwritten - data in the background to reclaim storage space. This process is - known as "version GC". By default, version GC reclaims versions - after they are one hour old. Because of this, Cloud Spanner cannot - perform reads at read timestamps more than one hour in the past. - This restriction also applies to in-progress reads and/or SQL - queries whose timestamp become too old while executing. Reads and - SQL queries with too-old read timestamps fail with the error - ``FAILED_PRECONDITION``. - - You can configure and extend the ``VERSION_RETENTION_PERIOD`` of a - database up to a period as long as one week, which allows Cloud - Spanner to perform reads up to one week in the past. - - Querying change Streams: - - A Change Stream is a schema object that can be configured to watch - data changes on the entire database, a set of tables, or a set of - columns in a database. - - When a change stream is created, Spanner automatically defines a - corresponding SQL Table-Valued Function (TVF) that can be used to - query the change records in the associated change stream using the - ExecuteStreamingSql API. The name of the TVF for a change stream is - generated from the name of the change stream: - READ_. - - All queries on change stream TVFs must be executed using the - ExecuteStreamingSql API with a single-use read-only transaction with - a strong read-only timestamp_bound. The change stream TVF allows - users to specify the start_timestamp and end_timestamp for the time - range of interest. All change records within the retention period is - accessible using the strong read-only timestamp_bound. All other - TransactionOptions are invalid for change stream queries. - - In addition, if TransactionOptions.read_only.return_read_timestamp - is set to true, a special value of 2^63 - 2 will be returned in the - [Transaction][google.spanner.v1.Transaction] message that describes - the transaction, instead of a valid read timestamp. This special - value should be discarded and not used for any subsequent queries. - - Please see https://cloud.google.com/spanner/docs/change-streams for - more details on how to query the change stream TVFs. - - Partitioned DML transactions: - - Partitioned DML transactions are used to execute DML statements with - a different execution strategy that provides different, and often - better, scalability properties for large, table-wide operations than - DML in a ReadWrite transaction. Smaller scoped statements, such as - an OLTP workload, should prefer using ReadWrite transactions. - - Partitioned DML partitions the keyspace and runs the DML statement - on each partition in separate, internal transactions. These - transactions commit automatically when complete, and run - independently from one another. - - To reduce lock contention, this execution strategy only acquires - read locks on rows that match the WHERE clause of the statement. - Additionally, the smaller per-partition transactions hold locks for - less time. - - That said, Partitioned DML is not a drop-in replacement for standard - DML used in ReadWrite transactions. - - - The DML statement must be fully-partitionable. Specifically, the - statement must be expressible as the union of many statements - which each access only a single row of the table. - - - The statement is not applied atomically to all rows of the table. - Rather, the statement is applied atomically to partitions of the - table, in independent transactions. Secondary index rows are - updated atomically with the base table rows. - - - Partitioned DML does not guarantee exactly-once execution - semantics against a partition. The statement will be applied at - least once to each partition. It is strongly recommended that the - DML statement should be idempotent to avoid unexpected results. - For instance, it is potentially dangerous to run a statement such - as ``UPDATE table SET column = column + 1`` as it could be run - multiple times against some rows. - - - The partitions are committed automatically - there is no support - for Commit or Rollback. If the call returns an error, or if the - client issuing the ExecuteSql call dies, it is possible that some - rows had the statement executed on them successfully. It is also - possible that statement was never executed against other rows. - - - Partitioned DML transactions may only contain the execution of a - single DML statement via ExecuteSql or ExecuteStreamingSql. - - - If any error is encountered during the execution of the - partitioned DML operation (for instance, a UNIQUE INDEX - violation, division by zero, or a value that cannot be stored due - to schema constraints), then the operation is stopped at that - point and an error is returned. It is possible that at this - point, some partitions have been committed (or even committed - multiple times), and other partitions have not been run at all. - - Given the above, Partitioned DML is good fit for large, - database-wide, operations that are idempotent, such as deleting old - rows from a very large table. - - This message has `oneof`_ fields (mutually exclusive fields). - For each oneof, at most one member field can be set at the same time. - Setting any member of the oneof automatically clears all other - members. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - read_write (google.cloud.spanner_v1.types.TransactionOptions.ReadWrite): - Transaction may write. - - Authorization to begin a read-write transaction requires - ``spanner.databases.beginOrRollbackReadWriteTransaction`` - permission on the ``session`` resource. - - This field is a member of `oneof`_ ``mode``. - partitioned_dml (google.cloud.spanner_v1.types.TransactionOptions.PartitionedDml): - Partitioned DML transaction. - - Authorization to begin a Partitioned DML transaction - requires - ``spanner.databases.beginPartitionedDmlTransaction`` - permission on the ``session`` resource. - - This field is a member of `oneof`_ ``mode``. - read_only (google.cloud.spanner_v1.types.TransactionOptions.ReadOnly): - Transaction will not write. - - Authorization to begin a read-only transaction requires - ``spanner.databases.beginReadOnlyTransaction`` permission on - the ``session`` resource. - - This field is a member of `oneof`_ ``mode``. - """ - - class ReadWrite(proto.Message): - r"""Message type to initiate a read-write transaction. Currently - this transaction type has no options. - - Attributes: - read_lock_mode (google.cloud.spanner_v1.types.TransactionOptions.ReadWrite.ReadLockMode): - Read lock mode for the transaction. - """ - class ReadLockMode(proto.Enum): - r"""``ReadLockMode`` is used to set the read lock mode for read-write - transactions. - - Values: - READ_LOCK_MODE_UNSPECIFIED (0): - Default value. - If the value is not specified, the pessimistic - read lock is used. - PESSIMISTIC (1): - Pessimistic lock mode. - Read locks are acquired immediately on read. - OPTIMISTIC (2): - Optimistic lock mode. - Locks for reads within the transaction are not - acquired on read. Instead the locks are acquired - on a commit to validate that read/queried data - has not changed since the transaction started. - """ - READ_LOCK_MODE_UNSPECIFIED = 0 - PESSIMISTIC = 1 - OPTIMISTIC = 2 - - read_lock_mode: 'TransactionOptions.ReadWrite.ReadLockMode' = proto.Field( - proto.ENUM, - number=1, - enum='TransactionOptions.ReadWrite.ReadLockMode', - ) - - class PartitionedDml(proto.Message): - r"""Message type to initiate a Partitioned DML transaction. - """ - - class ReadOnly(proto.Message): - r"""Message type to initiate a read-only transaction. - - This message has `oneof`_ fields (mutually exclusive fields). - For each oneof, at most one member field can be set at the same time. - Setting any member of the oneof automatically clears all other - members. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - strong (bool): - Read at a timestamp where all previously - committed transactions are visible. - - This field is a member of `oneof`_ ``timestamp_bound``. - min_read_timestamp (google.protobuf.timestamp_pb2.Timestamp): - Executes all reads at a timestamp >= ``min_read_timestamp``. - - This is useful for requesting fresher data than some - previous read, or data that is fresh enough to observe the - effects of some previously committed transaction whose - timestamp is known. - - Note that this option can only be used in single-use - transactions. - - A timestamp in RFC3339 UTC "Zulu" format, accurate to - nanoseconds. Example: ``"2014-10-02T15:01:23.045123456Z"``. - - This field is a member of `oneof`_ ``timestamp_bound``. - max_staleness (google.protobuf.duration_pb2.Duration): - Read data at a timestamp >= ``NOW - max_staleness`` seconds. - Guarantees that all writes that have committed more than the - specified number of seconds ago are visible. Because Cloud - Spanner chooses the exact timestamp, this mode works even if - the client's local clock is substantially skewed from Cloud - Spanner commit timestamps. - - Useful for reading the freshest data available at a nearby - replica, while bounding the possible staleness if the local - replica has fallen behind. - - Note that this option can only be used in single-use - transactions. - - This field is a member of `oneof`_ ``timestamp_bound``. - read_timestamp (google.protobuf.timestamp_pb2.Timestamp): - Executes all reads at the given timestamp. Unlike other - modes, reads at a specific timestamp are repeatable; the - same read at the same timestamp always returns the same - data. If the timestamp is in the future, the read will block - until the specified timestamp, modulo the read's deadline. - - Useful for large scale consistent reads such as mapreduces, - or for coordinating many reads against a consistent snapshot - of the data. - - A timestamp in RFC3339 UTC "Zulu" format, accurate to - nanoseconds. Example: ``"2014-10-02T15:01:23.045123456Z"``. - - This field is a member of `oneof`_ ``timestamp_bound``. - exact_staleness (google.protobuf.duration_pb2.Duration): - Executes all reads at a timestamp that is - ``exact_staleness`` old. The timestamp is chosen soon after - the read is started. - - Guarantees that all writes that have committed more than the - specified number of seconds ago are visible. Because Cloud - Spanner chooses the exact timestamp, this mode works even if - the client's local clock is substantially skewed from Cloud - Spanner commit timestamps. - - Useful for reading at nearby replicas without the - distributed timestamp negotiation overhead of - ``max_staleness``. - - This field is a member of `oneof`_ ``timestamp_bound``. - return_read_timestamp (bool): - If true, the Cloud Spanner-selected read timestamp is - included in the [Transaction][google.spanner.v1.Transaction] - message that describes the transaction. - """ - - strong: bool = proto.Field( - proto.BOOL, - number=1, - oneof='timestamp_bound', - ) - min_read_timestamp: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=2, - oneof='timestamp_bound', - message=timestamp_pb2.Timestamp, - ) - max_staleness: duration_pb2.Duration = proto.Field( - proto.MESSAGE, - number=3, - oneof='timestamp_bound', - message=duration_pb2.Duration, - ) - read_timestamp: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=4, - oneof='timestamp_bound', - message=timestamp_pb2.Timestamp, - ) - exact_staleness: duration_pb2.Duration = proto.Field( - proto.MESSAGE, - number=5, - oneof='timestamp_bound', - message=duration_pb2.Duration, - ) - return_read_timestamp: bool = proto.Field( - proto.BOOL, - number=6, - ) - - read_write: ReadWrite = proto.Field( - proto.MESSAGE, - number=1, - oneof='mode', - message=ReadWrite, - ) - partitioned_dml: PartitionedDml = proto.Field( - proto.MESSAGE, - number=3, - oneof='mode', - message=PartitionedDml, - ) - read_only: ReadOnly = proto.Field( - proto.MESSAGE, - number=2, - oneof='mode', - message=ReadOnly, - ) - - -class Transaction(proto.Message): - r"""A transaction. - - Attributes: - id (bytes): - ``id`` may be used to identify the transaction in subsequent - [Read][google.spanner.v1.Spanner.Read], - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], - [Commit][google.spanner.v1.Spanner.Commit], or - [Rollback][google.spanner.v1.Spanner.Rollback] calls. - - Single-use read-only transactions do not have IDs, because - single-use transactions do not support multiple requests. - read_timestamp (google.protobuf.timestamp_pb2.Timestamp): - For snapshot read-only transactions, the read timestamp - chosen for the transaction. Not returned by default: see - [TransactionOptions.ReadOnly.return_read_timestamp][google.spanner.v1.TransactionOptions.ReadOnly.return_read_timestamp]. - - A timestamp in RFC3339 UTC "Zulu" format, accurate to - nanoseconds. Example: ``"2014-10-02T15:01:23.045123456Z"``. - """ - - id: bytes = proto.Field( - proto.BYTES, - number=1, - ) - read_timestamp: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=2, - message=timestamp_pb2.Timestamp, - ) - - -class TransactionSelector(proto.Message): - r"""This message is used to select the transaction in which a - [Read][google.spanner.v1.Spanner.Read] or - [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] call runs. - - See [TransactionOptions][google.spanner.v1.TransactionOptions] for - more information about transactions. - - This message has `oneof`_ fields (mutually exclusive fields). - For each oneof, at most one member field can be set at the same time. - Setting any member of the oneof automatically clears all other - members. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - single_use (google.cloud.spanner_v1.types.TransactionOptions): - Execute the read or SQL query in a temporary - transaction. This is the most efficient way to - execute a transaction that consists of a single - SQL query. - - This field is a member of `oneof`_ ``selector``. - id (bytes): - Execute the read or SQL query in a - previously-started transaction. - - This field is a member of `oneof`_ ``selector``. - begin (google.cloud.spanner_v1.types.TransactionOptions): - Begin a new transaction and execute this read or SQL query - in it. The transaction ID of the new transaction is returned - in - [ResultSetMetadata.transaction][google.spanner.v1.ResultSetMetadata.transaction], - which is a [Transaction][google.spanner.v1.Transaction]. - - This field is a member of `oneof`_ ``selector``. - """ - - single_use: 'TransactionOptions' = proto.Field( - proto.MESSAGE, - number=1, - oneof='selector', - message='TransactionOptions', - ) - id: bytes = proto.Field( - proto.BYTES, - number=2, - oneof='selector', - ) - begin: 'TransactionOptions' = proto.Field( - proto.MESSAGE, - number=3, - oneof='selector', - message='TransactionOptions', - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/type.py b/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/type.py deleted file mode 100644 index 6b49415ec6..0000000000 --- a/owl-bot-staging/spanner/v1/google/cloud/spanner_v1/types/type.py +++ /dev/null @@ -1,248 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - - -__protobuf__ = proto.module( - package='google.spanner.v1', - manifest={ - 'TypeCode', - 'TypeAnnotationCode', - 'Type', - 'StructType', - }, -) - - -class TypeCode(proto.Enum): - r"""``TypeCode`` is used as part of [Type][google.spanner.v1.Type] to - indicate the type of a Cloud Spanner value. - - Each legal value of a type can be encoded to or decoded from a JSON - value, using the encodings described below. All Cloud Spanner values - can be ``null``, regardless of type; ``null``\ s are always encoded - as a JSON ``null``. - - Values: - TYPE_CODE_UNSPECIFIED (0): - Not specified. - BOOL (1): - Encoded as JSON ``true`` or ``false``. - INT64 (2): - Encoded as ``string``, in decimal format. - FLOAT64 (3): - Encoded as ``number``, or the strings ``"NaN"``, - ``"Infinity"``, or ``"-Infinity"``. - TIMESTAMP (4): - Encoded as ``string`` in RFC 3339 timestamp format. The time - zone must be present, and must be ``"Z"``. - - If the schema has the column option - ``allow_commit_timestamp=true``, the placeholder string - ``"spanner.commit_timestamp()"`` can be used to instruct the - system to insert the commit timestamp associated with the - transaction commit. - DATE (5): - Encoded as ``string`` in RFC 3339 date format. - STRING (6): - Encoded as ``string``. - BYTES (7): - Encoded as a base64-encoded ``string``, as described in RFC - 4648, section 4. - ARRAY (8): - Encoded as ``list``, where the list elements are represented - according to - [array_element_type][google.spanner.v1.Type.array_element_type]. - STRUCT (9): - Encoded as ``list``, where list element ``i`` is represented - according to - [struct_type.fields[i]][google.spanner.v1.StructType.fields]. - NUMERIC (10): - Encoded as ``string``, in decimal format or scientific - notation format. Decimal format: \ ``[+-]Digits[.[Digits]]`` - or \ ``[+-][Digits].Digits`` - - Scientific notation: - \ ``[+-]Digits[.[Digits]][ExponentIndicator[+-]Digits]`` or - \ ``[+-][Digits].Digits[ExponentIndicator[+-]Digits]`` - (ExponentIndicator is ``"e"`` or ``"E"``) - JSON (11): - Encoded as a JSON-formatted ``string`` as described in RFC - 7159. The following rules are applied when parsing JSON - input: - - - Whitespace characters are not preserved. - - If a JSON object has duplicate keys, only the first key - is preserved. - - Members of a JSON object are not guaranteed to have their - order preserved. - - JSON array elements will have their order preserved. - """ - TYPE_CODE_UNSPECIFIED = 0 - BOOL = 1 - INT64 = 2 - FLOAT64 = 3 - TIMESTAMP = 4 - DATE = 5 - STRING = 6 - BYTES = 7 - ARRAY = 8 - STRUCT = 9 - NUMERIC = 10 - JSON = 11 - - -class TypeAnnotationCode(proto.Enum): - r"""``TypeAnnotationCode`` is used as a part of - [Type][google.spanner.v1.Type] to disambiguate SQL types that should - be used for a given Cloud Spanner value. Disambiguation is needed - because the same Cloud Spanner type can be mapped to different SQL - types depending on SQL dialect. TypeAnnotationCode doesn't affect - the way value is serialized. - - Values: - TYPE_ANNOTATION_CODE_UNSPECIFIED (0): - Not specified. - PG_NUMERIC (2): - PostgreSQL compatible NUMERIC type. This annotation needs to - be applied to [Type][google.spanner.v1.Type] instances - having [NUMERIC][google.spanner.v1.TypeCode.NUMERIC] type - code to specify that values of this type should be treated - as PostgreSQL NUMERIC values. Currently this annotation is - always needed for - [NUMERIC][google.spanner.v1.TypeCode.NUMERIC] when a client - interacts with PostgreSQL-enabled Spanner databases. - PG_JSONB (3): - PostgreSQL compatible JSONB type. This annotation needs to - be applied to [Type][google.spanner.v1.Type] instances - having [JSON][google.spanner.v1.TypeCode.JSON] type code to - specify that values of this type should be treated as - PostgreSQL JSONB values. Currently this annotation is always - needed for [JSON][google.spanner.v1.TypeCode.JSON] when a - client interacts with PostgreSQL-enabled Spanner databases. - """ - TYPE_ANNOTATION_CODE_UNSPECIFIED = 0 - PG_NUMERIC = 2 - PG_JSONB = 3 - - -class Type(proto.Message): - r"""``Type`` indicates the type of a Cloud Spanner value, as might be - stored in a table cell or returned from an SQL query. - - Attributes: - code (google.cloud.spanner_v1.types.TypeCode): - Required. The [TypeCode][google.spanner.v1.TypeCode] for - this type. - array_element_type (google.cloud.spanner_v1.types.Type): - If [code][google.spanner.v1.Type.code] == - [ARRAY][google.spanner.v1.TypeCode.ARRAY], then - ``array_element_type`` is the type of the array elements. - struct_type (google.cloud.spanner_v1.types.StructType): - If [code][google.spanner.v1.Type.code] == - [STRUCT][google.spanner.v1.TypeCode.STRUCT], then - ``struct_type`` provides type information for the struct's - fields. - type_annotation (google.cloud.spanner_v1.types.TypeAnnotationCode): - The - [TypeAnnotationCode][google.spanner.v1.TypeAnnotationCode] - that disambiguates SQL type that Spanner will use to - represent values of this type during query processing. This - is necessary for some type codes because a single - [TypeCode][google.spanner.v1.TypeCode] can be mapped to - different SQL types depending on the SQL dialect. - [type_annotation][google.spanner.v1.Type.type_annotation] - typically is not needed to process the content of a value - (it doesn't affect serialization) and clients can ignore it - on the read path. - """ - - code: 'TypeCode' = proto.Field( - proto.ENUM, - number=1, - enum='TypeCode', - ) - array_element_type: 'Type' = proto.Field( - proto.MESSAGE, - number=2, - message='Type', - ) - struct_type: 'StructType' = proto.Field( - proto.MESSAGE, - number=3, - message='StructType', - ) - type_annotation: 'TypeAnnotationCode' = proto.Field( - proto.ENUM, - number=4, - enum='TypeAnnotationCode', - ) - - -class StructType(proto.Message): - r"""``StructType`` defines the fields of a - [STRUCT][google.spanner.v1.TypeCode.STRUCT] type. - - Attributes: - fields (MutableSequence[google.cloud.spanner_v1.types.StructType.Field]): - The list of fields that make up this struct. Order is - significant, because values of this struct type are - represented as lists, where the order of field values - matches the order of fields in the - [StructType][google.spanner.v1.StructType]. In turn, the - order of fields matches the order of columns in a read - request, or the order of fields in the ``SELECT`` clause of - a query. - """ - - class Field(proto.Message): - r"""Message representing a single field of a struct. - - Attributes: - name (str): - The name of the field. For reads, this is the column name. - For SQL queries, it is the column alias (e.g., ``"Word"`` in - the query ``"SELECT 'hello' AS Word"``), or the column name - (e.g., ``"ColName"`` in the query - ``"SELECT ColName FROM Table"``). Some columns might have an - empty name (e.g., ``"SELECT UPPER(ColName)"``). Note that a - query result can contain multiple fields with the same name. - type_ (google.cloud.spanner_v1.types.Type): - The type of the field. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - type_: 'Type' = proto.Field( - proto.MESSAGE, - number=2, - message='Type', - ) - - fields: MutableSequence[Field] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message=Field, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner/v1/mypy.ini b/owl-bot-staging/spanner/v1/mypy.ini deleted file mode 100644 index 574c5aed39..0000000000 --- a/owl-bot-staging/spanner/v1/mypy.ini +++ /dev/null @@ -1,3 +0,0 @@ -[mypy] -python_version = 3.7 -namespace_packages = True diff --git a/owl-bot-staging/spanner/v1/noxfile.py b/owl-bot-staging/spanner/v1/noxfile.py deleted file mode 100644 index cdf1942502..0000000000 --- a/owl-bot-staging/spanner/v1/noxfile.py +++ /dev/null @@ -1,184 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -import pathlib -import shutil -import subprocess -import sys - - -import nox # type: ignore - -ALL_PYTHON = [ - "3.7", - "3.8", - "3.9", - "3.10", - "3.11", -] - -CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() - -LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" -PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8") - -BLACK_VERSION = "black==22.3.0" -BLACK_PATHS = ["docs", "google", "tests", "samples", "noxfile.py", "setup.py"] -DEFAULT_PYTHON_VERSION = "3.11" - -nox.sessions = [ - "unit", - "cover", - "mypy", - "check_lower_bounds" - # exclude update_lower_bounds from default - "docs", - "blacken", - "lint", - "lint_setup_py", -] - -@nox.session(python=ALL_PYTHON) -def unit(session): - """Run the unit test suite.""" - - session.install('coverage', 'pytest', 'pytest-cov', 'pytest-asyncio', 'asyncmock; python_version < "3.8"') - session.install('-e', '.') - - session.run( - 'py.test', - '--quiet', - '--cov=google/cloud/spanner_v1/', - '--cov=tests/', - '--cov-config=.coveragerc', - '--cov-report=term', - '--cov-report=html', - os.path.join('tests', 'unit', ''.join(session.posargs)) - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def cover(session): - """Run the final coverage report. - This outputs the coverage report aggregating coverage from the unit - test runs (not system test runs), and then erases coverage data. - """ - session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=100") - - session.run("coverage", "erase") - - -@nox.session(python=ALL_PYTHON) -def mypy(session): - """Run the type checker.""" - session.install( - 'mypy', - 'types-requests', - 'types-protobuf' - ) - session.install('.') - session.run( - 'mypy', - '--explicit-package-bases', - 'google', - ) - - -@nox.session -def update_lower_bounds(session): - """Update lower bounds in constraints.txt to match setup.py""" - session.install('google-cloud-testutils') - session.install('.') - - session.run( - 'lower-bound-checker', - 'update', - '--package-name', - PACKAGE_NAME, - '--constraints-file', - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - - -@nox.session -def check_lower_bounds(session): - """Check lower bounds in setup.py are reflected in constraints file""" - session.install('google-cloud-testutils') - session.install('.') - - session.run( - 'lower-bound-checker', - 'check', - '--package-name', - PACKAGE_NAME, - '--constraints-file', - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def docs(session): - """Build the docs for this library.""" - - session.install("-e", ".") - session.install("sphinx==4.0.1", "alabaster", "recommonmark") - - shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) - session.run( - "sphinx-build", - "-W", # warnings as errors - "-T", # show full traceback on exception - "-N", # no colors - "-b", - "html", - "-d", - os.path.join("docs", "_build", "doctrees", ""), - os.path.join("docs", ""), - os.path.join("docs", "_build", "html", ""), - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def lint(session): - """Run linters. - - Returns a failure if the linters find linting errors or sufficiently - serious code quality issues. - """ - session.install("flake8", BLACK_VERSION) - session.run( - "black", - "--check", - *BLACK_PATHS, - ) - session.run("flake8", "google", "tests", "samples") - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def blacken(session): - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - session.run( - "black", - *BLACK_PATHS, - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def lint_setup_py(session): - """Verify that setup.py is valid (including RST check).""" - session.install("docutils", "pygments") - session.run("python", "setup.py", "check", "--restructuredtext", "--strict") diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/snippet_metadata_google.spanner.v1.json b/owl-bot-staging/spanner/v1/samples/generated_samples/snippet_metadata_google.spanner.v1.json deleted file mode 100644 index a8e8be3ae3..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/snippet_metadata_google.spanner.v1.json +++ /dev/null @@ -1,2410 +0,0 @@ -{ - "clientLibrary": { - "apis": [ - { - "id": "google.spanner.v1", - "version": "v1" - } - ], - "language": "PYTHON", - "name": "google-cloud-spanner", - "version": "0.1.0" - }, - "snippets": [ - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.batch_create_sessions", - "method": { - "fullName": "google.spanner.v1.Spanner.BatchCreateSessions", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "BatchCreateSessions" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.BatchCreateSessionsRequest" - }, - { - "name": "database", - "type": "str" - }, - { - "name": "session_count", - "type": "int" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.BatchCreateSessionsResponse", - "shortName": "batch_create_sessions" - }, - "description": "Sample for BatchCreateSessions", - "file": "spanner_v1_generated_spanner_batch_create_sessions_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_BatchCreateSessions_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_batch_create_sessions_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.batch_create_sessions", - "method": { - "fullName": "google.spanner.v1.Spanner.BatchCreateSessions", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "BatchCreateSessions" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.BatchCreateSessionsRequest" - }, - { - "name": "database", - "type": "str" - }, - { - "name": "session_count", - "type": "int" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.BatchCreateSessionsResponse", - "shortName": "batch_create_sessions" - }, - "description": "Sample for BatchCreateSessions", - "file": "spanner_v1_generated_spanner_batch_create_sessions_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_BatchCreateSessions_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_batch_create_sessions_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.begin_transaction", - "method": { - "fullName": "google.spanner.v1.Spanner.BeginTransaction", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "BeginTransaction" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.BeginTransactionRequest" - }, - { - "name": "session", - "type": "str" - }, - { - "name": "options", - "type": "google.cloud.spanner_v1.types.TransactionOptions" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.Transaction", - "shortName": "begin_transaction" - }, - "description": "Sample for BeginTransaction", - "file": "spanner_v1_generated_spanner_begin_transaction_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_BeginTransaction_async", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_begin_transaction_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.begin_transaction", - "method": { - "fullName": "google.spanner.v1.Spanner.BeginTransaction", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "BeginTransaction" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.BeginTransactionRequest" - }, - { - "name": "session", - "type": "str" - }, - { - "name": "options", - "type": "google.cloud.spanner_v1.types.TransactionOptions" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.Transaction", - "shortName": "begin_transaction" - }, - "description": "Sample for BeginTransaction", - "file": "spanner_v1_generated_spanner_begin_transaction_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_BeginTransaction_sync", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_begin_transaction_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.commit", - "method": { - "fullName": "google.spanner.v1.Spanner.Commit", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "Commit" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.CommitRequest" - }, - { - "name": "session", - "type": "str" - }, - { - "name": "transaction_id", - "type": "bytes" - }, - { - "name": "mutations", - "type": "MutableSequence[google.cloud.spanner_v1.types.Mutation]" - }, - { - "name": "single_use_transaction", - "type": "google.cloud.spanner_v1.types.TransactionOptions" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.CommitResponse", - "shortName": "commit" - }, - "description": "Sample for Commit", - "file": "spanner_v1_generated_spanner_commit_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_Commit_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_commit_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.commit", - "method": { - "fullName": "google.spanner.v1.Spanner.Commit", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "Commit" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.CommitRequest" - }, - { - "name": "session", - "type": "str" - }, - { - "name": "transaction_id", - "type": "bytes" - }, - { - "name": "mutations", - "type": "MutableSequence[google.cloud.spanner_v1.types.Mutation]" - }, - { - "name": "single_use_transaction", - "type": "google.cloud.spanner_v1.types.TransactionOptions" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.CommitResponse", - "shortName": "commit" - }, - "description": "Sample for Commit", - "file": "spanner_v1_generated_spanner_commit_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_Commit_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_commit_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.create_session", - "method": { - "fullName": "google.spanner.v1.Spanner.CreateSession", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "CreateSession" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.CreateSessionRequest" - }, - { - "name": "database", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.Session", - "shortName": "create_session" - }, - "description": "Sample for CreateSession", - "file": "spanner_v1_generated_spanner_create_session_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_CreateSession_async", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_create_session_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.create_session", - "method": { - "fullName": "google.spanner.v1.Spanner.CreateSession", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "CreateSession" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.CreateSessionRequest" - }, - { - "name": "database", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.Session", - "shortName": "create_session" - }, - "description": "Sample for CreateSession", - "file": "spanner_v1_generated_spanner_create_session_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_CreateSession_sync", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_create_session_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.delete_session", - "method": { - "fullName": "google.spanner.v1.Spanner.DeleteSession", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "DeleteSession" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.DeleteSessionRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "shortName": "delete_session" - }, - "description": "Sample for DeleteSession", - "file": "spanner_v1_generated_spanner_delete_session_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_DeleteSession_async", - "segments": [ - { - "end": 49, - "start": 27, - "type": "FULL" - }, - { - "end": 49, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_delete_session_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.delete_session", - "method": { - "fullName": "google.spanner.v1.Spanner.DeleteSession", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "DeleteSession" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.DeleteSessionRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "shortName": "delete_session" - }, - "description": "Sample for DeleteSession", - "file": "spanner_v1_generated_spanner_delete_session_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_DeleteSession_sync", - "segments": [ - { - "end": 49, - "start": 27, - "type": "FULL" - }, - { - "end": 49, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_delete_session_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.execute_batch_dml", - "method": { - "fullName": "google.spanner.v1.Spanner.ExecuteBatchDml", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "ExecuteBatchDml" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.ExecuteBatchDmlRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.ExecuteBatchDmlResponse", - "shortName": "execute_batch_dml" - }, - "description": "Sample for ExecuteBatchDml", - "file": "spanner_v1_generated_spanner_execute_batch_dml_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_ExecuteBatchDml_async", - "segments": [ - { - "end": 56, - "start": 27, - "type": "FULL" - }, - { - "end": 56, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 50, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 53, - "start": 51, - "type": "REQUEST_EXECUTION" - }, - { - "end": 57, - "start": 54, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_execute_batch_dml_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.execute_batch_dml", - "method": { - "fullName": "google.spanner.v1.Spanner.ExecuteBatchDml", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "ExecuteBatchDml" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.ExecuteBatchDmlRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.ExecuteBatchDmlResponse", - "shortName": "execute_batch_dml" - }, - "description": "Sample for ExecuteBatchDml", - "file": "spanner_v1_generated_spanner_execute_batch_dml_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_ExecuteBatchDml_sync", - "segments": [ - { - "end": 56, - "start": 27, - "type": "FULL" - }, - { - "end": 56, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 50, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 53, - "start": 51, - "type": "REQUEST_EXECUTION" - }, - { - "end": 57, - "start": 54, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_execute_batch_dml_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.execute_sql", - "method": { - "fullName": "google.spanner.v1.Spanner.ExecuteSql", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "ExecuteSql" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.ExecuteSqlRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.ResultSet", - "shortName": "execute_sql" - }, - "description": "Sample for ExecuteSql", - "file": "spanner_v1_generated_spanner_execute_sql_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_ExecuteSql_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_execute_sql_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.execute_sql", - "method": { - "fullName": "google.spanner.v1.Spanner.ExecuteSql", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "ExecuteSql" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.ExecuteSqlRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.ResultSet", - "shortName": "execute_sql" - }, - "description": "Sample for ExecuteSql", - "file": "spanner_v1_generated_spanner_execute_sql_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_ExecuteSql_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_execute_sql_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.execute_streaming_sql", - "method": { - "fullName": "google.spanner.v1.Spanner.ExecuteStreamingSql", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "ExecuteStreamingSql" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.ExecuteSqlRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "Iterable[google.cloud.spanner_v1.types.PartialResultSet]", - "shortName": "execute_streaming_sql" - }, - "description": "Sample for ExecuteStreamingSql", - "file": "spanner_v1_generated_spanner_execute_streaming_sql_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_ExecuteStreamingSql_async", - "segments": [ - { - "end": 53, - "start": 27, - "type": "FULL" - }, - { - "end": 53, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 54, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_execute_streaming_sql_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.execute_streaming_sql", - "method": { - "fullName": "google.spanner.v1.Spanner.ExecuteStreamingSql", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "ExecuteStreamingSql" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.ExecuteSqlRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "Iterable[google.cloud.spanner_v1.types.PartialResultSet]", - "shortName": "execute_streaming_sql" - }, - "description": "Sample for ExecuteStreamingSql", - "file": "spanner_v1_generated_spanner_execute_streaming_sql_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_ExecuteStreamingSql_sync", - "segments": [ - { - "end": 53, - "start": 27, - "type": "FULL" - }, - { - "end": 53, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 54, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_execute_streaming_sql_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.get_session", - "method": { - "fullName": "google.spanner.v1.Spanner.GetSession", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "GetSession" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.GetSessionRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.Session", - "shortName": "get_session" - }, - "description": "Sample for GetSession", - "file": "spanner_v1_generated_spanner_get_session_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_GetSession_async", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_get_session_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.get_session", - "method": { - "fullName": "google.spanner.v1.Spanner.GetSession", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "GetSession" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.GetSessionRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.Session", - "shortName": "get_session" - }, - "description": "Sample for GetSession", - "file": "spanner_v1_generated_spanner_get_session_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_GetSession_sync", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_get_session_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.list_sessions", - "method": { - "fullName": "google.spanner.v1.Spanner.ListSessions", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "ListSessions" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.ListSessionsRequest" - }, - { - "name": "database", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.services.spanner.pagers.ListSessionsAsyncPager", - "shortName": "list_sessions" - }, - "description": "Sample for ListSessions", - "file": "spanner_v1_generated_spanner_list_sessions_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_ListSessions_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_list_sessions_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.list_sessions", - "method": { - "fullName": "google.spanner.v1.Spanner.ListSessions", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "ListSessions" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.ListSessionsRequest" - }, - { - "name": "database", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.services.spanner.pagers.ListSessionsPager", - "shortName": "list_sessions" - }, - "description": "Sample for ListSessions", - "file": "spanner_v1_generated_spanner_list_sessions_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_ListSessions_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_list_sessions_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.partition_query", - "method": { - "fullName": "google.spanner.v1.Spanner.PartitionQuery", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "PartitionQuery" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.PartitionQueryRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.PartitionResponse", - "shortName": "partition_query" - }, - "description": "Sample for PartitionQuery", - "file": "spanner_v1_generated_spanner_partition_query_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_PartitionQuery_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_partition_query_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.partition_query", - "method": { - "fullName": "google.spanner.v1.Spanner.PartitionQuery", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "PartitionQuery" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.PartitionQueryRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.PartitionResponse", - "shortName": "partition_query" - }, - "description": "Sample for PartitionQuery", - "file": "spanner_v1_generated_spanner_partition_query_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_PartitionQuery_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_partition_query_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.partition_read", - "method": { - "fullName": "google.spanner.v1.Spanner.PartitionRead", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "PartitionRead" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.PartitionReadRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.PartitionResponse", - "shortName": "partition_read" - }, - "description": "Sample for PartitionRead", - "file": "spanner_v1_generated_spanner_partition_read_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_PartitionRead_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_partition_read_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.partition_read", - "method": { - "fullName": "google.spanner.v1.Spanner.PartitionRead", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "PartitionRead" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.PartitionReadRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.PartitionResponse", - "shortName": "partition_read" - }, - "description": "Sample for PartitionRead", - "file": "spanner_v1_generated_spanner_partition_read_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_PartitionRead_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_partition_read_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.read", - "method": { - "fullName": "google.spanner.v1.Spanner.Read", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "Read" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.ReadRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.ResultSet", - "shortName": "read" - }, - "description": "Sample for Read", - "file": "spanner_v1_generated_spanner_read_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_Read_async", - "segments": [ - { - "end": 53, - "start": 27, - "type": "FULL" - }, - { - "end": 53, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 47, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 50, - "start": 48, - "type": "REQUEST_EXECUTION" - }, - { - "end": 54, - "start": 51, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_read_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.read", - "method": { - "fullName": "google.spanner.v1.Spanner.Read", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "Read" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.ReadRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_v1.types.ResultSet", - "shortName": "read" - }, - "description": "Sample for Read", - "file": "spanner_v1_generated_spanner_read_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_Read_sync", - "segments": [ - { - "end": 53, - "start": 27, - "type": "FULL" - }, - { - "end": 53, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 47, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 50, - "start": 48, - "type": "REQUEST_EXECUTION" - }, - { - "end": 54, - "start": 51, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_read_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.rollback", - "method": { - "fullName": "google.spanner.v1.Spanner.Rollback", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "Rollback" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.RollbackRequest" - }, - { - "name": "session", - "type": "str" - }, - { - "name": "transaction_id", - "type": "bytes" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "shortName": "rollback" - }, - "description": "Sample for Rollback", - "file": "spanner_v1_generated_spanner_rollback_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_Rollback_async", - "segments": [ - { - "end": 50, - "start": 27, - "type": "FULL" - }, - { - "end": 50, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 51, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_rollback_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.rollback", - "method": { - "fullName": "google.spanner.v1.Spanner.Rollback", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "Rollback" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.RollbackRequest" - }, - { - "name": "session", - "type": "str" - }, - { - "name": "transaction_id", - "type": "bytes" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "shortName": "rollback" - }, - "description": "Sample for Rollback", - "file": "spanner_v1_generated_spanner_rollback_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_Rollback_sync", - "segments": [ - { - "end": 50, - "start": 27, - "type": "FULL" - }, - { - "end": 50, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 51, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_rollback_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient", - "shortName": "SpannerAsyncClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerAsyncClient.streaming_read", - "method": { - "fullName": "google.spanner.v1.Spanner.StreamingRead", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "StreamingRead" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.ReadRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "Iterable[google.cloud.spanner_v1.types.PartialResultSet]", - "shortName": "streaming_read" - }, - "description": "Sample for StreamingRead", - "file": "spanner_v1_generated_spanner_streaming_read_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_StreamingRead_async", - "segments": [ - { - "end": 54, - "start": 27, - "type": "FULL" - }, - { - "end": 54, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 47, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 50, - "start": 48, - "type": "REQUEST_EXECUTION" - }, - { - "end": 55, - "start": 51, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_streaming_read_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_v1.SpannerClient", - "shortName": "SpannerClient" - }, - "fullName": "google.cloud.spanner_v1.SpannerClient.streaming_read", - "method": { - "fullName": "google.spanner.v1.Spanner.StreamingRead", - "service": { - "fullName": "google.spanner.v1.Spanner", - "shortName": "Spanner" - }, - "shortName": "StreamingRead" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_v1.types.ReadRequest" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "Iterable[google.cloud.spanner_v1.types.PartialResultSet]", - "shortName": "streaming_read" - }, - "description": "Sample for StreamingRead", - "file": "spanner_v1_generated_spanner_streaming_read_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_Spanner_StreamingRead_sync", - "segments": [ - { - "end": 54, - "start": 27, - "type": "FULL" - }, - { - "end": 54, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 47, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 50, - "start": 48, - "type": "REQUEST_EXECUTION" - }, - { - "end": 55, - "start": 51, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_spanner_streaming_read_sync.py" - } - ] -} diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_async.py deleted file mode 100644 index 44c9850315..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for BatchCreateSessions -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_BatchCreateSessions_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_batch_create_sessions(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.BatchCreateSessionsRequest( - database="database_value", - session_count=1420, - ) - - # Make the request - response = await client.batch_create_sessions(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_BatchCreateSessions_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_sync.py deleted file mode 100644 index 35e256e2fb..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_batch_create_sessions_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for BatchCreateSessions -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_BatchCreateSessions_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_batch_create_sessions(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.BatchCreateSessionsRequest( - database="database_value", - session_count=1420, - ) - - # Make the request - response = client.batch_create_sessions(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_BatchCreateSessions_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_async.py deleted file mode 100644 index 86b292e2d9..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_async.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for BeginTransaction -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_BeginTransaction_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_begin_transaction(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.BeginTransactionRequest( - session="session_value", - ) - - # Make the request - response = await client.begin_transaction(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_BeginTransaction_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_sync.py deleted file mode 100644 index 7a7cecad3a..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_begin_transaction_sync.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for BeginTransaction -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_BeginTransaction_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_begin_transaction(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.BeginTransactionRequest( - session="session_value", - ) - - # Make the request - response = client.begin_transaction(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_BeginTransaction_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_async.py deleted file mode 100644 index 2f60d31995..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for Commit -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_Commit_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_commit(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.CommitRequest( - transaction_id=b'transaction_id_blob', - session="session_value", - ) - - # Make the request - response = await client.commit(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_Commit_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_sync.py deleted file mode 100644 index 8badd1cbf3..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_commit_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for Commit -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_Commit_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_commit(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.CommitRequest( - transaction_id=b'transaction_id_blob', - session="session_value", - ) - - # Make the request - response = client.commit(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_Commit_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_async.py deleted file mode 100644 index e55a750deb..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_async.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for CreateSession -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_CreateSession_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_create_session(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.CreateSessionRequest( - database="database_value", - ) - - # Make the request - response = await client.create_session(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_CreateSession_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_sync.py deleted file mode 100644 index e5d8d5561d..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_create_session_sync.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for CreateSession -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_CreateSession_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_create_session(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.CreateSessionRequest( - database="database_value", - ) - - # Make the request - response = client.create_session(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_CreateSession_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_async.py deleted file mode 100644 index b81c530274..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_async.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for DeleteSession -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_DeleteSession_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_delete_session(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.DeleteSessionRequest( - name="name_value", - ) - - # Make the request - await client.delete_session(request=request) - - -# [END spanner_v1_generated_Spanner_DeleteSession_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_sync.py deleted file mode 100644 index fedf7a3f6f..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_delete_session_sync.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for DeleteSession -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_DeleteSession_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_delete_session(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.DeleteSessionRequest( - name="name_value", - ) - - # Make the request - client.delete_session(request=request) - - -# [END spanner_v1_generated_Spanner_DeleteSession_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_async.py deleted file mode 100644 index 971b21fbdf..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_async.py +++ /dev/null @@ -1,57 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ExecuteBatchDml -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_ExecuteBatchDml_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_execute_batch_dml(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - statements = spanner_v1.Statement() - statements.sql = "sql_value" - - request = spanner_v1.ExecuteBatchDmlRequest( - session="session_value", - statements=statements, - seqno=550, - ) - - # Make the request - response = await client.execute_batch_dml(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_ExecuteBatchDml_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_sync.py deleted file mode 100644 index 9bce572521..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_batch_dml_sync.py +++ /dev/null @@ -1,57 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ExecuteBatchDml -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_ExecuteBatchDml_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_execute_batch_dml(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - statements = spanner_v1.Statement() - statements.sql = "sql_value" - - request = spanner_v1.ExecuteBatchDmlRequest( - session="session_value", - statements=statements, - seqno=550, - ) - - # Make the request - response = client.execute_batch_dml(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_ExecuteBatchDml_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_async.py deleted file mode 100644 index b904386d10..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ExecuteSql -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_ExecuteSql_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_execute_sql(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.ExecuteSqlRequest( - session="session_value", - sql="sql_value", - ) - - # Make the request - response = await client.execute_sql(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_ExecuteSql_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_sync.py deleted file mode 100644 index 2591106775..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_sql_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ExecuteSql -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_ExecuteSql_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_execute_sql(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.ExecuteSqlRequest( - session="session_value", - sql="sql_value", - ) - - # Make the request - response = client.execute_sql(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_ExecuteSql_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_async.py deleted file mode 100644 index 0165a9e66c..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_async.py +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ExecuteStreamingSql -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_ExecuteStreamingSql_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_execute_streaming_sql(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.ExecuteSqlRequest( - session="session_value", - sql="sql_value", - ) - - # Make the request - stream = await client.execute_streaming_sql(request=request) - - # Handle the response - async for response in stream: - print(response) - -# [END spanner_v1_generated_Spanner_ExecuteStreamingSql_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_sync.py deleted file mode 100644 index 9f6d434588..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_execute_streaming_sql_sync.py +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ExecuteStreamingSql -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_ExecuteStreamingSql_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_execute_streaming_sql(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.ExecuteSqlRequest( - session="session_value", - sql="sql_value", - ) - - # Make the request - stream = client.execute_streaming_sql(request=request) - - # Handle the response - for response in stream: - print(response) - -# [END spanner_v1_generated_Spanner_ExecuteStreamingSql_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_async.py deleted file mode 100644 index f2400b8631..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_async.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetSession -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_GetSession_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_get_session(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.GetSessionRequest( - name="name_value", - ) - - # Make the request - response = await client.get_session(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_GetSession_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_sync.py deleted file mode 100644 index 157f7d60fc..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_get_session_sync.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetSession -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_GetSession_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_get_session(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.GetSessionRequest( - name="name_value", - ) - - # Make the request - response = client.get_session(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_GetSession_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_async.py deleted file mode 100644 index 35205eadd4..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListSessions -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_ListSessions_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_list_sessions(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.ListSessionsRequest( - database="database_value", - ) - - # Make the request - page_result = client.list_sessions(request=request) - - # Handle the response - async for response in page_result: - print(response) - -# [END spanner_v1_generated_Spanner_ListSessions_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_sync.py deleted file mode 100644 index 0cc98c4366..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_list_sessions_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListSessions -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_ListSessions_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_list_sessions(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.ListSessionsRequest( - database="database_value", - ) - - # Make the request - page_result = client.list_sessions(request=request) - - # Handle the response - for response in page_result: - print(response) - -# [END spanner_v1_generated_Spanner_ListSessions_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_async.py deleted file mode 100644 index 4c821844b1..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for PartitionQuery -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_PartitionQuery_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_partition_query(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.PartitionQueryRequest( - session="session_value", - sql="sql_value", - ) - - # Make the request - response = await client.partition_query(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_PartitionQuery_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_sync.py deleted file mode 100644 index 1008022404..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_query_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for PartitionQuery -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_PartitionQuery_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_partition_query(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.PartitionQueryRequest( - session="session_value", - sql="sql_value", - ) - - # Make the request - response = client.partition_query(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_PartitionQuery_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_async.py deleted file mode 100644 index 050dd4028b..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for PartitionRead -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_PartitionRead_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_partition_read(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.PartitionReadRequest( - session="session_value", - table="table_value", - ) - - # Make the request - response = await client.partition_read(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_PartitionRead_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_sync.py deleted file mode 100644 index 52bfcb48c3..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_partition_read_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for PartitionRead -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_PartitionRead_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_partition_read(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.PartitionReadRequest( - session="session_value", - table="table_value", - ) - - # Make the request - response = client.partition_read(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_PartitionRead_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_async.py deleted file mode 100644 index 8d79db7524..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_async.py +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for Read -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_Read_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_read(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.ReadRequest( - session="session_value", - table="table_value", - columns=['columns_value1', 'columns_value2'], - ) - - # Make the request - response = await client.read(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_Read_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_sync.py deleted file mode 100644 index 512e29c917..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_read_sync.py +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for Read -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_Read_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_read(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.ReadRequest( - session="session_value", - table="table_value", - columns=['columns_value1', 'columns_value2'], - ) - - # Make the request - response = client.read(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_Spanner_Read_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_async.py deleted file mode 100644 index edfd86d457..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_async.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for Rollback -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_Rollback_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_rollback(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.RollbackRequest( - session="session_value", - transaction_id=b'transaction_id_blob', - ) - - # Make the request - await client.rollback(request=request) - - -# [END spanner_v1_generated_Spanner_Rollback_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_sync.py deleted file mode 100644 index 6fe90e6678..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_rollback_sync.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for Rollback -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_Rollback_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_rollback(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.RollbackRequest( - session="session_value", - transaction_id=b'transaction_id_blob', - ) - - # Make the request - client.rollback(request=request) - - -# [END spanner_v1_generated_Spanner_Rollback_sync] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_async.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_async.py deleted file mode 100644 index 9709b040ea..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_async.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for StreamingRead -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_StreamingRead_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -async def sample_streaming_read(): - # Create a client - client = spanner_v1.SpannerAsyncClient() - - # Initialize request argument(s) - request = spanner_v1.ReadRequest( - session="session_value", - table="table_value", - columns=['columns_value1', 'columns_value2'], - ) - - # Make the request - stream = await client.streaming_read(request=request) - - # Handle the response - async for response in stream: - print(response) - -# [END spanner_v1_generated_Spanner_StreamingRead_async] diff --git a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_sync.py b/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_sync.py deleted file mode 100644 index 3d5636eadb..0000000000 --- a/owl-bot-staging/spanner/v1/samples/generated_samples/spanner_v1_generated_spanner_streaming_read_sync.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for StreamingRead -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner - - -# [START spanner_v1_generated_Spanner_StreamingRead_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_v1 - - -def sample_streaming_read(): - # Create a client - client = spanner_v1.SpannerClient() - - # Initialize request argument(s) - request = spanner_v1.ReadRequest( - session="session_value", - table="table_value", - columns=['columns_value1', 'columns_value2'], - ) - - # Make the request - stream = client.streaming_read(request=request) - - # Handle the response - for response in stream: - print(response) - -# [END spanner_v1_generated_Spanner_StreamingRead_sync] diff --git a/owl-bot-staging/spanner/v1/scripts/fixup_spanner_v1_keywords.py b/owl-bot-staging/spanner/v1/scripts/fixup_spanner_v1_keywords.py deleted file mode 100644 index b897807106..0000000000 --- a/owl-bot-staging/spanner/v1/scripts/fixup_spanner_v1_keywords.py +++ /dev/null @@ -1,190 +0,0 @@ -#! /usr/bin/env python3 -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import argparse -import os -import libcst as cst -import pathlib -import sys -from typing import (Any, Callable, Dict, List, Sequence, Tuple) - - -def partition( - predicate: Callable[[Any], bool], - iterator: Sequence[Any] -) -> Tuple[List[Any], List[Any]]: - """A stable, out-of-place partition.""" - results = ([], []) - - for i in iterator: - results[int(predicate(i))].append(i) - - # Returns trueList, falseList - return results[1], results[0] - - -class spannerCallTransformer(cst.CSTTransformer): - CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') - METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'batch_create_sessions': ('database', 'session_count', 'session_template', ), - 'begin_transaction': ('session', 'options', 'request_options', ), - 'commit': ('session', 'transaction_id', 'single_use_transaction', 'mutations', 'return_commit_stats', 'request_options', ), - 'create_session': ('database', 'session', ), - 'delete_session': ('name', ), - 'execute_batch_dml': ('session', 'transaction', 'statements', 'seqno', 'request_options', ), - 'execute_sql': ('session', 'sql', 'transaction', 'params', 'param_types', 'resume_token', 'query_mode', 'partition_token', 'seqno', 'query_options', 'request_options', 'data_boost_enabled', ), - 'execute_streaming_sql': ('session', 'sql', 'transaction', 'params', 'param_types', 'resume_token', 'query_mode', 'partition_token', 'seqno', 'query_options', 'request_options', 'data_boost_enabled', ), - 'get_session': ('name', ), - 'list_sessions': ('database', 'page_size', 'page_token', 'filter', ), - 'partition_query': ('session', 'sql', 'transaction', 'params', 'param_types', 'partition_options', ), - 'partition_read': ('session', 'table', 'key_set', 'transaction', 'index', 'columns', 'partition_options', ), - 'read': ('session', 'table', 'columns', 'key_set', 'transaction', 'index', 'limit', 'resume_token', 'partition_token', 'request_options', 'data_boost_enabled', ), - 'rollback': ('session', 'transaction_id', ), - 'streaming_read': ('session', 'table', 'columns', 'key_set', 'transaction', 'index', 'limit', 'resume_token', 'partition_token', 'request_options', 'data_boost_enabled', ), - } - - def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: - try: - key = original.func.attr.value - kword_params = self.METHOD_TO_PARAMS[key] - except (AttributeError, KeyError): - # Either not a method from the API or too convoluted to be sure. - return updated - - # If the existing code is valid, keyword args come after positional args. - # Therefore, all positional args must map to the first parameters. - args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) - if any(k.keyword.value == "request" for k in kwargs): - # We've already fixed this file, don't fix it again. - return updated - - kwargs, ctrl_kwargs = partition( - lambda a: a.keyword.value not in self.CTRL_PARAMS, - kwargs - ) - - args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] - ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) - for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) - - request_arg = cst.Arg( - value=cst.Dict([ - cst.DictElement( - cst.SimpleString("'{}'".format(name)), -cst.Element(value=arg.value) - ) - # Note: the args + kwargs looks silly, but keep in mind that - # the control parameters had to be stripped out, and that - # those could have been passed positionally or by keyword. - for name, arg in zip(kword_params, args + kwargs)]), - keyword=cst.Name("request") - ) - - return updated.with_changes( - args=[request_arg] + ctrl_kwargs - ) - - -def fix_files( - in_dir: pathlib.Path, - out_dir: pathlib.Path, - *, - transformer=spannerCallTransformer(), -): - """Duplicate the input dir to the output dir, fixing file method calls. - - Preconditions: - * in_dir is a real directory - * out_dir is a real, empty directory - """ - pyfile_gen = ( - pathlib.Path(os.path.join(root, f)) - for root, _, files in os.walk(in_dir) - for f in files if os.path.splitext(f)[1] == ".py" - ) - - for fpath in pyfile_gen: - with open(fpath, 'r') as f: - src = f.read() - - # Parse the code and insert method call fixes. - tree = cst.parse_module(src) - updated = tree.visit(transformer) - - # Create the path and directory structure for the new file. - updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) - updated_path.parent.mkdir(parents=True, exist_ok=True) - - # Generate the updated source file at the corresponding path. - with open(updated_path, 'w') as f: - f.write(updated.code) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description="""Fix up source that uses the spanner client library. - -The existing sources are NOT overwritten but are copied to output_dir with changes made. - -Note: This tool operates at a best-effort level at converting positional - parameters in client method calls to keyword based parameters. - Cases where it WILL FAIL include - A) * or ** expansion in a method call. - B) Calls via function or method alias (includes free function calls) - C) Indirect or dispatched calls (e.g. the method is looked up dynamically) - - These all constitute false negatives. The tool will also detect false - positives when an API method shares a name with another method. -""") - parser.add_argument( - '-d', - '--input-directory', - required=True, - dest='input_dir', - help='the input directory to walk for python files to fix up', - ) - parser.add_argument( - '-o', - '--output-directory', - required=True, - dest='output_dir', - help='the directory to output files fixed via un-flattening', - ) - args = parser.parse_args() - input_dir = pathlib.Path(args.input_dir) - output_dir = pathlib.Path(args.output_dir) - if not input_dir.is_dir(): - print( - f"input directory '{input_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if not output_dir.is_dir(): - print( - f"output directory '{output_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if os.listdir(output_dir): - print( - f"output directory '{output_dir}' is not empty", - file=sys.stderr, - ) - sys.exit(-1) - - fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/spanner/v1/setup.py b/owl-bot-staging/spanner/v1/setup.py deleted file mode 100644 index 322e535102..0000000000 --- a/owl-bot-staging/spanner/v1/setup.py +++ /dev/null @@ -1,90 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import io -import os - -import setuptools # type: ignore - -package_root = os.path.abspath(os.path.dirname(__file__)) - -name = 'google-cloud-spanner' - - -description = "Google Cloud Spanner API client library" - -version = {} -with open(os.path.join(package_root, 'google/cloud/spanner/gapic_version.py')) as fp: - exec(fp.read(), version) -version = version["__version__"] - -if version[0] == "0": - release_status = "Development Status :: 4 - Beta" -else: - release_status = "Development Status :: 5 - Production/Stable" - -dependencies = [ - "google-api-core[grpc] >= 1.34.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", - "proto-plus >= 1.22.0, <2.0.0dev", - "proto-plus >= 1.22.2, <2.0.0dev; python_version>='3.11'", - "protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", -] -url = "https://github.com/googleapis/python-spanner" - -package_root = os.path.abspath(os.path.dirname(__file__)) - -readme_filename = os.path.join(package_root, "README.rst") -with io.open(readme_filename, encoding="utf-8") as readme_file: - readme = readme_file.read() - -packages = [ - package - for package in setuptools.PEP420PackageFinder.find() - if package.startswith("google") -] - -namespaces = ["google", "google.cloud"] - -setuptools.setup( - name=name, - version=version, - description=description, - long_description=readme, - author="Google LLC", - author_email="googleapis-packages@google.com", - license="Apache 2.0", - url=url, - classifiers=[ - release_status, - "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Operating System :: OS Independent", - "Topic :: Internet", - ], - platforms="Posix; MacOS X; Windows", - packages=packages, - python_requires=">=3.7", - namespace_packages=namespaces, - install_requires=dependencies, - include_package_data=True, - zip_safe=False, -) diff --git a/owl-bot-staging/spanner/v1/testing/constraints-3.10.txt b/owl-bot-staging/spanner/v1/testing/constraints-3.10.txt deleted file mode 100644 index ed7f9aed25..0000000000 --- a/owl-bot-staging/spanner/v1/testing/constraints-3.10.txt +++ /dev/null @@ -1,6 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf diff --git a/owl-bot-staging/spanner/v1/testing/constraints-3.11.txt b/owl-bot-staging/spanner/v1/testing/constraints-3.11.txt deleted file mode 100644 index ed7f9aed25..0000000000 --- a/owl-bot-staging/spanner/v1/testing/constraints-3.11.txt +++ /dev/null @@ -1,6 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf diff --git a/owl-bot-staging/spanner/v1/testing/constraints-3.12.txt b/owl-bot-staging/spanner/v1/testing/constraints-3.12.txt deleted file mode 100644 index ed7f9aed25..0000000000 --- a/owl-bot-staging/spanner/v1/testing/constraints-3.12.txt +++ /dev/null @@ -1,6 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf diff --git a/owl-bot-staging/spanner/v1/testing/constraints-3.7.txt b/owl-bot-staging/spanner/v1/testing/constraints-3.7.txt deleted file mode 100644 index 6c44adfea7..0000000000 --- a/owl-bot-staging/spanner/v1/testing/constraints-3.7.txt +++ /dev/null @@ -1,9 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.0 -proto-plus==1.22.0 -protobuf==3.19.5 diff --git a/owl-bot-staging/spanner/v1/testing/constraints-3.8.txt b/owl-bot-staging/spanner/v1/testing/constraints-3.8.txt deleted file mode 100644 index ed7f9aed25..0000000000 --- a/owl-bot-staging/spanner/v1/testing/constraints-3.8.txt +++ /dev/null @@ -1,6 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf diff --git a/owl-bot-staging/spanner/v1/testing/constraints-3.9.txt b/owl-bot-staging/spanner/v1/testing/constraints-3.9.txt deleted file mode 100644 index ed7f9aed25..0000000000 --- a/owl-bot-staging/spanner/v1/testing/constraints-3.9.txt +++ /dev/null @@ -1,6 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf diff --git a/owl-bot-staging/spanner/v1/tests/__init__.py b/owl-bot-staging/spanner/v1/tests/__init__.py deleted file mode 100644 index 231bc12501..0000000000 --- a/owl-bot-staging/spanner/v1/tests/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner/v1/tests/unit/__init__.py b/owl-bot-staging/spanner/v1/tests/unit/__init__.py deleted file mode 100644 index 231bc12501..0000000000 --- a/owl-bot-staging/spanner/v1/tests/unit/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner/v1/tests/unit/gapic/__init__.py b/owl-bot-staging/spanner/v1/tests/unit/gapic/__init__.py deleted file mode 100644 index 231bc12501..0000000000 --- a/owl-bot-staging/spanner/v1/tests/unit/gapic/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/__init__.py b/owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/__init__.py deleted file mode 100644 index 231bc12501..0000000000 --- a/owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/test_spanner.py b/owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/test_spanner.py deleted file mode 100644 index e6954d4dbd..0000000000 --- a/owl-bot-staging/spanner/v1/tests/unit/gapic/spanner_v1/test_spanner.py +++ /dev/null @@ -1,7665 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -# try/except added for compatibility with python < 3.8 -try: - from unittest import mock - from unittest.mock import AsyncMock # pragma: NO COVER -except ImportError: # pragma: NO COVER - import mock - -import grpc -from grpc.experimental import aio -from collections.abc import Iterable -from google.protobuf import json_format -import json -import math -import pytest -from proto.marshal.rules.dates import DurationRule, TimestampRule -from proto.marshal.rules import wrappers -from requests import Response -from requests import Request, PreparedRequest -from requests.sessions import Session -from google.protobuf import json_format - -from google.api_core import client_options -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import path_template -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.cloud.spanner_v1.services.spanner import SpannerAsyncClient -from google.cloud.spanner_v1.services.spanner import SpannerClient -from google.cloud.spanner_v1.services.spanner import pagers -from google.cloud.spanner_v1.services.spanner import transports -from google.cloud.spanner_v1.types import commit_response -from google.cloud.spanner_v1.types import keys -from google.cloud.spanner_v1.types import mutation -from google.cloud.spanner_v1.types import result_set -from google.cloud.spanner_v1.types import spanner -from google.cloud.spanner_v1.types import transaction -from google.cloud.spanner_v1.types import type as gs_type -from google.oauth2 import service_account -from google.protobuf import duration_pb2 # type: ignore -from google.protobuf import struct_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -import google.auth - - -def client_cert_source_callback(): - return b"cert bytes", b"key bytes" - - -# If default endpoint is localhost, then default mtls endpoint will be the same. -# This method modifies the default endpoint so the client can produce a different -# mtls endpoint for endpoint testing purposes. -def modify_default_endpoint(client): - return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT - - -def test__get_default_mtls_endpoint(): - api_endpoint = "example.googleapis.com" - api_mtls_endpoint = "example.mtls.googleapis.com" - sandbox_endpoint = "example.sandbox.googleapis.com" - sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" - non_googleapi = "api.example.com" - - assert SpannerClient._get_default_mtls_endpoint(None) is None - assert SpannerClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert SpannerClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert SpannerClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert SpannerClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert SpannerClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - - -@pytest.mark.parametrize("client_class,transport_name", [ - (SpannerClient, "grpc"), - (SpannerAsyncClient, "grpc_asyncio"), - (SpannerClient, "rest"), -]) -def test_spanner_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: - factory.return_value = creds - info = {"valid": True} - client = client_class.from_service_account_info(info, transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == ( - 'spanner.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else - 'https://spanner.googleapis.com' - ) - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.SpannerGrpcTransport, "grpc"), - (transports.SpannerGrpcAsyncIOTransport, "grpc_asyncio"), - (transports.SpannerRestTransport, "rest"), -]) -def test_spanner_client_service_account_always_use_jwt(transport_class, transport_name): - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - transport = transport_class(credentials=creds, always_use_jwt_access=True) - use_jwt.assert_called_once_with(True) - - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - transport = transport_class(credentials=creds, always_use_jwt_access=False) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("client_class,transport_name", [ - (SpannerClient, "grpc"), - (SpannerAsyncClient, "grpc_asyncio"), - (SpannerClient, "rest"), -]) -def test_spanner_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: - factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == ( - 'spanner.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else - 'https://spanner.googleapis.com' - ) - - -def test_spanner_client_get_transport_class(): - transport = SpannerClient.get_transport_class() - available_transports = [ - transports.SpannerGrpcTransport, - transports.SpannerRestTransport, - ] - assert transport in available_transports - - transport = SpannerClient.get_transport_class("grpc") - assert transport == transports.SpannerGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (SpannerClient, transports.SpannerGrpcTransport, "grpc"), - (SpannerAsyncClient, transports.SpannerGrpcAsyncIOTransport, "grpc_asyncio"), - (SpannerClient, transports.SpannerRestTransport, "rest"), -]) -@mock.patch.object(SpannerClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SpannerClient)) -@mock.patch.object(SpannerAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SpannerAsyncClient)) -def test_spanner_client_client_options(client_class, transport_class, transport_name): - # Check that if channel is provided we won't create a new one. - with mock.patch.object(SpannerClient, 'get_transport_class') as gtc: - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ) - client = client_class(transport=transport) - gtc.assert_not_called() - - # Check that if channel is provided via str we will create a new one. - with mock.patch.object(SpannerClient, 'get_transport_class') as gtc: - client = client_class(transport=transport_name) - gtc.assert_called() - - # Check the case api_endpoint is provided. - options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name, client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_MTLS_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has - # unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): - with pytest.raises(MutualTLSChannelError): - client = client_class(transport=transport_name) - - # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): - with pytest.raises(ValueError): - client = client_class(transport=transport_name) - - # Check the case quota_project_id is provided - options = client_options.ClientOptions(quota_project_id="octopus") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id="octopus", - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - # Check the case api_endpoint is provided - options = client_options.ClientOptions(api_audience="https://language.googleapis.com") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience="https://language.googleapis.com" - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (SpannerClient, transports.SpannerGrpcTransport, "grpc", "true"), - (SpannerAsyncClient, transports.SpannerGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (SpannerClient, transports.SpannerGrpcTransport, "grpc", "false"), - (SpannerAsyncClient, transports.SpannerGrpcAsyncIOTransport, "grpc_asyncio", "false"), - (SpannerClient, transports.SpannerRestTransport, "rest", "true"), - (SpannerClient, transports.SpannerRestTransport, "rest", "false"), -]) -@mock.patch.object(SpannerClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SpannerClient)) -@mock.patch.object(SpannerAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SpannerAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_spanner_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): - # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default - # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. - - # Check the case client_cert_source is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - - if use_client_cert_env == "false": - expected_client_cert_source = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_client_cert_source = client_cert_source_callback - expected_host = client.DEFAULT_MTLS_ENDPOINT - - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case ADC client cert is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): - if use_client_cert_env == "false": - expected_host = client.DEFAULT_ENDPOINT - expected_client_cert_source = None - else: - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_client_cert_source = client_cert_source_callback - - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - -@pytest.mark.parametrize("client_class", [ - SpannerClient, SpannerAsyncClient -]) -@mock.patch.object(SpannerClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SpannerClient)) -@mock.patch.object(SpannerAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SpannerAsyncClient)) -def test_spanner_client_get_mtls_endpoint_and_cert_source(client_class): - mock_client_cert_source = mock.Mock() - - # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - mock_api_endpoint = "foo" - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) - assert api_endpoint == mock_api_endpoint - assert cert_source == mock_client_cert_source - - # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): - mock_client_cert_source = mock.Mock() - mock_api_endpoint = "foo" - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) - assert api_endpoint == mock_api_endpoint - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_client_cert_source): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT - assert cert_source == mock_client_cert_source - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (SpannerClient, transports.SpannerGrpcTransport, "grpc"), - (SpannerAsyncClient, transports.SpannerGrpcAsyncIOTransport, "grpc_asyncio"), - (SpannerClient, transports.SpannerRestTransport, "rest"), -]) -def test_spanner_client_client_options_scopes(client_class, transport_class, transport_name): - # Check the case scopes are provided. - options = client_options.ClientOptions( - scopes=["1", "2"], - ) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=["1", "2"], - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ - (SpannerClient, transports.SpannerGrpcTransport, "grpc", grpc_helpers), - (SpannerAsyncClient, transports.SpannerGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), - (SpannerClient, transports.SpannerRestTransport, "rest", None), -]) -def test_spanner_client_client_options_credentials_file(client_class, transport_class, transport_name, grpc_helpers): - # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) - - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file="credentials.json", - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - -def test_spanner_client_client_options_from_dict(): - with mock.patch('google.cloud.spanner_v1.services.spanner.transports.SpannerGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = SpannerClient( - client_options={'api_endpoint': 'squid.clam.whelk'} - ) - grpc_transport.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ - (SpannerClient, transports.SpannerGrpcTransport, "grpc", grpc_helpers), - (SpannerAsyncClient, transports.SpannerGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), -]) -def test_spanner_client_create_channel_credentials_file(client_class, transport_class, transport_name, grpc_helpers): - # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) - - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file="credentials.json", - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel" - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() - load_creds.return_value = (file_creds, None) - adc.return_value = (creds, None) - client = client_class(client_options=options, transport=transport_name) - create_channel.assert_called_with( - "spanner.googleapis.com:443", - credentials=file_creds, - credentials_file=None, - quota_project_id=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.data', -), - scopes=None, - default_host="spanner.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.CreateSessionRequest, - dict, -]) -def test_create_session(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_session), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.Session( - name='name_value', - creator_role='creator_role_value', - ) - response = client.create_session(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.CreateSessionRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.Session) - assert response.name == 'name_value' - assert response.creator_role == 'creator_role_value' - - -def test_create_session_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_session), - '__call__') as call: - client.create_session() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.CreateSessionRequest() - -@pytest.mark.asyncio -async def test_create_session_async(transport: str = 'grpc_asyncio', request_type=spanner.CreateSessionRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_session), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner.Session( - name='name_value', - creator_role='creator_role_value', - )) - response = await client.create_session(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.CreateSessionRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.Session) - assert response.name == 'name_value' - assert response.creator_role == 'creator_role_value' - - -@pytest.mark.asyncio -async def test_create_session_async_from_dict(): - await test_create_session_async(request_type=dict) - - -def test_create_session_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.CreateSessionRequest() - - request.database = 'database_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_session), - '__call__') as call: - call.return_value = spanner.Session() - client.create_session(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'database=database_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_create_session_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.CreateSessionRequest() - - request.database = 'database_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_session), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.Session()) - await client.create_session(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'database=database_value', - ) in kw['metadata'] - - -def test_create_session_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_session), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.Session() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_session( - database='database_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].database - mock_val = 'database_value' - assert arg == mock_val - - -def test_create_session_flattened_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_session( - spanner.CreateSessionRequest(), - database='database_value', - ) - -@pytest.mark.asyncio -async def test_create_session_flattened_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_session), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.Session() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.Session()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_session( - database='database_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].database - mock_val = 'database_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_create_session_flattened_error_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.create_session( - spanner.CreateSessionRequest(), - database='database_value', - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.BatchCreateSessionsRequest, - dict, -]) -def test_batch_create_sessions(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_create_sessions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.BatchCreateSessionsResponse( - ) - response = client.batch_create_sessions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.BatchCreateSessionsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.BatchCreateSessionsResponse) - - -def test_batch_create_sessions_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_create_sessions), - '__call__') as call: - client.batch_create_sessions() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.BatchCreateSessionsRequest() - -@pytest.mark.asyncio -async def test_batch_create_sessions_async(transport: str = 'grpc_asyncio', request_type=spanner.BatchCreateSessionsRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_create_sessions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner.BatchCreateSessionsResponse( - )) - response = await client.batch_create_sessions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.BatchCreateSessionsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.BatchCreateSessionsResponse) - - -@pytest.mark.asyncio -async def test_batch_create_sessions_async_from_dict(): - await test_batch_create_sessions_async(request_type=dict) - - -def test_batch_create_sessions_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.BatchCreateSessionsRequest() - - request.database = 'database_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_create_sessions), - '__call__') as call: - call.return_value = spanner.BatchCreateSessionsResponse() - client.batch_create_sessions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'database=database_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_batch_create_sessions_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.BatchCreateSessionsRequest() - - request.database = 'database_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_create_sessions), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.BatchCreateSessionsResponse()) - await client.batch_create_sessions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'database=database_value', - ) in kw['metadata'] - - -def test_batch_create_sessions_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_create_sessions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.BatchCreateSessionsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.batch_create_sessions( - database='database_value', - session_count=1420, - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].database - mock_val = 'database_value' - assert arg == mock_val - arg = args[0].session_count - mock_val = 1420 - assert arg == mock_val - - -def test_batch_create_sessions_flattened_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.batch_create_sessions( - spanner.BatchCreateSessionsRequest(), - database='database_value', - session_count=1420, - ) - -@pytest.mark.asyncio -async def test_batch_create_sessions_flattened_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.batch_create_sessions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.BatchCreateSessionsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.BatchCreateSessionsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.batch_create_sessions( - database='database_value', - session_count=1420, - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].database - mock_val = 'database_value' - assert arg == mock_val - arg = args[0].session_count - mock_val = 1420 - assert arg == mock_val - -@pytest.mark.asyncio -async def test_batch_create_sessions_flattened_error_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.batch_create_sessions( - spanner.BatchCreateSessionsRequest(), - database='database_value', - session_count=1420, - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.GetSessionRequest, - dict, -]) -def test_get_session(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_session), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.Session( - name='name_value', - creator_role='creator_role_value', - ) - response = client.get_session(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.GetSessionRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.Session) - assert response.name == 'name_value' - assert response.creator_role == 'creator_role_value' - - -def test_get_session_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_session), - '__call__') as call: - client.get_session() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.GetSessionRequest() - -@pytest.mark.asyncio -async def test_get_session_async(transport: str = 'grpc_asyncio', request_type=spanner.GetSessionRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_session), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner.Session( - name='name_value', - creator_role='creator_role_value', - )) - response = await client.get_session(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.GetSessionRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.Session) - assert response.name == 'name_value' - assert response.creator_role == 'creator_role_value' - - -@pytest.mark.asyncio -async def test_get_session_async_from_dict(): - await test_get_session_async(request_type=dict) - - -def test_get_session_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.GetSessionRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_session), - '__call__') as call: - call.return_value = spanner.Session() - client.get_session(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_get_session_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.GetSessionRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_session), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.Session()) - await client.get_session(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -def test_get_session_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_session), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.Session() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_session( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - - -def test_get_session_flattened_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_session( - spanner.GetSessionRequest(), - name='name_value', - ) - -@pytest.mark.asyncio -async def test_get_session_flattened_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_session), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.Session() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.Session()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_session( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_get_session_flattened_error_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.get_session( - spanner.GetSessionRequest(), - name='name_value', - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.ListSessionsRequest, - dict, -]) -def test_list_sessions(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_sessions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.ListSessionsResponse( - next_page_token='next_page_token_value', - ) - response = client.list_sessions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ListSessionsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListSessionsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_sessions_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_sessions), - '__call__') as call: - client.list_sessions() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ListSessionsRequest() - -@pytest.mark.asyncio -async def test_list_sessions_async(transport: str = 'grpc_asyncio', request_type=spanner.ListSessionsRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_sessions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner.ListSessionsResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_sessions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ListSessionsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListSessionsAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_sessions_async_from_dict(): - await test_list_sessions_async(request_type=dict) - - -def test_list_sessions_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.ListSessionsRequest() - - request.database = 'database_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_sessions), - '__call__') as call: - call.return_value = spanner.ListSessionsResponse() - client.list_sessions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'database=database_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_list_sessions_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.ListSessionsRequest() - - request.database = 'database_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_sessions), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.ListSessionsResponse()) - await client.list_sessions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'database=database_value', - ) in kw['metadata'] - - -def test_list_sessions_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_sessions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.ListSessionsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_sessions( - database='database_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].database - mock_val = 'database_value' - assert arg == mock_val - - -def test_list_sessions_flattened_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_sessions( - spanner.ListSessionsRequest(), - database='database_value', - ) - -@pytest.mark.asyncio -async def test_list_sessions_flattened_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_sessions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.ListSessionsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.ListSessionsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_sessions( - database='database_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].database - mock_val = 'database_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_list_sessions_flattened_error_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.list_sessions( - spanner.ListSessionsRequest(), - database='database_value', - ) - - -def test_list_sessions_pager(transport_name: str = "grpc"): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_sessions), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - spanner.Session(), - spanner.Session(), - ], - next_page_token='abc', - ), - spanner.ListSessionsResponse( - sessions=[], - next_page_token='def', - ), - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - ], - next_page_token='ghi', - ), - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - spanner.Session(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('database', ''), - )), - ) - pager = client.list_sessions(request={}) - - assert pager._metadata == metadata - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, spanner.Session) - for i in results) -def test_list_sessions_pages(transport_name: str = "grpc"): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_sessions), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - spanner.Session(), - spanner.Session(), - ], - next_page_token='abc', - ), - spanner.ListSessionsResponse( - sessions=[], - next_page_token='def', - ), - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - ], - next_page_token='ghi', - ), - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - spanner.Session(), - ], - ), - RuntimeError, - ) - pages = list(client.list_sessions(request={}).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.asyncio -async def test_list_sessions_async_pager(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_sessions), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - spanner.Session(), - spanner.Session(), - ], - next_page_token='abc', - ), - spanner.ListSessionsResponse( - sessions=[], - next_page_token='def', - ), - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - ], - next_page_token='ghi', - ), - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - spanner.Session(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_sessions(request={},) - assert async_pager.next_page_token == 'abc' - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, spanner.Session) - for i in responses) - - -@pytest.mark.asyncio -async def test_list_sessions_async_pages(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_sessions), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - spanner.Session(), - spanner.Session(), - ], - next_page_token='abc', - ), - spanner.ListSessionsResponse( - sessions=[], - next_page_token='def', - ), - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - ], - next_page_token='ghi', - ), - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - spanner.Session(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_sessions(request={})).pages: # pragma: no branch - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.parametrize("request_type", [ - spanner.DeleteSessionRequest, - dict, -]) -def test_delete_session(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_session), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_session(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.DeleteSessionRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_session_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_session), - '__call__') as call: - client.delete_session() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.DeleteSessionRequest() - -@pytest.mark.asyncio -async def test_delete_session_async(transport: str = 'grpc_asyncio', request_type=spanner.DeleteSessionRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_session), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_session(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.DeleteSessionRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_session_async_from_dict(): - await test_delete_session_async(request_type=dict) - - -def test_delete_session_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.DeleteSessionRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_session), - '__call__') as call: - call.return_value = None - client.delete_session(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_delete_session_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.DeleteSessionRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_session), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_session(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -def test_delete_session_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_session), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_session( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - - -def test_delete_session_flattened_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_session( - spanner.DeleteSessionRequest(), - name='name_value', - ) - -@pytest.mark.asyncio -async def test_delete_session_flattened_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_session), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_session( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_delete_session_flattened_error_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.delete_session( - spanner.DeleteSessionRequest(), - name='name_value', - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.ExecuteSqlRequest, - dict, -]) -def test_execute_sql(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_sql), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = result_set.ResultSet( - ) - response = client.execute_sql(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ExecuteSqlRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, result_set.ResultSet) - - -def test_execute_sql_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_sql), - '__call__') as call: - client.execute_sql() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ExecuteSqlRequest() - -@pytest.mark.asyncio -async def test_execute_sql_async(transport: str = 'grpc_asyncio', request_type=spanner.ExecuteSqlRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_sql), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(result_set.ResultSet( - )) - response = await client.execute_sql(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ExecuteSqlRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, result_set.ResultSet) - - -@pytest.mark.asyncio -async def test_execute_sql_async_from_dict(): - await test_execute_sql_async(request_type=dict) - - -def test_execute_sql_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.ExecuteSqlRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_sql), - '__call__') as call: - call.return_value = result_set.ResultSet() - client.execute_sql(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_execute_sql_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.ExecuteSqlRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_sql), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(result_set.ResultSet()) - await client.execute_sql(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.parametrize("request_type", [ - spanner.ExecuteSqlRequest, - dict, -]) -def test_execute_streaming_sql(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_streaming_sql), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = iter([result_set.PartialResultSet()]) - response = client.execute_streaming_sql(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ExecuteSqlRequest() - - # Establish that the response is the type that we expect. - for message in response: - assert isinstance(message, result_set.PartialResultSet) - - -def test_execute_streaming_sql_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_streaming_sql), - '__call__') as call: - client.execute_streaming_sql() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ExecuteSqlRequest() - -@pytest.mark.asyncio -async def test_execute_streaming_sql_async(transport: str = 'grpc_asyncio', request_type=spanner.ExecuteSqlRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_streaming_sql), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) - call.return_value.read = mock.AsyncMock(side_effect=[result_set.PartialResultSet()]) - response = await client.execute_streaming_sql(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ExecuteSqlRequest() - - # Establish that the response is the type that we expect. - message = await response.read() - assert isinstance(message, result_set.PartialResultSet) - - -@pytest.mark.asyncio -async def test_execute_streaming_sql_async_from_dict(): - await test_execute_streaming_sql_async(request_type=dict) - - -def test_execute_streaming_sql_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.ExecuteSqlRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_streaming_sql), - '__call__') as call: - call.return_value = iter([result_set.PartialResultSet()]) - client.execute_streaming_sql(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_execute_streaming_sql_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.ExecuteSqlRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_streaming_sql), - '__call__') as call: - call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) - call.return_value.read = mock.AsyncMock(side_effect=[result_set.PartialResultSet()]) - await client.execute_streaming_sql(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.parametrize("request_type", [ - spanner.ExecuteBatchDmlRequest, - dict, -]) -def test_execute_batch_dml(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_batch_dml), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.ExecuteBatchDmlResponse( - ) - response = client.execute_batch_dml(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ExecuteBatchDmlRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.ExecuteBatchDmlResponse) - - -def test_execute_batch_dml_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_batch_dml), - '__call__') as call: - client.execute_batch_dml() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ExecuteBatchDmlRequest() - -@pytest.mark.asyncio -async def test_execute_batch_dml_async(transport: str = 'grpc_asyncio', request_type=spanner.ExecuteBatchDmlRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_batch_dml), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner.ExecuteBatchDmlResponse( - )) - response = await client.execute_batch_dml(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ExecuteBatchDmlRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.ExecuteBatchDmlResponse) - - -@pytest.mark.asyncio -async def test_execute_batch_dml_async_from_dict(): - await test_execute_batch_dml_async(request_type=dict) - - -def test_execute_batch_dml_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.ExecuteBatchDmlRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_batch_dml), - '__call__') as call: - call.return_value = spanner.ExecuteBatchDmlResponse() - client.execute_batch_dml(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_execute_batch_dml_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.ExecuteBatchDmlRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.execute_batch_dml), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.ExecuteBatchDmlResponse()) - await client.execute_batch_dml(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.parametrize("request_type", [ - spanner.ReadRequest, - dict, -]) -def test_read(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.read), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = result_set.ResultSet( - ) - response = client.read(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ReadRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, result_set.ResultSet) - - -def test_read_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.read), - '__call__') as call: - client.read() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ReadRequest() - -@pytest.mark.asyncio -async def test_read_async(transport: str = 'grpc_asyncio', request_type=spanner.ReadRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.read), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(result_set.ResultSet( - )) - response = await client.read(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ReadRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, result_set.ResultSet) - - -@pytest.mark.asyncio -async def test_read_async_from_dict(): - await test_read_async(request_type=dict) - - -def test_read_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.ReadRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.read), - '__call__') as call: - call.return_value = result_set.ResultSet() - client.read(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_read_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.ReadRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.read), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(result_set.ResultSet()) - await client.read(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.parametrize("request_type", [ - spanner.ReadRequest, - dict, -]) -def test_streaming_read(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.streaming_read), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = iter([result_set.PartialResultSet()]) - response = client.streaming_read(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ReadRequest() - - # Establish that the response is the type that we expect. - for message in response: - assert isinstance(message, result_set.PartialResultSet) - - -def test_streaming_read_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.streaming_read), - '__call__') as call: - client.streaming_read() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ReadRequest() - -@pytest.mark.asyncio -async def test_streaming_read_async(transport: str = 'grpc_asyncio', request_type=spanner.ReadRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.streaming_read), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) - call.return_value.read = mock.AsyncMock(side_effect=[result_set.PartialResultSet()]) - response = await client.streaming_read(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.ReadRequest() - - # Establish that the response is the type that we expect. - message = await response.read() - assert isinstance(message, result_set.PartialResultSet) - - -@pytest.mark.asyncio -async def test_streaming_read_async_from_dict(): - await test_streaming_read_async(request_type=dict) - - -def test_streaming_read_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.ReadRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.streaming_read), - '__call__') as call: - call.return_value = iter([result_set.PartialResultSet()]) - client.streaming_read(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_streaming_read_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.ReadRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.streaming_read), - '__call__') as call: - call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) - call.return_value.read = mock.AsyncMock(side_effect=[result_set.PartialResultSet()]) - await client.streaming_read(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.parametrize("request_type", [ - spanner.BeginTransactionRequest, - dict, -]) -def test_begin_transaction(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.begin_transaction), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = transaction.Transaction( - id=b'id_blob', - ) - response = client.begin_transaction(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.BeginTransactionRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, transaction.Transaction) - assert response.id == b'id_blob' - - -def test_begin_transaction_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.begin_transaction), - '__call__') as call: - client.begin_transaction() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.BeginTransactionRequest() - -@pytest.mark.asyncio -async def test_begin_transaction_async(transport: str = 'grpc_asyncio', request_type=spanner.BeginTransactionRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.begin_transaction), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(transaction.Transaction( - id=b'id_blob', - )) - response = await client.begin_transaction(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.BeginTransactionRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, transaction.Transaction) - assert response.id == b'id_blob' - - -@pytest.mark.asyncio -async def test_begin_transaction_async_from_dict(): - await test_begin_transaction_async(request_type=dict) - - -def test_begin_transaction_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.BeginTransactionRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.begin_transaction), - '__call__') as call: - call.return_value = transaction.Transaction() - client.begin_transaction(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_begin_transaction_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.BeginTransactionRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.begin_transaction), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(transaction.Transaction()) - await client.begin_transaction(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -def test_begin_transaction_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.begin_transaction), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = transaction.Transaction() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.begin_transaction( - session='session_value', - options=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].session - mock_val = 'session_value' - assert arg == mock_val - arg = args[0].options - mock_val = transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)) - assert arg == mock_val - - -def test_begin_transaction_flattened_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.begin_transaction( - spanner.BeginTransactionRequest(), - session='session_value', - options=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), - ) - -@pytest.mark.asyncio -async def test_begin_transaction_flattened_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.begin_transaction), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = transaction.Transaction() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(transaction.Transaction()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.begin_transaction( - session='session_value', - options=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].session - mock_val = 'session_value' - assert arg == mock_val - arg = args[0].options - mock_val = transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)) - assert arg == mock_val - -@pytest.mark.asyncio -async def test_begin_transaction_flattened_error_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.begin_transaction( - spanner.BeginTransactionRequest(), - session='session_value', - options=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.CommitRequest, - dict, -]) -def test_commit(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.commit), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = commit_response.CommitResponse( - ) - response = client.commit(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.CommitRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, commit_response.CommitResponse) - - -def test_commit_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.commit), - '__call__') as call: - client.commit() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.CommitRequest() - -@pytest.mark.asyncio -async def test_commit_async(transport: str = 'grpc_asyncio', request_type=spanner.CommitRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.commit), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(commit_response.CommitResponse( - )) - response = await client.commit(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.CommitRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, commit_response.CommitResponse) - - -@pytest.mark.asyncio -async def test_commit_async_from_dict(): - await test_commit_async(request_type=dict) - - -def test_commit_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.CommitRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.commit), - '__call__') as call: - call.return_value = commit_response.CommitResponse() - client.commit(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_commit_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.CommitRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.commit), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(commit_response.CommitResponse()) - await client.commit(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -def test_commit_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.commit), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = commit_response.CommitResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.commit( - session='session_value', - transaction_id=b'transaction_id_blob', - mutations=[mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))], - single_use_transaction=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].session - mock_val = 'session_value' - assert arg == mock_val - arg = args[0].mutations - mock_val = [mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))] - assert arg == mock_val - assert args[0].single_use_transaction == transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)) - - -def test_commit_flattened_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.commit( - spanner.CommitRequest(), - session='session_value', - transaction_id=b'transaction_id_blob', - mutations=[mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))], - single_use_transaction=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), - ) - -@pytest.mark.asyncio -async def test_commit_flattened_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.commit), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = commit_response.CommitResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(commit_response.CommitResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.commit( - session='session_value', - transaction_id=b'transaction_id_blob', - mutations=[mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))], - single_use_transaction=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].session - mock_val = 'session_value' - assert arg == mock_val - arg = args[0].mutations - mock_val = [mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))] - assert arg == mock_val - assert args[0].single_use_transaction == transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)) - -@pytest.mark.asyncio -async def test_commit_flattened_error_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.commit( - spanner.CommitRequest(), - session='session_value', - transaction_id=b'transaction_id_blob', - mutations=[mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))], - single_use_transaction=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.RollbackRequest, - dict, -]) -def test_rollback(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.rollback), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.rollback(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.RollbackRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_rollback_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.rollback), - '__call__') as call: - client.rollback() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.RollbackRequest() - -@pytest.mark.asyncio -async def test_rollback_async(transport: str = 'grpc_asyncio', request_type=spanner.RollbackRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.rollback), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.rollback(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.RollbackRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_rollback_async_from_dict(): - await test_rollback_async(request_type=dict) - - -def test_rollback_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.RollbackRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.rollback), - '__call__') as call: - call.return_value = None - client.rollback(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_rollback_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.RollbackRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.rollback), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.rollback(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -def test_rollback_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.rollback), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.rollback( - session='session_value', - transaction_id=b'transaction_id_blob', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].session - mock_val = 'session_value' - assert arg == mock_val - arg = args[0].transaction_id - mock_val = b'transaction_id_blob' - assert arg == mock_val - - -def test_rollback_flattened_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.rollback( - spanner.RollbackRequest(), - session='session_value', - transaction_id=b'transaction_id_blob', - ) - -@pytest.mark.asyncio -async def test_rollback_flattened_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.rollback), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.rollback( - session='session_value', - transaction_id=b'transaction_id_blob', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].session - mock_val = 'session_value' - assert arg == mock_val - arg = args[0].transaction_id - mock_val = b'transaction_id_blob' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_rollback_flattened_error_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.rollback( - spanner.RollbackRequest(), - session='session_value', - transaction_id=b'transaction_id_blob', - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.PartitionQueryRequest, - dict, -]) -def test_partition_query(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.partition_query), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.PartitionResponse( - ) - response = client.partition_query(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.PartitionQueryRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.PartitionResponse) - - -def test_partition_query_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.partition_query), - '__call__') as call: - client.partition_query() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.PartitionQueryRequest() - -@pytest.mark.asyncio -async def test_partition_query_async(transport: str = 'grpc_asyncio', request_type=spanner.PartitionQueryRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.partition_query), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner.PartitionResponse( - )) - response = await client.partition_query(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.PartitionQueryRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.PartitionResponse) - - -@pytest.mark.asyncio -async def test_partition_query_async_from_dict(): - await test_partition_query_async(request_type=dict) - - -def test_partition_query_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.PartitionQueryRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.partition_query), - '__call__') as call: - call.return_value = spanner.PartitionResponse() - client.partition_query(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_partition_query_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.PartitionQueryRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.partition_query), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.PartitionResponse()) - await client.partition_query(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.parametrize("request_type", [ - spanner.PartitionReadRequest, - dict, -]) -def test_partition_read(request_type, transport: str = 'grpc'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.partition_read), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner.PartitionResponse( - ) - response = client.partition_read(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.PartitionReadRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.PartitionResponse) - - -def test_partition_read_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.partition_read), - '__call__') as call: - client.partition_read() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.PartitionReadRequest() - -@pytest.mark.asyncio -async def test_partition_read_async(transport: str = 'grpc_asyncio', request_type=spanner.PartitionReadRequest): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.partition_read), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner.PartitionResponse( - )) - response = await client.partition_read(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner.PartitionReadRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.PartitionResponse) - - -@pytest.mark.asyncio -async def test_partition_read_async_from_dict(): - await test_partition_read_async(request_type=dict) - - -def test_partition_read_field_headers(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.PartitionReadRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.partition_read), - '__call__') as call: - call.return_value = spanner.PartitionResponse() - client.partition_read(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_partition_read_field_headers_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner.PartitionReadRequest() - - request.session = 'session_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.partition_read), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner.PartitionResponse()) - await client.partition_read(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'session=session_value', - ) in kw['metadata'] - - -@pytest.mark.parametrize("request_type", [ - spanner.CreateSessionRequest, - dict, -]) -def test_create_session_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner.Session( - name='name_value', - creator_role='creator_role_value', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner.Session.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.create_session(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.Session) - assert response.name == 'name_value' - assert response.creator_role == 'creator_role_value' - - -def test_create_session_rest_required_fields(request_type=spanner.CreateSessionRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["database"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_session._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["database"] = 'database_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_session._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "database" in jsonified_request - assert jsonified_request["database"] == 'database_value' - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner.Session() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner.Session.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.create_session(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_create_session_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.create_session._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("database", "session", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_session_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "post_create_session") as post, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_create_session") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner.CreateSessionRequest.pb(spanner.CreateSessionRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner.Session.to_json(spanner.Session()) - - request = spanner.CreateSessionRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner.Session() - - client.create_session(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_create_session_rest_bad_request(transport: str = 'rest', request_type=spanner.CreateSessionRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.create_session(request) - - -def test_create_session_rest_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner.Session() - - # get arguments that satisfy an http rule for this method - sample_request = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - - # get truthy value for each flattened field - mock_args = dict( - database='database_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner.Session.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.create_session(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{database=projects/*/instances/*/databases/*}/sessions" % client.transport._host, args[1]) - - -def test_create_session_rest_flattened_error(transport: str = 'rest'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_session( - spanner.CreateSessionRequest(), - database='database_value', - ) - - -def test_create_session_rest_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.BatchCreateSessionsRequest, - dict, -]) -def test_batch_create_sessions_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner.BatchCreateSessionsResponse( - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner.BatchCreateSessionsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.batch_create_sessions(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.BatchCreateSessionsResponse) - - -def test_batch_create_sessions_rest_required_fields(request_type=spanner.BatchCreateSessionsRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["database"] = "" - request_init["session_count"] = 0 - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).batch_create_sessions._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["database"] = 'database_value' - jsonified_request["sessionCount"] = 1420 - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).batch_create_sessions._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "database" in jsonified_request - assert jsonified_request["database"] == 'database_value' - assert "sessionCount" in jsonified_request - assert jsonified_request["sessionCount"] == 1420 - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner.BatchCreateSessionsResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner.BatchCreateSessionsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.batch_create_sessions(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_batch_create_sessions_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.batch_create_sessions._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("database", "sessionCount", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_batch_create_sessions_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "post_batch_create_sessions") as post, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_batch_create_sessions") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner.BatchCreateSessionsRequest.pb(spanner.BatchCreateSessionsRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner.BatchCreateSessionsResponse.to_json(spanner.BatchCreateSessionsResponse()) - - request = spanner.BatchCreateSessionsRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner.BatchCreateSessionsResponse() - - client.batch_create_sessions(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_batch_create_sessions_rest_bad_request(transport: str = 'rest', request_type=spanner.BatchCreateSessionsRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.batch_create_sessions(request) - - -def test_batch_create_sessions_rest_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner.BatchCreateSessionsResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - - # get truthy value for each flattened field - mock_args = dict( - database='database_value', - session_count=1420, - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner.BatchCreateSessionsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.batch_create_sessions(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{database=projects/*/instances/*/databases/*}/sessions:batchCreate" % client.transport._host, args[1]) - - -def test_batch_create_sessions_rest_flattened_error(transport: str = 'rest'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.batch_create_sessions( - spanner.BatchCreateSessionsRequest(), - database='database_value', - session_count=1420, - ) - - -def test_batch_create_sessions_rest_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.GetSessionRequest, - dict, -]) -def test_get_session_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner.Session( - name='name_value', - creator_role='creator_role_value', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner.Session.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.get_session(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.Session) - assert response.name == 'name_value' - assert response.creator_role == 'creator_role_value' - - -def test_get_session_rest_required_fields(request_type=spanner.GetSessionRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["name"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_session._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["name"] = 'name_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_session._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == 'name_value' - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner.Session() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner.Session.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.get_session(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_get_session_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.get_session._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_session_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "post_get_session") as post, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_get_session") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner.GetSessionRequest.pb(spanner.GetSessionRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner.Session.to_json(spanner.Session()) - - request = spanner.GetSessionRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner.Session() - - client.get_session(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_get_session_rest_bad_request(transport: str = 'rest', request_type=spanner.GetSessionRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.get_session(request) - - -def test_get_session_rest_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner.Session() - - # get arguments that satisfy an http rule for this method - sample_request = {'name': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - - # get truthy value for each flattened field - mock_args = dict( - name='name_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner.Session.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.get_session(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{name=projects/*/instances/*/databases/*/sessions/*}" % client.transport._host, args[1]) - - -def test_get_session_rest_flattened_error(transport: str = 'rest'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_session( - spanner.GetSessionRequest(), - name='name_value', - ) - - -def test_get_session_rest_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.ListSessionsRequest, - dict, -]) -def test_list_sessions_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner.ListSessionsResponse( - next_page_token='next_page_token_value', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner.ListSessionsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.list_sessions(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListSessionsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_sessions_rest_required_fields(request_type=spanner.ListSessionsRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["database"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_sessions._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["database"] = 'database_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_sessions._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("filter", "page_size", "page_token", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "database" in jsonified_request - assert jsonified_request["database"] == 'database_value' - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner.ListSessionsResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner.ListSessionsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.list_sessions(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_list_sessions_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.list_sessions._get_unset_required_fields({}) - assert set(unset_fields) == (set(("filter", "pageSize", "pageToken", )) & set(("database", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_sessions_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "post_list_sessions") as post, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_list_sessions") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner.ListSessionsRequest.pb(spanner.ListSessionsRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner.ListSessionsResponse.to_json(spanner.ListSessionsResponse()) - - request = spanner.ListSessionsRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner.ListSessionsResponse() - - client.list_sessions(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_list_sessions_rest_bad_request(transport: str = 'rest', request_type=spanner.ListSessionsRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.list_sessions(request) - - -def test_list_sessions_rest_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner.ListSessionsResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - - # get truthy value for each flattened field - mock_args = dict( - database='database_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner.ListSessionsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.list_sessions(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{database=projects/*/instances/*/databases/*}/sessions" % client.transport._host, args[1]) - - -def test_list_sessions_rest_flattened_error(transport: str = 'rest'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_sessions( - spanner.ListSessionsRequest(), - database='database_value', - ) - - -def test_list_sessions_rest_pager(transport: str = 'rest'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - #with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - spanner.Session(), - spanner.Session(), - ], - next_page_token='abc', - ), - spanner.ListSessionsResponse( - sessions=[], - next_page_token='def', - ), - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - ], - next_page_token='ghi', - ), - spanner.ListSessionsResponse( - sessions=[ - spanner.Session(), - spanner.Session(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(spanner.ListSessionsResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode('UTF-8') - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - - pager = client.list_sessions(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, spanner.Session) - for i in results) - - pages = list(client.list_sessions(request=sample_request).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.parametrize("request_type", [ - spanner.DeleteSessionRequest, - dict, -]) -def test_delete_session_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.delete_session(request) - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_session_rest_required_fields(request_type=spanner.DeleteSessionRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["name"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_session._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["name"] = 'name_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_session._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == 'name_value' - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = None - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "delete", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.delete_session(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_delete_session_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.delete_session._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_session_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_delete_session") as pre: - pre.assert_not_called() - pb_message = spanner.DeleteSessionRequest.pb(spanner.DeleteSessionRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - - request = spanner.DeleteSessionRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - - client.delete_session(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - - -def test_delete_session_rest_bad_request(transport: str = 'rest', request_type=spanner.DeleteSessionRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.delete_session(request) - - -def test_delete_session_rest_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # get arguments that satisfy an http rule for this method - sample_request = {'name': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - - # get truthy value for each flattened field - mock_args = dict( - name='name_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.delete_session(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{name=projects/*/instances/*/databases/*/sessions/*}" % client.transport._host, args[1]) - - -def test_delete_session_rest_flattened_error(transport: str = 'rest'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_session( - spanner.DeleteSessionRequest(), - name='name_value', - ) - - -def test_delete_session_rest_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.ExecuteSqlRequest, - dict, -]) -def test_execute_sql_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = result_set.ResultSet( - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = result_set.ResultSet.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.execute_sql(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, result_set.ResultSet) - - -def test_execute_sql_rest_required_fields(request_type=spanner.ExecuteSqlRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["session"] = "" - request_init["sql"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).execute_sql._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["session"] = 'session_value' - jsonified_request["sql"] = 'sql_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).execute_sql._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "session" in jsonified_request - assert jsonified_request["session"] == 'session_value' - assert "sql" in jsonified_request - assert jsonified_request["sql"] == 'sql_value' - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = result_set.ResultSet() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = result_set.ResultSet.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.execute_sql(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_execute_sql_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.execute_sql._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("session", "sql", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_execute_sql_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "post_execute_sql") as post, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_execute_sql") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner.ExecuteSqlRequest.pb(spanner.ExecuteSqlRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = result_set.ResultSet.to_json(result_set.ResultSet()) - - request = spanner.ExecuteSqlRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = result_set.ResultSet() - - client.execute_sql(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_execute_sql_rest_bad_request(transport: str = 'rest', request_type=spanner.ExecuteSqlRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.execute_sql(request) - - -def test_execute_sql_rest_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.ExecuteSqlRequest, - dict, -]) -def test_execute_streaming_sql_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = result_set.PartialResultSet( - chunked_value=True, - resume_token=b'resume_token_blob', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = result_set.PartialResultSet.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - json_return_value = "[{}]".format(json_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - with mock.patch.object(response_value, 'iter_content') as iter_content: - iter_content.return_value = iter(json_return_value) - response = client.execute_streaming_sql(request) - - assert isinstance(response, Iterable) - response = next(response) - - # Establish that the response is the type that we expect. - assert isinstance(response, result_set.PartialResultSet) - assert response.chunked_value is True - assert response.resume_token == b'resume_token_blob' - - -def test_execute_streaming_sql_rest_required_fields(request_type=spanner.ExecuteSqlRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["session"] = "" - request_init["sql"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).execute_streaming_sql._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["session"] = 'session_value' - jsonified_request["sql"] = 'sql_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).execute_streaming_sql._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "session" in jsonified_request - assert jsonified_request["session"] == 'session_value' - assert "sql" in jsonified_request - assert jsonified_request["sql"] == 'sql_value' - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = result_set.PartialResultSet() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = result_set.PartialResultSet.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - json_return_value = "[{}]".format(json_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - with mock.patch.object(response_value, 'iter_content') as iter_content: - iter_content.return_value = iter(json_return_value) - response = client.execute_streaming_sql(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_execute_streaming_sql_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.execute_streaming_sql._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("session", "sql", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_execute_streaming_sql_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "post_execute_streaming_sql") as post, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_execute_streaming_sql") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner.ExecuteSqlRequest.pb(spanner.ExecuteSqlRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = result_set.PartialResultSet.to_json(result_set.PartialResultSet()) - req.return_value._content = "[{}]".format(req.return_value._content) - - request = spanner.ExecuteSqlRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = result_set.PartialResultSet() - - client.execute_streaming_sql(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_execute_streaming_sql_rest_bad_request(transport: str = 'rest', request_type=spanner.ExecuteSqlRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.execute_streaming_sql(request) - - -def test_execute_streaming_sql_rest_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.ExecuteBatchDmlRequest, - dict, -]) -def test_execute_batch_dml_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner.ExecuteBatchDmlResponse( - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner.ExecuteBatchDmlResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.execute_batch_dml(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.ExecuteBatchDmlResponse) - - -def test_execute_batch_dml_rest_required_fields(request_type=spanner.ExecuteBatchDmlRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["session"] = "" - request_init["seqno"] = 0 - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).execute_batch_dml._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["session"] = 'session_value' - jsonified_request["seqno"] = 550 - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).execute_batch_dml._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "session" in jsonified_request - assert jsonified_request["session"] == 'session_value' - assert "seqno" in jsonified_request - assert jsonified_request["seqno"] == 550 - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner.ExecuteBatchDmlResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner.ExecuteBatchDmlResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.execute_batch_dml(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_execute_batch_dml_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.execute_batch_dml._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("session", "transaction", "statements", "seqno", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_execute_batch_dml_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "post_execute_batch_dml") as post, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_execute_batch_dml") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner.ExecuteBatchDmlRequest.pb(spanner.ExecuteBatchDmlRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner.ExecuteBatchDmlResponse.to_json(spanner.ExecuteBatchDmlResponse()) - - request = spanner.ExecuteBatchDmlRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner.ExecuteBatchDmlResponse() - - client.execute_batch_dml(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_execute_batch_dml_rest_bad_request(transport: str = 'rest', request_type=spanner.ExecuteBatchDmlRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.execute_batch_dml(request) - - -def test_execute_batch_dml_rest_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.ReadRequest, - dict, -]) -def test_read_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = result_set.ResultSet( - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = result_set.ResultSet.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.read(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, result_set.ResultSet) - - -def test_read_rest_required_fields(request_type=spanner.ReadRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["session"] = "" - request_init["table"] = "" - request_init["columns"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).read._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["session"] = 'session_value' - jsonified_request["table"] = 'table_value' - jsonified_request["columns"] = 'columns_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).read._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "session" in jsonified_request - assert jsonified_request["session"] == 'session_value' - assert "table" in jsonified_request - assert jsonified_request["table"] == 'table_value' - assert "columns" in jsonified_request - assert jsonified_request["columns"] == 'columns_value' - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = result_set.ResultSet() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = result_set.ResultSet.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.read(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_read_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.read._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("session", "table", "columns", "keySet", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_read_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "post_read") as post, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_read") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner.ReadRequest.pb(spanner.ReadRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = result_set.ResultSet.to_json(result_set.ResultSet()) - - request = spanner.ReadRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = result_set.ResultSet() - - client.read(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_read_rest_bad_request(transport: str = 'rest', request_type=spanner.ReadRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.read(request) - - -def test_read_rest_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.ReadRequest, - dict, -]) -def test_streaming_read_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = result_set.PartialResultSet( - chunked_value=True, - resume_token=b'resume_token_blob', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = result_set.PartialResultSet.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - json_return_value = "[{}]".format(json_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - with mock.patch.object(response_value, 'iter_content') as iter_content: - iter_content.return_value = iter(json_return_value) - response = client.streaming_read(request) - - assert isinstance(response, Iterable) - response = next(response) - - # Establish that the response is the type that we expect. - assert isinstance(response, result_set.PartialResultSet) - assert response.chunked_value is True - assert response.resume_token == b'resume_token_blob' - - -def test_streaming_read_rest_required_fields(request_type=spanner.ReadRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["session"] = "" - request_init["table"] = "" - request_init["columns"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).streaming_read._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["session"] = 'session_value' - jsonified_request["table"] = 'table_value' - jsonified_request["columns"] = 'columns_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).streaming_read._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "session" in jsonified_request - assert jsonified_request["session"] == 'session_value' - assert "table" in jsonified_request - assert jsonified_request["table"] == 'table_value' - assert "columns" in jsonified_request - assert jsonified_request["columns"] == 'columns_value' - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = result_set.PartialResultSet() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = result_set.PartialResultSet.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - json_return_value = "[{}]".format(json_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - with mock.patch.object(response_value, 'iter_content') as iter_content: - iter_content.return_value = iter(json_return_value) - response = client.streaming_read(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_streaming_read_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.streaming_read._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("session", "table", "columns", "keySet", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_streaming_read_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "post_streaming_read") as post, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_streaming_read") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner.ReadRequest.pb(spanner.ReadRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = result_set.PartialResultSet.to_json(result_set.PartialResultSet()) - req.return_value._content = "[{}]".format(req.return_value._content) - - request = spanner.ReadRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = result_set.PartialResultSet() - - client.streaming_read(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_streaming_read_rest_bad_request(transport: str = 'rest', request_type=spanner.ReadRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.streaming_read(request) - - -def test_streaming_read_rest_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.BeginTransactionRequest, - dict, -]) -def test_begin_transaction_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = transaction.Transaction( - id=b'id_blob', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = transaction.Transaction.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.begin_transaction(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, transaction.Transaction) - assert response.id == b'id_blob' - - -def test_begin_transaction_rest_required_fields(request_type=spanner.BeginTransactionRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["session"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).begin_transaction._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["session"] = 'session_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).begin_transaction._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "session" in jsonified_request - assert jsonified_request["session"] == 'session_value' - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = transaction.Transaction() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = transaction.Transaction.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.begin_transaction(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_begin_transaction_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.begin_transaction._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("session", "options", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_begin_transaction_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "post_begin_transaction") as post, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_begin_transaction") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner.BeginTransactionRequest.pb(spanner.BeginTransactionRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = transaction.Transaction.to_json(transaction.Transaction()) - - request = spanner.BeginTransactionRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = transaction.Transaction() - - client.begin_transaction(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_begin_transaction_rest_bad_request(transport: str = 'rest', request_type=spanner.BeginTransactionRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.begin_transaction(request) - - -def test_begin_transaction_rest_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = transaction.Transaction() - - # get arguments that satisfy an http rule for this method - sample_request = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - - # get truthy value for each flattened field - mock_args = dict( - session='session_value', - options=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = transaction.Transaction.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.begin_transaction(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{session=projects/*/instances/*/databases/*/sessions/*}:beginTransaction" % client.transport._host, args[1]) - - -def test_begin_transaction_rest_flattened_error(transport: str = 'rest'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.begin_transaction( - spanner.BeginTransactionRequest(), - session='session_value', - options=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), - ) - - -def test_begin_transaction_rest_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.CommitRequest, - dict, -]) -def test_commit_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = commit_response.CommitResponse( - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = commit_response.CommitResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.commit(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, commit_response.CommitResponse) - - -def test_commit_rest_required_fields(request_type=spanner.CommitRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["session"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).commit._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["session"] = 'session_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).commit._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "session" in jsonified_request - assert jsonified_request["session"] == 'session_value' - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = commit_response.CommitResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = commit_response.CommitResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.commit(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_commit_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.commit._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("session", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_commit_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "post_commit") as post, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_commit") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner.CommitRequest.pb(spanner.CommitRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = commit_response.CommitResponse.to_json(commit_response.CommitResponse()) - - request = spanner.CommitRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = commit_response.CommitResponse() - - client.commit(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_commit_rest_bad_request(transport: str = 'rest', request_type=spanner.CommitRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.commit(request) - - -def test_commit_rest_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = commit_response.CommitResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - - # get truthy value for each flattened field - mock_args = dict( - session='session_value', - mutations=[mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))], - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = commit_response.CommitResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.commit(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{session=projects/*/instances/*/databases/*/sessions/*}:commit" % client.transport._host, args[1]) - - -def test_commit_rest_flattened_error(transport: str = 'rest'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.commit( - spanner.CommitRequest(), - session='session_value', - transaction_id=b'transaction_id_blob', - mutations=[mutation.Mutation(insert=mutation.Mutation.Write(table='table_value'))], - single_use_transaction=transaction.TransactionOptions(read_write=transaction.TransactionOptions.ReadWrite(read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC)), - ) - - -def test_commit_rest_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.RollbackRequest, - dict, -]) -def test_rollback_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.rollback(request) - - # Establish that the response is the type that we expect. - assert response is None - - -def test_rollback_rest_required_fields(request_type=spanner.RollbackRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["session"] = "" - request_init["transaction_id"] = b'' - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).rollback._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["session"] = 'session_value' - jsonified_request["transactionId"] = b'transaction_id_blob' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).rollback._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "session" in jsonified_request - assert jsonified_request["session"] == 'session_value' - assert "transactionId" in jsonified_request - assert jsonified_request["transactionId"] == b'transaction_id_blob' - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = None - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.rollback(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_rollback_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.rollback._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("session", "transactionId", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_rollback_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_rollback") as pre: - pre.assert_not_called() - pb_message = spanner.RollbackRequest.pb(spanner.RollbackRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - - request = spanner.RollbackRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - - client.rollback(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - - -def test_rollback_rest_bad_request(transport: str = 'rest', request_type=spanner.RollbackRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.rollback(request) - - -def test_rollback_rest_flattened(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # get arguments that satisfy an http rule for this method - sample_request = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - - # get truthy value for each flattened field - mock_args = dict( - session='session_value', - transaction_id=b'transaction_id_blob', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.rollback(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{session=projects/*/instances/*/databases/*/sessions/*}:rollback" % client.transport._host, args[1]) - - -def test_rollback_rest_flattened_error(transport: str = 'rest'): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.rollback( - spanner.RollbackRequest(), - session='session_value', - transaction_id=b'transaction_id_blob', - ) - - -def test_rollback_rest_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.PartitionQueryRequest, - dict, -]) -def test_partition_query_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner.PartitionResponse( - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner.PartitionResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.partition_query(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.PartitionResponse) - - -def test_partition_query_rest_required_fields(request_type=spanner.PartitionQueryRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["session"] = "" - request_init["sql"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).partition_query._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["session"] = 'session_value' - jsonified_request["sql"] = 'sql_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).partition_query._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "session" in jsonified_request - assert jsonified_request["session"] == 'session_value' - assert "sql" in jsonified_request - assert jsonified_request["sql"] == 'sql_value' - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner.PartitionResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner.PartitionResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.partition_query(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_partition_query_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.partition_query._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("session", "sql", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_partition_query_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "post_partition_query") as post, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_partition_query") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner.PartitionQueryRequest.pb(spanner.PartitionQueryRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner.PartitionResponse.to_json(spanner.PartitionResponse()) - - request = spanner.PartitionQueryRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner.PartitionResponse() - - client.partition_query(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_partition_query_rest_bad_request(transport: str = 'rest', request_type=spanner.PartitionQueryRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.partition_query(request) - - -def test_partition_query_rest_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner.PartitionReadRequest, - dict, -]) -def test_partition_read_rest(request_type): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner.PartitionResponse( - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner.PartitionResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.partition_read(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner.PartitionResponse) - - -def test_partition_read_rest_required_fields(request_type=spanner.PartitionReadRequest): - transport_class = transports.SpannerRestTransport - - request_init = {} - request_init["session"] = "" - request_init["table"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).partition_read._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["session"] = 'session_value' - jsonified_request["table"] = 'table_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).partition_read._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "session" in jsonified_request - assert jsonified_request["session"] == 'session_value' - assert "table" in jsonified_request - assert jsonified_request["table"] == 'table_value' - - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner.PartitionResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner.PartitionResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.partition_read(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_partition_read_rest_unset_required_fields(): - transport = transports.SpannerRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.partition_read._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("session", "table", "keySet", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_partition_read_rest_interceptors(null_interceptor): - transport = transports.SpannerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.SpannerRestInterceptor(), - ) - client = SpannerClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.SpannerRestInterceptor, "post_partition_read") as post, \ - mock.patch.object(transports.SpannerRestInterceptor, "pre_partition_read") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner.PartitionReadRequest.pb(spanner.PartitionReadRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner.PartitionResponse.to_json(spanner.PartitionResponse()) - - request = spanner.PartitionReadRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner.PartitionResponse() - - client.partition_read(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_partition_read_rest_bad_request(transport: str = 'rest', request_type=spanner.PartitionReadRequest): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'session': 'projects/sample1/instances/sample2/databases/sample3/sessions/sample4'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.partition_read(request) - - -def test_partition_read_rest_error(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.SpannerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.SpannerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = SpannerClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide an api_key and a transport instance. - transport = transports.SpannerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - options = client_options.ClientOptions() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = SpannerClient( - client_options=options, - transport=transport, - ) - - # It is an error to provide an api_key and a credential. - options = mock.Mock() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = SpannerClient( - client_options=options, - credentials=ga_credentials.AnonymousCredentials() - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.SpannerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = SpannerClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.SpannerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = SpannerClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.SpannerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.SpannerGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.SpannerGrpcTransport, - transports.SpannerGrpcAsyncIOTransport, - transports.SpannerRestTransport, -]) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() - -@pytest.mark.parametrize("transport_name", [ - "grpc", - "rest", -]) -def test_transport_kind(transport_name): - transport = SpannerClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert transport.kind == transport_name - -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.SpannerGrpcTransport, - ) - -def test_spanner_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.SpannerTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_spanner_base_transport(): - # Instantiate the base transport. - with mock.patch('google.cloud.spanner_v1.services.spanner.transports.SpannerTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.SpannerTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'create_session', - 'batch_create_sessions', - 'get_session', - 'list_sessions', - 'delete_session', - 'execute_sql', - 'execute_streaming_sql', - 'execute_batch_dml', - 'read', - 'streaming_read', - 'begin_transaction', - 'commit', - 'rollback', - 'partition_query', - 'partition_read', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - with pytest.raises(NotImplementedError): - transport.close() - - # Catch all for all remaining methods and properties - remainder = [ - 'kind', - ] - for r in remainder: - with pytest.raises(NotImplementedError): - getattr(transport, r)() - - -def test_spanner_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file - with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.spanner_v1.services.spanner.transports.SpannerTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SpannerTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.data', -), - quota_project_id="octopus", - ) - - -def test_spanner_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.cloud.spanner_v1.services.spanner.transports.SpannerTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SpannerTransport() - adc.assert_called_once() - - -def test_spanner_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - SpannerClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.data', -), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.SpannerGrpcTransport, - transports.SpannerGrpcAsyncIOTransport, - ], -) -def test_spanner_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/spanner.data',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.SpannerGrpcTransport, - transports.SpannerGrpcAsyncIOTransport, - transports.SpannerRestTransport, - ], -) -def test_spanner_transport_auth_gdch_credentials(transport_class): - host = 'https://language.com' - api_audience_tests = [None, 'https://language2.com'] - api_audience_expect = [host, 'https://language2.com'] - for t, e in zip(api_audience_tests, api_audience_expect): - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - gdch_mock = mock.MagicMock() - type(gdch_mock).with_gdch_audience = mock.PropertyMock(return_value=gdch_mock) - adc.return_value = (gdch_mock, None) - transport_class(host=host, api_audience=t) - gdch_mock.with_gdch_audience.assert_called_once_with( - e - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.SpannerGrpcTransport, grpc_helpers), - (transports.SpannerGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_spanner_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class( - quota_project_id="octopus", - scopes=["1", "2"] - ) - - create_channel.assert_called_with( - "spanner.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.data', -), - scopes=["1", "2"], - default_host="spanner.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.SpannerGrpcTransport, transports.SpannerGrpcAsyncIOTransport]) -def test_spanner_grpc_transport_client_cert_source_for_mtls( - transport_class -): - cred = ga_credentials.AnonymousCredentials() - - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds - ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback - ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, - private_key=expected_key - ) - -def test_spanner_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() - with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel") as mock_configure_mtls_channel: - transports.SpannerRestTransport ( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback - ) - mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) - - -@pytest.mark.parametrize("transport_name", [ - "grpc", - "grpc_asyncio", - "rest", -]) -def test_spanner_host_no_port(transport_name): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='spanner.googleapis.com'), - transport=transport_name, - ) - assert client.transport._host == ( - 'spanner.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else 'https://spanner.googleapis.com' - ) - -@pytest.mark.parametrize("transport_name", [ - "grpc", - "grpc_asyncio", - "rest", -]) -def test_spanner_host_with_port(transport_name): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='spanner.googleapis.com:8000'), - transport=transport_name, - ) - assert client.transport._host == ( - 'spanner.googleapis.com:8000' - if transport_name in ['grpc', 'grpc_asyncio'] - else 'https://spanner.googleapis.com:8000' - ) - -@pytest.mark.parametrize("transport_name", [ - "rest", -]) -def test_spanner_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() - client1 = SpannerClient( - credentials=creds1, - transport=transport_name, - ) - client2 = SpannerClient( - credentials=creds2, - transport=transport_name, - ) - session1 = client1.transport.create_session._session - session2 = client2.transport.create_session._session - assert session1 != session2 - session1 = client1.transport.batch_create_sessions._session - session2 = client2.transport.batch_create_sessions._session - assert session1 != session2 - session1 = client1.transport.get_session._session - session2 = client2.transport.get_session._session - assert session1 != session2 - session1 = client1.transport.list_sessions._session - session2 = client2.transport.list_sessions._session - assert session1 != session2 - session1 = client1.transport.delete_session._session - session2 = client2.transport.delete_session._session - assert session1 != session2 - session1 = client1.transport.execute_sql._session - session2 = client2.transport.execute_sql._session - assert session1 != session2 - session1 = client1.transport.execute_streaming_sql._session - session2 = client2.transport.execute_streaming_sql._session - assert session1 != session2 - session1 = client1.transport.execute_batch_dml._session - session2 = client2.transport.execute_batch_dml._session - assert session1 != session2 - session1 = client1.transport.read._session - session2 = client2.transport.read._session - assert session1 != session2 - session1 = client1.transport.streaming_read._session - session2 = client2.transport.streaming_read._session - assert session1 != session2 - session1 = client1.transport.begin_transaction._session - session2 = client2.transport.begin_transaction._session - assert session1 != session2 - session1 = client1.transport.commit._session - session2 = client2.transport.commit._session - assert session1 != session2 - session1 = client1.transport.rollback._session - session2 = client2.transport.rollback._session - assert session1 != session2 - session1 = client1.transport.partition_query._session - session2 = client2.transport.partition_query._session - assert session1 != session2 - session1 = client1.transport.partition_read._session - session2 = client2.transport.partition_read._session - assert session1 != session2 -def test_spanner_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.SpannerGrpcTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -def test_spanner_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.SpannerGrpcAsyncIOTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.SpannerGrpcTransport, transports.SpannerGrpcAsyncIOTransport]) -def test_spanner_transport_channel_mtls_with_client_cert_source( - transport_class -): - with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() - - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.SpannerGrpcTransport, transports.SpannerGrpcAsyncIOTransport]) -def test_spanner_transport_channel_mtls_with_adc( - transport_class -): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() - - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) - - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - - -def test_database_path(): - project = "squid" - instance = "clam" - database = "whelk" - expected = "projects/{project}/instances/{instance}/databases/{database}".format(project=project, instance=instance, database=database, ) - actual = SpannerClient.database_path(project, instance, database) - assert expected == actual - - -def test_parse_database_path(): - expected = { - "project": "octopus", - "instance": "oyster", - "database": "nudibranch", - } - path = SpannerClient.database_path(**expected) - - # Check that the path construction is reversible. - actual = SpannerClient.parse_database_path(path) - assert expected == actual - -def test_session_path(): - project = "cuttlefish" - instance = "mussel" - database = "winkle" - session = "nautilus" - expected = "projects/{project}/instances/{instance}/databases/{database}/sessions/{session}".format(project=project, instance=instance, database=database, session=session, ) - actual = SpannerClient.session_path(project, instance, database, session) - assert expected == actual - - -def test_parse_session_path(): - expected = { - "project": "scallop", - "instance": "abalone", - "database": "squid", - "session": "clam", - } - path = SpannerClient.session_path(**expected) - - # Check that the path construction is reversible. - actual = SpannerClient.parse_session_path(path) - assert expected == actual - -def test_common_billing_account_path(): - billing_account = "whelk" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = SpannerClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "octopus", - } - path = SpannerClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = SpannerClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "oyster" - expected = "folders/{folder}".format(folder=folder, ) - actual = SpannerClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "nudibranch", - } - path = SpannerClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = SpannerClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "cuttlefish" - expected = "organizations/{organization}".format(organization=organization, ) - actual = SpannerClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "mussel", - } - path = SpannerClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = SpannerClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "winkle" - expected = "projects/{project}".format(project=project, ) - actual = SpannerClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "nautilus", - } - path = SpannerClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = SpannerClient.parse_common_project_path(path) - assert expected == actual - -def test_common_location_path(): - project = "scallop" - location = "abalone" - expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) - actual = SpannerClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "squid", - "location": "clam", - } - path = SpannerClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = SpannerClient.parse_common_location_path(path) - assert expected == actual - - -def test_client_with_default_client_info(): - client_info = gapic_v1.client_info.ClientInfo() - - with mock.patch.object(transports.SpannerTransport, '_prep_wrapped_messages') as prep: - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.SpannerTransport, '_prep_wrapped_messages') as prep: - transport_class = SpannerClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - -@pytest.mark.asyncio -async def test_transport_close_async(): - client = SpannerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc_asyncio", - ) - with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: - async with client: - close.assert_not_called() - close.assert_called_once() - - -def test_transport_close(): - transports = { - "rest": "_session", - "grpc": "_grpc_channel", - } - - for transport, close_name in transports.items(): - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - -def test_client_ctx(): - transports = [ - 'rest', - 'grpc', - ] - for transport in transports: - client = SpannerClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - # Test client calls underlying transport. - with mock.patch.object(type(client.transport), "close") as close: - close.assert_not_called() - with client: - pass - close.assert_called() - -@pytest.mark.parametrize("client_class,transport_class", [ - (SpannerClient, transports.SpannerGrpcTransport), - (SpannerAsyncClient, transports.SpannerGrpcAsyncIOTransport), -]) -def test_api_key_credentials(client_class, transport_class): - with mock.patch.object( - google.auth._default, "get_api_key_credentials", create=True - ) as get_api_key_credentials: - mock_cred = mock.Mock() - get_api_key_credentials.return_value = mock_cred - options = client_options.ClientOptions() - options.api_key = "api_key" - with mock.patch.object(transport_class, "__init__") as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=mock_cred, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) diff --git a/owl-bot-staging/spanner_admin_database/v1/.coveragerc b/owl-bot-staging/spanner_admin_database/v1/.coveragerc deleted file mode 100644 index 6085d54da4..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/.coveragerc +++ /dev/null @@ -1,13 +0,0 @@ -[run] -branch = True - -[report] -show_missing = True -omit = - google/cloud/spanner_admin_database/__init__.py - google/cloud/spanner_admin_database/gapic_version.py -exclude_lines = - # Re-enable the standard pragma - pragma: NO COVER - # Ignore debug-only repr - def __repr__ diff --git a/owl-bot-staging/spanner_admin_database/v1/.flake8 b/owl-bot-staging/spanner_admin_database/v1/.flake8 deleted file mode 100644 index 29227d4cf4..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/.flake8 +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Generated by synthtool. DO NOT EDIT! -[flake8] -ignore = E203, E266, E501, W503 -exclude = - # Exclude generated code. - **/proto/** - **/gapic/** - **/services/** - **/types/** - *_pb2.py - - # Standard linting exemptions. - **/.nox/** - __pycache__, - .git, - *.pyc, - conf.py diff --git a/owl-bot-staging/spanner_admin_database/v1/MANIFEST.in b/owl-bot-staging/spanner_admin_database/v1/MANIFEST.in deleted file mode 100644 index 550e337e01..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include google/cloud/spanner_admin_database *.py -recursive-include google/cloud/spanner_admin_database_v1 *.py diff --git a/owl-bot-staging/spanner_admin_database/v1/README.rst b/owl-bot-staging/spanner_admin_database/v1/README.rst deleted file mode 100644 index 12e0ba69de..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/README.rst +++ /dev/null @@ -1,49 +0,0 @@ -Python Client for Google Cloud Spanner Admin Database API -================================================= - -Quick Start ------------ - -In order to use this library, you first need to go through the following steps: - -1. `Select or create a Cloud Platform project.`_ -2. `Enable billing for your project.`_ -3. Enable the Google Cloud Spanner Admin Database API. -4. `Setup Authentication.`_ - -.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project -.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project -.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html - -Installation -~~~~~~~~~~~~ - -Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to -create isolated Python environments. The basic problem it addresses is one of -dependencies and versions, and indirectly permissions. - -With `virtualenv`_, it's possible to install this library without needing system -install permissions, and without clashing with the installed system -dependencies. - -.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ - - -Mac/Linux -^^^^^^^^^ - -.. code-block:: console - - python3 -m venv - source /bin/activate - /bin/pip install /path/to/library - - -Windows -^^^^^^^ - -.. code-block:: console - - python3 -m venv - \Scripts\activate - \Scripts\pip.exe install \path\to\library diff --git a/owl-bot-staging/spanner_admin_database/v1/docs/conf.py b/owl-bot-staging/spanner_admin_database/v1/docs/conf.py deleted file mode 100644 index 16ce340ec0..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/docs/conf.py +++ /dev/null @@ -1,376 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# -# google-cloud-spanner-admin-database documentation build configuration file -# -# This file is execfile()d with the current directory set to its -# containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -import sys -import os -import shlex - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath("..")) - -__version__ = "0.1.0" - -# -- General configuration ------------------------------------------------ - -# If your documentation needs a minimal Sphinx version, state it here. -needs_sphinx = "4.0.1" - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.autosummary", - "sphinx.ext.intersphinx", - "sphinx.ext.coverage", - "sphinx.ext.napoleon", - "sphinx.ext.todo", - "sphinx.ext.viewcode", -] - -# autodoc/autosummary flags -autoclass_content = "both" -autodoc_default_flags = ["members"] -autosummary_generate = True - - -# Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] - -# Allow markdown includes (so releases.md can include CHANGLEOG.md) -# http://www.sphinx-doc.org/en/master/markdown.html -source_parsers = {".md": "recommonmark.parser.CommonMarkParser"} - -# The suffix(es) of source filenames. -# You can specify multiple suffix as a list of string: -source_suffix = [".rst", ".md"] - -# The encoding of source files. -# source_encoding = 'utf-8-sig' - -# The root toctree document. -root_doc = "index" - -# General information about the project. -project = u"google-cloud-spanner-admin-database" -copyright = u"2022, Google, LLC" -author = u"Google APIs" # TODO: autogenerate this bit - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The full version, including alpha/beta/rc tags. -release = __version__ -# The short X.Y version. -version = ".".join(release.split(".")[0:2]) - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. -language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -# today = '' -# Else, today_fmt is used as the format for a strftime call. -# today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = ["_build"] - -# The reST default role (used for this markup: `text`) to use for all -# documents. -# default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -# add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -# add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -# show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = "sphinx" - -# A list of ignored prefixes for module index sorting. -# modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built documents. -# keep_warnings = False - -# If true, `todo` and `todoList` produce output, else they produce nothing. -todo_include_todos = True - - -# -- Options for HTML output ---------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = "alabaster" - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -html_theme_options = { - "description": "Google Cloud Client Libraries for Python", - "github_user": "googleapis", - "github_repo": "google-cloud-python", - "github_banner": True, - "font_family": "'Roboto', Georgia, sans", - "head_font_family": "'Roboto', Georgia, serif", - "code_font_family": "'Roboto Mono', 'Consolas', monospace", -} - -# Add any paths that contain custom themes here, relative to this directory. -# html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -# html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -# html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -# html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -# html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] - -# Add any extra paths that contain custom files (such as robots.txt or -# .htaccess) here, relative to this directory. These files are copied -# directly to the root of the documentation. -# html_extra_path = [] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -# html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -# html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -# html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -# html_additional_pages = {} - -# If false, no module index is generated. -# html_domain_indices = True - -# If false, no index is generated. -# html_use_index = True - -# If true, the index is split into individual pages for each letter. -# html_split_index = False - -# If true, links to the reST sources are added to the pages. -# html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -# html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -# html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -# html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -# html_file_suffix = None - -# Language to be used for generating the HTML full-text search index. -# Sphinx supports the following languages: -# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' -# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' -# html_search_language = 'en' - -# A dictionary with options for the search language support, empty by default. -# Now only 'ja' uses this config value -# html_search_options = {'type': 'default'} - -# The name of a javascript file (relative to the configuration directory) that -# implements a search results scorer. If empty, the default will be used. -# html_search_scorer = 'scorer.js' - -# Output file base name for HTML help builder. -htmlhelp_basename = "google-cloud-spanner-admin-database-doc" - -# -- Options for warnings ------------------------------------------------------ - - -suppress_warnings = [ - # Temporarily suppress this to avoid "more than one target found for - # cross-reference" warning, which are intractable for us to avoid while in - # a mono-repo. - # See https://github.com/sphinx-doc/sphinx/blob - # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 - "ref.python" -] - -# -- Options for LaTeX output --------------------------------------------- - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). - # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. - # 'preamble': '', - # Latex figure (float) alignment - # 'figure_align': 'htbp', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - ( - root_doc, - "google-cloud-spanner-admin-database.tex", - u"google-cloud-spanner-admin-database Documentation", - author, - "manual", - ) -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -# latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -# latex_use_parts = False - -# If true, show page references after internal links. -# latex_show_pagerefs = False - -# If true, show URL addresses after external links. -# latex_show_urls = False - -# Documents to append as an appendix to all manuals. -# latex_appendices = [] - -# If false, no module index is generated. -# latex_domain_indices = True - - -# -- Options for manual page output --------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - ( - root_doc, - "google-cloud-spanner-admin-database", - u"Google Cloud Spanner Admin Database Documentation", - [author], - 1, - ) -] - -# If true, show URL addresses after external links. -# man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - ( - root_doc, - "google-cloud-spanner-admin-database", - u"google-cloud-spanner-admin-database Documentation", - author, - "google-cloud-spanner-admin-database", - "GAPIC library for Google Cloud Spanner Admin Database API", - "APIs", - ) -] - -# Documents to append as an appendix to all manuals. -# texinfo_appendices = [] - -# If false, no module index is generated. -# texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -# texinfo_show_urls = 'footnote' - -# If true, do not generate a @detailmenu in the "Top" node's menu. -# texinfo_no_detailmenu = False - - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = { - "python": ("http://python.readthedocs.org/en/latest/", None), - "gax": ("https://gax-python.readthedocs.org/en/latest/", None), - "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), - "google-gax": ("https://gax-python.readthedocs.io/en/latest/", None), - "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None), - "grpc": ("https://grpc.io/grpc/python/", None), - "requests": ("http://requests.kennethreitz.org/en/stable/", None), - "proto": ("https://proto-plus-python.readthedocs.io/en/stable", None), - "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), -} - - -# Napoleon settings -napoleon_google_docstring = True -napoleon_numpy_docstring = True -napoleon_include_private_with_doc = False -napoleon_include_special_with_doc = True -napoleon_use_admonition_for_examples = False -napoleon_use_admonition_for_notes = False -napoleon_use_admonition_for_references = False -napoleon_use_ivar = False -napoleon_use_param = True -napoleon_use_rtype = True diff --git a/owl-bot-staging/spanner_admin_database/v1/docs/index.rst b/owl-bot-staging/spanner_admin_database/v1/docs/index.rst deleted file mode 100644 index e2947e7442..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/docs/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -API Reference -------------- -.. toctree:: - :maxdepth: 2 - - spanner_admin_database_v1/services - spanner_admin_database_v1/types diff --git a/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/database_admin.rst b/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/database_admin.rst deleted file mode 100644 index bd6aab00e4..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/database_admin.rst +++ /dev/null @@ -1,10 +0,0 @@ -DatabaseAdmin -------------------------------- - -.. automodule:: google.cloud.spanner_admin_database_v1.services.database_admin - :members: - :inherited-members: - -.. automodule:: google.cloud.spanner_admin_database_v1.services.database_admin.pagers - :members: - :inherited-members: diff --git a/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/services.rst b/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/services.rst deleted file mode 100644 index 55e57d8dc0..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/services.rst +++ /dev/null @@ -1,6 +0,0 @@ -Services for Google Cloud Spanner Admin Database v1 API -======================================================= -.. toctree:: - :maxdepth: 2 - - database_admin diff --git a/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/types.rst b/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/types.rst deleted file mode 100644 index fe6c27778b..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/docs/spanner_admin_database_v1/types.rst +++ /dev/null @@ -1,6 +0,0 @@ -Types for Google Cloud Spanner Admin Database v1 API -==================================================== - -.. automodule:: google.cloud.spanner_admin_database_v1.types - :members: - :show-inheritance: diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/__init__.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/__init__.py deleted file mode 100644 index 4333b2d92f..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/__init__.py +++ /dev/null @@ -1,113 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from google.cloud.spanner_admin_database import gapic_version as package_version - -__version__ = package_version.__version__ - - -from google.cloud.spanner_admin_database_v1.services.database_admin.client import DatabaseAdminClient -from google.cloud.spanner_admin_database_v1.services.database_admin.async_client import DatabaseAdminAsyncClient - -from google.cloud.spanner_admin_database_v1.types.backup import Backup -from google.cloud.spanner_admin_database_v1.types.backup import BackupInfo -from google.cloud.spanner_admin_database_v1.types.backup import CopyBackupEncryptionConfig -from google.cloud.spanner_admin_database_v1.types.backup import CopyBackupMetadata -from google.cloud.spanner_admin_database_v1.types.backup import CopyBackupRequest -from google.cloud.spanner_admin_database_v1.types.backup import CreateBackupEncryptionConfig -from google.cloud.spanner_admin_database_v1.types.backup import CreateBackupMetadata -from google.cloud.spanner_admin_database_v1.types.backup import CreateBackupRequest -from google.cloud.spanner_admin_database_v1.types.backup import DeleteBackupRequest -from google.cloud.spanner_admin_database_v1.types.backup import GetBackupRequest -from google.cloud.spanner_admin_database_v1.types.backup import ListBackupOperationsRequest -from google.cloud.spanner_admin_database_v1.types.backup import ListBackupOperationsResponse -from google.cloud.spanner_admin_database_v1.types.backup import ListBackupsRequest -from google.cloud.spanner_admin_database_v1.types.backup import ListBackupsResponse -from google.cloud.spanner_admin_database_v1.types.backup import UpdateBackupRequest -from google.cloud.spanner_admin_database_v1.types.common import EncryptionConfig -from google.cloud.spanner_admin_database_v1.types.common import EncryptionInfo -from google.cloud.spanner_admin_database_v1.types.common import OperationProgress -from google.cloud.spanner_admin_database_v1.types.common import DatabaseDialect -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import CreateDatabaseMetadata -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import CreateDatabaseRequest -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import Database -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import DatabaseRole -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import DropDatabaseRequest -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import GetDatabaseDdlRequest -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import GetDatabaseDdlResponse -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import GetDatabaseRequest -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import ListDatabaseOperationsRequest -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import ListDatabaseOperationsResponse -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import ListDatabaseRolesRequest -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import ListDatabaseRolesResponse -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import ListDatabasesRequest -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import ListDatabasesResponse -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import OptimizeRestoredDatabaseMetadata -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import RestoreDatabaseEncryptionConfig -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import RestoreDatabaseMetadata -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import RestoreDatabaseRequest -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import RestoreInfo -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import UpdateDatabaseDdlMetadata -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import UpdateDatabaseDdlRequest -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import UpdateDatabaseMetadata -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import UpdateDatabaseRequest -from google.cloud.spanner_admin_database_v1.types.spanner_database_admin import RestoreSourceType - -__all__ = ('DatabaseAdminClient', - 'DatabaseAdminAsyncClient', - 'Backup', - 'BackupInfo', - 'CopyBackupEncryptionConfig', - 'CopyBackupMetadata', - 'CopyBackupRequest', - 'CreateBackupEncryptionConfig', - 'CreateBackupMetadata', - 'CreateBackupRequest', - 'DeleteBackupRequest', - 'GetBackupRequest', - 'ListBackupOperationsRequest', - 'ListBackupOperationsResponse', - 'ListBackupsRequest', - 'ListBackupsResponse', - 'UpdateBackupRequest', - 'EncryptionConfig', - 'EncryptionInfo', - 'OperationProgress', - 'DatabaseDialect', - 'CreateDatabaseMetadata', - 'CreateDatabaseRequest', - 'Database', - 'DatabaseRole', - 'DropDatabaseRequest', - 'GetDatabaseDdlRequest', - 'GetDatabaseDdlResponse', - 'GetDatabaseRequest', - 'ListDatabaseOperationsRequest', - 'ListDatabaseOperationsResponse', - 'ListDatabaseRolesRequest', - 'ListDatabaseRolesResponse', - 'ListDatabasesRequest', - 'ListDatabasesResponse', - 'OptimizeRestoredDatabaseMetadata', - 'RestoreDatabaseEncryptionConfig', - 'RestoreDatabaseMetadata', - 'RestoreDatabaseRequest', - 'RestoreInfo', - 'UpdateDatabaseDdlMetadata', - 'UpdateDatabaseDdlRequest', - 'UpdateDatabaseMetadata', - 'UpdateDatabaseRequest', - 'RestoreSourceType', -) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/gapic_version.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/gapic_version.py deleted file mode 100644 index 405b1cebcf..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/gapic_version.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -__version__ = "0.1.0" # {x-release-please-version} diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/py.typed b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/py.typed deleted file mode 100644 index 29f334aad6..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-spanner-admin-database package uses inline types. diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/__init__.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/__init__.py deleted file mode 100644 index 4b9db19432..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/__init__.py +++ /dev/null @@ -1,114 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from google.cloud.spanner_admin_database_v1 import gapic_version as package_version - -__version__ = package_version.__version__ - - -from .services.database_admin import DatabaseAdminClient -from .services.database_admin import DatabaseAdminAsyncClient - -from .types.backup import Backup -from .types.backup import BackupInfo -from .types.backup import CopyBackupEncryptionConfig -from .types.backup import CopyBackupMetadata -from .types.backup import CopyBackupRequest -from .types.backup import CreateBackupEncryptionConfig -from .types.backup import CreateBackupMetadata -from .types.backup import CreateBackupRequest -from .types.backup import DeleteBackupRequest -from .types.backup import GetBackupRequest -from .types.backup import ListBackupOperationsRequest -from .types.backup import ListBackupOperationsResponse -from .types.backup import ListBackupsRequest -from .types.backup import ListBackupsResponse -from .types.backup import UpdateBackupRequest -from .types.common import EncryptionConfig -from .types.common import EncryptionInfo -from .types.common import OperationProgress -from .types.common import DatabaseDialect -from .types.spanner_database_admin import CreateDatabaseMetadata -from .types.spanner_database_admin import CreateDatabaseRequest -from .types.spanner_database_admin import Database -from .types.spanner_database_admin import DatabaseRole -from .types.spanner_database_admin import DropDatabaseRequest -from .types.spanner_database_admin import GetDatabaseDdlRequest -from .types.spanner_database_admin import GetDatabaseDdlResponse -from .types.spanner_database_admin import GetDatabaseRequest -from .types.spanner_database_admin import ListDatabaseOperationsRequest -from .types.spanner_database_admin import ListDatabaseOperationsResponse -from .types.spanner_database_admin import ListDatabaseRolesRequest -from .types.spanner_database_admin import ListDatabaseRolesResponse -from .types.spanner_database_admin import ListDatabasesRequest -from .types.spanner_database_admin import ListDatabasesResponse -from .types.spanner_database_admin import OptimizeRestoredDatabaseMetadata -from .types.spanner_database_admin import RestoreDatabaseEncryptionConfig -from .types.spanner_database_admin import RestoreDatabaseMetadata -from .types.spanner_database_admin import RestoreDatabaseRequest -from .types.spanner_database_admin import RestoreInfo -from .types.spanner_database_admin import UpdateDatabaseDdlMetadata -from .types.spanner_database_admin import UpdateDatabaseDdlRequest -from .types.spanner_database_admin import UpdateDatabaseMetadata -from .types.spanner_database_admin import UpdateDatabaseRequest -from .types.spanner_database_admin import RestoreSourceType - -__all__ = ( - 'DatabaseAdminAsyncClient', -'Backup', -'BackupInfo', -'CopyBackupEncryptionConfig', -'CopyBackupMetadata', -'CopyBackupRequest', -'CreateBackupEncryptionConfig', -'CreateBackupMetadata', -'CreateBackupRequest', -'CreateDatabaseMetadata', -'CreateDatabaseRequest', -'Database', -'DatabaseAdminClient', -'DatabaseDialect', -'DatabaseRole', -'DeleteBackupRequest', -'DropDatabaseRequest', -'EncryptionConfig', -'EncryptionInfo', -'GetBackupRequest', -'GetDatabaseDdlRequest', -'GetDatabaseDdlResponse', -'GetDatabaseRequest', -'ListBackupOperationsRequest', -'ListBackupOperationsResponse', -'ListBackupsRequest', -'ListBackupsResponse', -'ListDatabaseOperationsRequest', -'ListDatabaseOperationsResponse', -'ListDatabaseRolesRequest', -'ListDatabaseRolesResponse', -'ListDatabasesRequest', -'ListDatabasesResponse', -'OperationProgress', -'OptimizeRestoredDatabaseMetadata', -'RestoreDatabaseEncryptionConfig', -'RestoreDatabaseMetadata', -'RestoreDatabaseRequest', -'RestoreInfo', -'RestoreSourceType', -'UpdateBackupRequest', -'UpdateDatabaseDdlMetadata', -'UpdateDatabaseDdlRequest', -'UpdateDatabaseMetadata', -'UpdateDatabaseRequest', -) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_metadata.json b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_metadata.json deleted file mode 100644 index b0fb4f1384..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_metadata.json +++ /dev/null @@ -1,328 +0,0 @@ - { - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "python", - "libraryPackage": "google.cloud.spanner_admin_database_v1", - "protoPackage": "google.spanner.admin.database.v1", - "schema": "1.0", - "services": { - "DatabaseAdmin": { - "clients": { - "grpc": { - "libraryClient": "DatabaseAdminClient", - "rpcs": { - "CopyBackup": { - "methods": [ - "copy_backup" - ] - }, - "CreateBackup": { - "methods": [ - "create_backup" - ] - }, - "CreateDatabase": { - "methods": [ - "create_database" - ] - }, - "DeleteBackup": { - "methods": [ - "delete_backup" - ] - }, - "DropDatabase": { - "methods": [ - "drop_database" - ] - }, - "GetBackup": { - "methods": [ - "get_backup" - ] - }, - "GetDatabase": { - "methods": [ - "get_database" - ] - }, - "GetDatabaseDdl": { - "methods": [ - "get_database_ddl" - ] - }, - "GetIamPolicy": { - "methods": [ - "get_iam_policy" - ] - }, - "ListBackupOperations": { - "methods": [ - "list_backup_operations" - ] - }, - "ListBackups": { - "methods": [ - "list_backups" - ] - }, - "ListDatabaseOperations": { - "methods": [ - "list_database_operations" - ] - }, - "ListDatabaseRoles": { - "methods": [ - "list_database_roles" - ] - }, - "ListDatabases": { - "methods": [ - "list_databases" - ] - }, - "RestoreDatabase": { - "methods": [ - "restore_database" - ] - }, - "SetIamPolicy": { - "methods": [ - "set_iam_policy" - ] - }, - "TestIamPermissions": { - "methods": [ - "test_iam_permissions" - ] - }, - "UpdateBackup": { - "methods": [ - "update_backup" - ] - }, - "UpdateDatabase": { - "methods": [ - "update_database" - ] - }, - "UpdateDatabaseDdl": { - "methods": [ - "update_database_ddl" - ] - } - } - }, - "grpc-async": { - "libraryClient": "DatabaseAdminAsyncClient", - "rpcs": { - "CopyBackup": { - "methods": [ - "copy_backup" - ] - }, - "CreateBackup": { - "methods": [ - "create_backup" - ] - }, - "CreateDatabase": { - "methods": [ - "create_database" - ] - }, - "DeleteBackup": { - "methods": [ - "delete_backup" - ] - }, - "DropDatabase": { - "methods": [ - "drop_database" - ] - }, - "GetBackup": { - "methods": [ - "get_backup" - ] - }, - "GetDatabase": { - "methods": [ - "get_database" - ] - }, - "GetDatabaseDdl": { - "methods": [ - "get_database_ddl" - ] - }, - "GetIamPolicy": { - "methods": [ - "get_iam_policy" - ] - }, - "ListBackupOperations": { - "methods": [ - "list_backup_operations" - ] - }, - "ListBackups": { - "methods": [ - "list_backups" - ] - }, - "ListDatabaseOperations": { - "methods": [ - "list_database_operations" - ] - }, - "ListDatabaseRoles": { - "methods": [ - "list_database_roles" - ] - }, - "ListDatabases": { - "methods": [ - "list_databases" - ] - }, - "RestoreDatabase": { - "methods": [ - "restore_database" - ] - }, - "SetIamPolicy": { - "methods": [ - "set_iam_policy" - ] - }, - "TestIamPermissions": { - "methods": [ - "test_iam_permissions" - ] - }, - "UpdateBackup": { - "methods": [ - "update_backup" - ] - }, - "UpdateDatabase": { - "methods": [ - "update_database" - ] - }, - "UpdateDatabaseDdl": { - "methods": [ - "update_database_ddl" - ] - } - } - }, - "rest": { - "libraryClient": "DatabaseAdminClient", - "rpcs": { - "CopyBackup": { - "methods": [ - "copy_backup" - ] - }, - "CreateBackup": { - "methods": [ - "create_backup" - ] - }, - "CreateDatabase": { - "methods": [ - "create_database" - ] - }, - "DeleteBackup": { - "methods": [ - "delete_backup" - ] - }, - "DropDatabase": { - "methods": [ - "drop_database" - ] - }, - "GetBackup": { - "methods": [ - "get_backup" - ] - }, - "GetDatabase": { - "methods": [ - "get_database" - ] - }, - "GetDatabaseDdl": { - "methods": [ - "get_database_ddl" - ] - }, - "GetIamPolicy": { - "methods": [ - "get_iam_policy" - ] - }, - "ListBackupOperations": { - "methods": [ - "list_backup_operations" - ] - }, - "ListBackups": { - "methods": [ - "list_backups" - ] - }, - "ListDatabaseOperations": { - "methods": [ - "list_database_operations" - ] - }, - "ListDatabaseRoles": { - "methods": [ - "list_database_roles" - ] - }, - "ListDatabases": { - "methods": [ - "list_databases" - ] - }, - "RestoreDatabase": { - "methods": [ - "restore_database" - ] - }, - "SetIamPolicy": { - "methods": [ - "set_iam_policy" - ] - }, - "TestIamPermissions": { - "methods": [ - "test_iam_permissions" - ] - }, - "UpdateBackup": { - "methods": [ - "update_backup" - ] - }, - "UpdateDatabase": { - "methods": [ - "update_database" - ] - }, - "UpdateDatabaseDdl": { - "methods": [ - "update_database_ddl" - ] - } - } - } - } - } - } -} diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_version.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_version.py deleted file mode 100644 index 405b1cebcf..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/gapic_version.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -__version__ = "0.1.0" # {x-release-please-version} diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/py.typed b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/py.typed deleted file mode 100644 index 29f334aad6..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-spanner-admin-database package uses inline types. diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/__init__.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/__init__.py deleted file mode 100644 index e8e1c3845d..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py deleted file mode 100644 index f18b3b7d61..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .client import DatabaseAdminClient -from .async_client import DatabaseAdminAsyncClient - -__all__ = ( - 'DatabaseAdminClient', - 'DatabaseAdminAsyncClient', -) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py deleted file mode 100644 index c0c1cbc083..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py +++ /dev/null @@ -1,3146 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -import functools -import re -from typing import Dict, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union - -from google.cloud.spanner_admin_database_v1 import gapic_version as package_version - -from google.api_core.client_options import ClientOptions -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore - -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object] # type: ignore - -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.cloud.spanner_admin_database_v1.services.database_admin import pagers -from google.cloud.spanner_admin_database_v1.types import backup -from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup -from google.cloud.spanner_admin_database_v1.types import common -from google.cloud.spanner_admin_database_v1.types import spanner_database_admin -from google.iam.v1 import iam_policy_pb2 # type: ignore -from google.iam.v1 import policy_pb2 # type: ignore -from google.longrunning import operations_pb2 -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from .transports.base import DatabaseAdminTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import DatabaseAdminGrpcAsyncIOTransport -from .client import DatabaseAdminClient - - -class DatabaseAdminAsyncClient: - """Cloud Spanner Database Admin API - - The Cloud Spanner Database Admin API can be used to: - - - create, drop, and list databases - - update the schema of pre-existing databases - - create, delete and list backups for a database - - restore a database from an existing backup - """ - - _client: DatabaseAdminClient - - DEFAULT_ENDPOINT = DatabaseAdminClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = DatabaseAdminClient.DEFAULT_MTLS_ENDPOINT - - backup_path = staticmethod(DatabaseAdminClient.backup_path) - parse_backup_path = staticmethod(DatabaseAdminClient.parse_backup_path) - crypto_key_path = staticmethod(DatabaseAdminClient.crypto_key_path) - parse_crypto_key_path = staticmethod(DatabaseAdminClient.parse_crypto_key_path) - crypto_key_version_path = staticmethod(DatabaseAdminClient.crypto_key_version_path) - parse_crypto_key_version_path = staticmethod(DatabaseAdminClient.parse_crypto_key_version_path) - database_path = staticmethod(DatabaseAdminClient.database_path) - parse_database_path = staticmethod(DatabaseAdminClient.parse_database_path) - database_role_path = staticmethod(DatabaseAdminClient.database_role_path) - parse_database_role_path = staticmethod(DatabaseAdminClient.parse_database_role_path) - instance_path = staticmethod(DatabaseAdminClient.instance_path) - parse_instance_path = staticmethod(DatabaseAdminClient.parse_instance_path) - common_billing_account_path = staticmethod(DatabaseAdminClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(DatabaseAdminClient.parse_common_billing_account_path) - common_folder_path = staticmethod(DatabaseAdminClient.common_folder_path) - parse_common_folder_path = staticmethod(DatabaseAdminClient.parse_common_folder_path) - common_organization_path = staticmethod(DatabaseAdminClient.common_organization_path) - parse_common_organization_path = staticmethod(DatabaseAdminClient.parse_common_organization_path) - common_project_path = staticmethod(DatabaseAdminClient.common_project_path) - parse_common_project_path = staticmethod(DatabaseAdminClient.parse_common_project_path) - common_location_path = staticmethod(DatabaseAdminClient.common_location_path) - parse_common_location_path = staticmethod(DatabaseAdminClient.parse_common_location_path) - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DatabaseAdminAsyncClient: The constructed client. - """ - return DatabaseAdminClient.from_service_account_info.__func__(DatabaseAdminAsyncClient, info, *args, **kwargs) # type: ignore - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DatabaseAdminAsyncClient: The constructed client. - """ - return DatabaseAdminClient.from_service_account_file.__func__(DatabaseAdminAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @classmethod - def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[ClientOptions] = None): - """Return the API endpoint and client cert source for mutual TLS. - - The client cert source is determined in the following order: - (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the - client cert source is None. - (2) if `client_options.client_cert_source` is provided, use the provided one; if the - default client cert source exists, use the default one; otherwise the client cert - source is None. - - The API endpoint is determined in the following order: - (1) if `client_options.api_endpoint` if provided, use the provided one. - (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the - default mTLS endpoint; if the environment variable is "never", use the default API - endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise - use the default API endpoint. - - More details can be found at https://google.aip.dev/auth/4114. - - Args: - client_options (google.api_core.client_options.ClientOptions): Custom options for the - client. Only the `api_endpoint` and `client_cert_source` properties may be used - in this method. - - Returns: - Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the - client cert source to use. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If any errors happen. - """ - return DatabaseAdminClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore - - @property - def transport(self) -> DatabaseAdminTransport: - """Returns the transport used by the client instance. - - Returns: - DatabaseAdminTransport: The transport used by the client instance. - """ - return self._client.transport - - get_transport_class = functools.partial(type(DatabaseAdminClient).get_transport_class, type(DatabaseAdminClient)) - - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, DatabaseAdminTransport] = "grpc_asyncio", - client_options: Optional[ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the database admin client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Union[str, ~.DatabaseAdminTransport]): The - transport to use. If set to None, a transport is chosen - automatically. - client_options (ClientOptions): Custom options for the client. It - won't take effect if a ``transport`` instance is provided. - (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT - environment variable can also be used to override the endpoint: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto switch to the - default mTLS endpoint if client certificate is present, this is - the default value). However, the ``api_endpoint`` property takes - precedence if provided. - (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide client certificate for mutual TLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - """ - self._client = DatabaseAdminClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - async def list_databases(self, - request: Optional[Union[spanner_database_admin.ListDatabasesRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListDatabasesAsyncPager: - r"""Lists Cloud Spanner databases. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_list_databases(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListDatabasesRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_databases(request=request) - - # Handle the response - async for response in page_result: - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest, dict]]): - The request object. The request for - [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. - parent (:class:`str`): - Required. The instance whose databases should be listed. - Values are of the form - ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabasesAsyncPager: - The response for - [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_database_admin.ListDatabasesRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_databases, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListDatabasesAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def create_database(self, - request: Optional[Union[spanner_database_admin.CreateDatabaseRequest, dict]] = None, - *, - parent: Optional[str] = None, - create_statement: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Creates a new Cloud Spanner database and starts to prepare it - for serving. The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and can be - used to track preparation of the database. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateDatabaseMetadata][google.spanner.admin.database.v1.CreateDatabaseMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Database][google.spanner.admin.database.v1.Database], if - successful. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_create_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.CreateDatabaseRequest( - parent="parent_value", - create_statement="create_statement_value", - ) - - # Make the request - operation = client.create_database(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.CreateDatabaseRequest, dict]]): - The request object. The request for - [CreateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase]. - parent (:class:`str`): - Required. The name of the instance that will serve the - new database. Values are of the form - ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - create_statement (:class:`str`): - Required. A ``CREATE DATABASE`` statement, which - specifies the ID of the new database. The database ID - must conform to the regular expression - ``[a-z][a-z0-9_\-]*[a-z0-9]`` and be between 2 and 30 - characters in length. If the database ID is a reserved - word or if it contains a hyphen, the database ID must be - enclosed in backticks (:literal:`\``). - - This corresponds to the ``create_statement`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.spanner_admin_database_v1.types.Database` - A Cloud Spanner database. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, create_statement]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_database_admin.CreateDatabaseRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if create_statement is not None: - request.create_statement = create_statement - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.create_database, - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - spanner_database_admin.Database, - metadata_type=spanner_database_admin.CreateDatabaseMetadata, - ) - - # Done; return the response. - return response - - async def get_database(self, - request: Optional[Union[spanner_database_admin.GetDatabaseRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner_database_admin.Database: - r"""Gets the state of a Cloud Spanner database. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_get_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.GetDatabaseRequest( - name="name_value", - ) - - # Make the request - response = await client.get_database(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.GetDatabaseRequest, dict]]): - The request object. The request for - [GetDatabase][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase]. - name (:class:`str`): - Required. The name of the requested database. Values are - of the form - ``projects//instances//databases/``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.types.Database: - A Cloud Spanner database. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_database_admin.GetDatabaseRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_database, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def update_database(self, - request: Optional[Union[spanner_database_admin.UpdateDatabaseRequest, dict]] = None, - *, - database: Optional[spanner_database_admin.Database] = None, - update_mask: Optional[field_mask_pb2.FieldMask] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Updates a Cloud Spanner database. The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of updating the database. If the named database - does not exist, returns ``NOT_FOUND``. - - While the operation is pending: - - - The database's - [reconciling][google.spanner.admin.database.v1.Database.reconciling] - field is set to true. - - Cancelling the operation is best-effort. If the cancellation - succeeds, the operation metadata's - [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] - is set, the updates are reverted, and the operation - terminates with a ``CANCELLED`` status. - - New UpdateDatabase requests will return a - ``FAILED_PRECONDITION`` error until the pending operation is - done (returns successfully or with error). - - Reading the database via the API continues to give the - pre-request values. - - Upon completion of the returned operation: - - - The new values are in effect and readable via the API. - - The database's - [reconciling][google.spanner.admin.database.v1.Database.reconciling] - field becomes false. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format - ``projects//instances//databases//operations/`` - and can be used to track the database modification. The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Database][google.spanner.admin.database.v1.Database], if - successful. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_update_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - database = spanner_admin_database_v1.Database() - database.name = "name_value" - - request = spanner_admin_database_v1.UpdateDatabaseRequest( - database=database, - ) - - # Make the request - operation = client.update_database(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest, dict]]): - The request object. The request for - [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. - database (:class:`google.cloud.spanner_admin_database_v1.types.Database`): - Required. The database to update. The ``name`` field of - the database is of the form - ``projects//instances//databases/``. - - This corresponds to the ``database`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - Required. The list of fields to update. Currently, only - ``enable_drop_protection`` field can be updated. - - This corresponds to the ``update_mask`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.spanner_admin_database_v1.types.Database` - A Cloud Spanner database. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([database, update_mask]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_database_admin.UpdateDatabaseRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if database is not None: - request.database = database - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_database, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("database.name", request.database.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - spanner_database_admin.Database, - metadata_type=spanner_database_admin.UpdateDatabaseMetadata, - ) - - # Done; return the response. - return response - - async def update_database_ddl(self, - request: Optional[Union[spanner_database_admin.UpdateDatabaseDdlRequest, dict]] = None, - *, - database: Optional[str] = None, - statements: Optional[MutableSequence[str]] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Updates the schema of a Cloud Spanner database by - creating/altering/dropping tables, columns, indexes, etc. The - returned [long-running operation][google.longrunning.Operation] - will have a name of the format - ``/operations/`` and can be used to - track execution of the schema change(s). The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateDatabaseDdlMetadata][google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata]. - The operation has no response. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_update_database_ddl(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.UpdateDatabaseDdlRequest( - database="database_value", - statements=['statements_value1', 'statements_value2'], - ) - - # Make the request - operation = client.update_database_ddl(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseDdlRequest, dict]]): - The request object. Enqueues the given DDL statements to be applied, in - order but not necessarily all at once, to the database - schema at some point (or points) in the future. The - server checks that the statements are executable - (syntactically valid, name tables that exist, etc.) - before enqueueing them, but they may still fail upon - later execution (e.g., if a statement from another batch - of statements is applied first and it conflicts in some - way, or if there is some data-related problem like a - ``NULL`` value in a column to which ``NOT NULL`` would - be added). If a statement fails, all subsequent - statements in the batch are automatically cancelled. - - Each batch of statements is assigned a name which can be - used with the - [Operations][google.longrunning.Operations] API to - monitor progress. See the - [operation_id][google.spanner.admin.database.v1.UpdateDatabaseDdlRequest.operation_id] - field for more details. - database (:class:`str`): - Required. The database to update. - This corresponds to the ``database`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - statements (:class:`MutableSequence[str]`): - Required. DDL statements to be - applied to the database. - - This corresponds to the ``statements`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - 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 - empty messages in your APIs. A typical example is to - use it as the request or the response type of an API - method. For instance: - - service Foo { - rpc Bar(google.protobuf.Empty) returns - (google.protobuf.Empty); - - } - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([database, statements]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_database_admin.UpdateDatabaseDdlRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if database is not None: - request.database = database - if statements: - request.statements.extend(statements) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_database_ddl, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("database", request.database), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - empty_pb2.Empty, - metadata_type=spanner_database_admin.UpdateDatabaseDdlMetadata, - ) - - # Done; return the response. - return response - - async def drop_database(self, - request: Optional[Union[spanner_database_admin.DropDatabaseRequest, dict]] = None, - *, - database: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Drops (aka deletes) a Cloud Spanner database. Completed backups - for the database will be retained according to their - ``expire_time``. Note: Cloud Spanner might continue to accept - requests for a few seconds after the database has been deleted. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_drop_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.DropDatabaseRequest( - database="database_value", - ) - - # Make the request - await client.drop_database(request=request) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.DropDatabaseRequest, dict]]): - The request object. The request for - [DropDatabase][google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase]. - database (:class:`str`): - Required. The database to be dropped. - This corresponds to the ``database`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([database]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_database_admin.DropDatabaseRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if database is not None: - request.database = database - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.drop_database, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("database", request.database), - )), - ) - - # Send the request. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def get_database_ddl(self, - request: Optional[Union[spanner_database_admin.GetDatabaseDdlRequest, dict]] = None, - *, - database: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner_database_admin.GetDatabaseDdlResponse: - r"""Returns the schema of a Cloud Spanner database as a list of - formatted DDL statements. This method does not show pending - schema updates, those may be queried using the - [Operations][google.longrunning.Operations] API. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_get_database_ddl(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.GetDatabaseDdlRequest( - database="database_value", - ) - - # Make the request - response = await client.get_database_ddl(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlRequest, dict]]): - The request object. The request for - [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. - database (:class:`str`): - Required. The database whose schema we wish to get. - Values are of the form - ``projects//instances//databases/`` - - This corresponds to the ``database`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlResponse: - The response for - [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([database]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_database_admin.GetDatabaseDdlRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if database is not None: - request.database = database - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_database_ddl, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("database", request.database), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def set_iam_policy(self, - request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, - *, - resource: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> policy_pb2.Policy: - r"""Sets the access control policy on a database or backup resource. - Replaces any existing policy. - - Authorization requires ``spanner.databases.setIamPolicy`` - permission on - [resource][google.iam.v1.SetIamPolicyRequest.resource]. For - backups, authorization requires ``spanner.backups.setIamPolicy`` - permission on - [resource][google.iam.v1.SetIamPolicyRequest.resource]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - from google.iam.v1 import iam_policy_pb2 # type: ignore - - async def sample_set_iam_policy(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = iam_policy_pb2.SetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = await client.set_iam_policy(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]]): - The request object. Request message for ``SetIamPolicy`` method. - resource (:class:`str`): - REQUIRED: The resource for which the - policy is being specified. See the - operation documentation for the - appropriate value for this field. - - This corresponds to the ``resource`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.iam.v1.policy_pb2.Policy: - An Identity and Access Management (IAM) policy, which specifies access - controls for Google Cloud resources. - - A Policy is a collection of bindings. A binding binds - one or more members, or principals, to a single role. - Principals can be user accounts, service accounts, - Google groups, and domains (such as G Suite). A role - is a named list of permissions; each role can be an - IAM predefined role or a user-created custom role. - - For some types of Google Cloud resources, a binding - can also specify a condition, which is a logical - expression that allows access to a resource only if - the expression evaluates to true. A condition can add - constraints based on attributes of the request, the - resource, or both. To learn which resources support - conditions in their IAM policies, see the [IAM - documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). - - **JSON example:** - - { - "bindings": [ - { - "role": - "roles/resourcemanager.organizationAdmin", - "members": [ "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - - }, { "role": - "roles/resourcemanager.organizationViewer", - "members": [ "user:eve@example.com" ], - "condition": { "title": "expirable access", - "description": "Does not grant access after - Sep 2020", "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", } } - - ], "etag": "BwWWja0YfJA=", "version": 3 - - } - - **YAML example:** - - bindings: - members: - user:\ mike@example.com - - group:\ admins@example.com - domain:google.com - - serviceAccount:\ my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - user:\ eve@example.com role: - roles/resourcemanager.organizationViewer - condition: title: expirable access description: - Does not grant access after Sep 2020 expression: - request.time < - timestamp('2020-10-01T00:00:00.000Z') etag: - BwWWja0YfJA= version: 3 - - For a description of IAM and its features, see the - [IAM - documentation](\ https://cloud.google.com/iam/docs/). - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([resource]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) - elif not request: - request = iam_policy_pb2.SetIamPolicyRequest(resource=resource, ) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.set_iam_policy, - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("resource", request.resource), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def get_iam_policy(self, - request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, - *, - resource: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> policy_pb2.Policy: - r"""Gets the access control policy for a database or backup - resource. Returns an empty policy if a database or backup exists - but does not have a policy set. - - Authorization requires ``spanner.databases.getIamPolicy`` - permission on - [resource][google.iam.v1.GetIamPolicyRequest.resource]. For - backups, authorization requires ``spanner.backups.getIamPolicy`` - permission on - [resource][google.iam.v1.GetIamPolicyRequest.resource]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - from google.iam.v1 import iam_policy_pb2 # type: ignore - - async def sample_get_iam_policy(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = iam_policy_pb2.GetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = await client.get_iam_policy(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]]): - The request object. Request message for ``GetIamPolicy`` method. - resource (:class:`str`): - REQUIRED: The resource for which the - policy is being requested. See the - operation documentation for the - appropriate value for this field. - - This corresponds to the ``resource`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.iam.v1.policy_pb2.Policy: - An Identity and Access Management (IAM) policy, which specifies access - controls for Google Cloud resources. - - A Policy is a collection of bindings. A binding binds - one or more members, or principals, to a single role. - Principals can be user accounts, service accounts, - Google groups, and domains (such as G Suite). A role - is a named list of permissions; each role can be an - IAM predefined role or a user-created custom role. - - For some types of Google Cloud resources, a binding - can also specify a condition, which is a logical - expression that allows access to a resource only if - the expression evaluates to true. A condition can add - constraints based on attributes of the request, the - resource, or both. To learn which resources support - conditions in their IAM policies, see the [IAM - documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). - - **JSON example:** - - { - "bindings": [ - { - "role": - "roles/resourcemanager.organizationAdmin", - "members": [ "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - - }, { "role": - "roles/resourcemanager.organizationViewer", - "members": [ "user:eve@example.com" ], - "condition": { "title": "expirable access", - "description": "Does not grant access after - Sep 2020", "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", } } - - ], "etag": "BwWWja0YfJA=", "version": 3 - - } - - **YAML example:** - - bindings: - members: - user:\ mike@example.com - - group:\ admins@example.com - domain:google.com - - serviceAccount:\ my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - user:\ eve@example.com role: - roles/resourcemanager.organizationViewer - condition: title: expirable access description: - Does not grant access after Sep 2020 expression: - request.time < - timestamp('2020-10-01T00:00:00.000Z') etag: - BwWWja0YfJA= version: 3 - - For a description of IAM and its features, see the - [IAM - documentation](\ https://cloud.google.com/iam/docs/). - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([resource]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) - elif not request: - request = iam_policy_pb2.GetIamPolicyRequest(resource=resource, ) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_iam_policy, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("resource", request.resource), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def test_iam_permissions(self, - request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, - *, - resource: Optional[str] = None, - permissions: Optional[MutableSequence[str]] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> iam_policy_pb2.TestIamPermissionsResponse: - r"""Returns permissions that the caller has on the specified - database or backup resource. - - Attempting this RPC on a non-existent Cloud Spanner database - will result in a NOT_FOUND error if the user has - ``spanner.databases.list`` permission on the containing Cloud - Spanner instance. Otherwise returns an empty set of permissions. - Calling this method on a backup that does not exist will result - in a NOT_FOUND error if the user has ``spanner.backups.list`` - permission on the containing instance. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - from google.iam.v1 import iam_policy_pb2 # type: ignore - - async def sample_test_iam_permissions(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = iam_policy_pb2.TestIamPermissionsRequest( - resource="resource_value", - permissions=['permissions_value1', 'permissions_value2'], - ) - - # Make the request - response = await client.test_iam_permissions(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]]): - The request object. Request message for ``TestIamPermissions`` method. - resource (:class:`str`): - REQUIRED: The resource for which the - policy detail is being requested. See - the operation documentation for the - appropriate value for this field. - - This corresponds to the ``resource`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - permissions (:class:`MutableSequence[str]`): - The set of permissions to check for the ``resource``. - Permissions with wildcards (such as '*' or 'storage.*') - are not allowed. For more information see `IAM - Overview `__. - - This corresponds to the ``permissions`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: - Response message for TestIamPermissions method. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([resource, permissions]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) - elif not request: - request = iam_policy_pb2.TestIamPermissionsRequest(resource=resource, permissions=permissions, ) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.test_iam_permissions, - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("resource", request.resource), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def create_backup(self, - request: Optional[Union[gsad_backup.CreateBackupRequest, dict]] = None, - *, - parent: Optional[str] = None, - backup: Optional[gsad_backup.Backup] = None, - backup_id: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Starts creating a new Cloud Spanner Backup. The returned backup - [long-running operation][google.longrunning.Operation] will have - a name of the format - ``projects//instances//backups//operations/`` - and can be used to track creation of the backup. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Backup][google.spanner.admin.database.v1.Backup], if - successful. Cancelling the returned operation will stop the - creation and delete the backup. There can be only one pending - backup creation per database. Backup creation of different - databases can run concurrently. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_create_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.CreateBackupRequest( - parent="parent_value", - backup_id="backup_id_value", - ) - - # Make the request - operation = client.create_backup(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.CreateBackupRequest, dict]]): - The request object. The request for - [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup]. - parent (:class:`str`): - Required. The name of the instance in which the backup - will be created. This must be the same instance that - contains the database the backup will be created from. - The backup will be stored in the location(s) specified - in the instance configuration of this instance. Values - are of the form - ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - backup (:class:`google.cloud.spanner_admin_database_v1.types.Backup`): - Required. The backup to create. - This corresponds to the ``backup`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - backup_id (:class:`str`): - Required. The id of the backup to be created. The - ``backup_id`` appended to ``parent`` forms the full - backup name of the form - ``projects//instances//backups/``. - - This corresponds to the ``backup_id`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.spanner_admin_database_v1.types.Backup` - A backup of a Cloud Spanner database. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, backup, backup_id]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = gsad_backup.CreateBackupRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if backup is not None: - request.backup = backup - if backup_id is not None: - request.backup_id = backup_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.create_backup, - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - gsad_backup.Backup, - metadata_type=gsad_backup.CreateBackupMetadata, - ) - - # Done; return the response. - return response - - async def copy_backup(self, - request: Optional[Union[backup.CopyBackupRequest, dict]] = None, - *, - parent: Optional[str] = None, - backup_id: Optional[str] = None, - source_backup: Optional[str] = None, - expire_time: Optional[timestamp_pb2.Timestamp] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Starts copying a Cloud Spanner Backup. The returned backup - [long-running operation][google.longrunning.Operation] will have - a name of the format - ``projects//instances//backups//operations/`` - and can be used to track copying of the backup. The operation is - associated with the destination backup. The - [metadata][google.longrunning.Operation.metadata] field type is - [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Backup][google.spanner.admin.database.v1.Backup], if - successful. Cancelling the returned operation will stop the - copying and delete the backup. Concurrent CopyBackup requests - can run on the same source backup. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_copy_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.CopyBackupRequest( - parent="parent_value", - backup_id="backup_id_value", - source_backup="source_backup_value", - ) - - # Make the request - operation = client.copy_backup(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.CopyBackupRequest, dict]]): - The request object. The request for - [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup]. - parent (:class:`str`): - Required. The name of the destination instance that will - contain the backup copy. Values are of the form: - ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - backup_id (:class:`str`): - Required. The id of the backup copy. The ``backup_id`` - appended to ``parent`` forms the full backup_uri of the - form - ``projects//instances//backups/``. - - This corresponds to the ``backup_id`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - source_backup (:class:`str`): - Required. The source backup to be copied. The source - backup needs to be in READY state for it to be copied. - Once CopyBackup is in progress, the source backup cannot - be deleted or cleaned up on expiration until CopyBackup - is finished. Values are of the form: - ``projects//instances//backups/``. - - This corresponds to the ``source_backup`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - expire_time (:class:`google.protobuf.timestamp_pb2.Timestamp`): - Required. The expiration time of the backup in - microsecond granularity. The expiration time must be at - least 6 hours and at most 366 days from the - ``create_time`` of the source backup. Once the - ``expire_time`` has passed, the backup is eligible to be - automatically deleted by Cloud Spanner to free the - resources used by the backup. - - This corresponds to the ``expire_time`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.spanner_admin_database_v1.types.Backup` - A backup of a Cloud Spanner database. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, backup_id, source_backup, expire_time]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = backup.CopyBackupRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if backup_id is not None: - request.backup_id = backup_id - if source_backup is not None: - request.source_backup = source_backup - if expire_time is not None: - request.expire_time = expire_time - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.copy_backup, - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - backup.Backup, - metadata_type=backup.CopyBackupMetadata, - ) - - # Done; return the response. - return response - - async def get_backup(self, - request: Optional[Union[backup.GetBackupRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> backup.Backup: - r"""Gets metadata on a pending or completed - [Backup][google.spanner.admin.database.v1.Backup]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_get_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.GetBackupRequest( - name="name_value", - ) - - # Make the request - response = await client.get_backup(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.GetBackupRequest, dict]]): - The request object. The request for - [GetBackup][google.spanner.admin.database.v1.DatabaseAdmin.GetBackup]. - name (:class:`str`): - Required. Name of the backup. Values are of the form - ``projects//instances//backups/``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.types.Backup: - A backup of a Cloud Spanner database. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = backup.GetBackupRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_backup, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def update_backup(self, - request: Optional[Union[gsad_backup.UpdateBackupRequest, dict]] = None, - *, - backup: Optional[gsad_backup.Backup] = None, - update_mask: Optional[field_mask_pb2.FieldMask] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> gsad_backup.Backup: - r"""Updates a pending or completed - [Backup][google.spanner.admin.database.v1.Backup]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_update_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.UpdateBackupRequest( - ) - - # Make the request - response = await client.update_backup(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.UpdateBackupRequest, dict]]): - The request object. The request for - [UpdateBackup][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup]. - backup (:class:`google.cloud.spanner_admin_database_v1.types.Backup`): - Required. The backup to update. ``backup.name``, and the - fields to be updated as specified by ``update_mask`` are - required. Other fields are ignored. Update is only - supported for the following fields: - - - ``backup.expire_time``. - - This corresponds to the ``backup`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - Required. A mask specifying which fields (e.g. - ``expire_time``) in the Backup resource should be - updated. This mask is relative to the Backup resource, - not to the request message. The field mask must always - be specified; this prevents any future fields from being - erased accidentally by clients that do not know about - them. - - This corresponds to the ``update_mask`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.types.Backup: - A backup of a Cloud Spanner database. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([backup, update_mask]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = gsad_backup.UpdateBackupRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if backup is not None: - request.backup = backup - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_backup, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("backup.name", request.backup.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def delete_backup(self, - request: Optional[Union[backup.DeleteBackupRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Deletes a pending or completed - [Backup][google.spanner.admin.database.v1.Backup]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_delete_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.DeleteBackupRequest( - name="name_value", - ) - - # Make the request - await client.delete_backup(request=request) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.DeleteBackupRequest, dict]]): - The request object. The request for - [DeleteBackup][google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup]. - name (:class:`str`): - Required. Name of the backup to delete. Values are of - the form - ``projects//instances//backups/``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = backup.DeleteBackupRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.delete_backup, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def list_backups(self, - request: Optional[Union[backup.ListBackupsRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListBackupsAsyncPager: - r"""Lists completed and pending backups. Backups returned are - ordered by ``create_time`` in descending order, starting from - the most recent ``create_time``. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_list_backups(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListBackupsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_backups(request=request) - - # Handle the response - async for response in page_result: - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.ListBackupsRequest, dict]]): - The request object. The request for - [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. - parent (:class:`str`): - Required. The instance to list backups from. Values are - of the form ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupsAsyncPager: - The response for - [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = backup.ListBackupsRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_backups, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListBackupsAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def restore_database(self, - request: Optional[Union[spanner_database_admin.RestoreDatabaseRequest, dict]] = None, - *, - parent: Optional[str] = None, - database_id: Optional[str] = None, - backup: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Create a new database by restoring from a completed backup. The - new database must be in the same project and in an instance with - the same instance configuration as the instance containing the - backup. The returned database [long-running - operation][google.longrunning.Operation] has a name of the - format - ``projects//instances//databases//operations/``, - and can be used to track the progress of the operation, and to - cancel it. The [metadata][google.longrunning.Operation.metadata] - field type is - [RestoreDatabaseMetadata][google.spanner.admin.database.v1.RestoreDatabaseMetadata]. - The [response][google.longrunning.Operation.response] type is - [Database][google.spanner.admin.database.v1.Database], if - successful. Cancelling the returned operation will stop the - restore and delete the database. There can be only one database - being restored into an instance at a time. Once the restore - operation completes, a new restore operation can be initiated, - without waiting for the optimize operation associated with the - first restore to complete. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_restore_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.RestoreDatabaseRequest( - backup="backup_value", - parent="parent_value", - database_id="database_id_value", - ) - - # Make the request - operation = client.restore_database(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.RestoreDatabaseRequest, dict]]): - The request object. The request for - [RestoreDatabase][google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase]. - parent (:class:`str`): - Required. The name of the instance in which to create - the restored database. This instance must be in the same - project and have the same instance configuration as the - instance containing the source backup. Values are of the - form ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - database_id (:class:`str`): - Required. The id of the database to create and restore - to. This database must not already exist. The - ``database_id`` appended to ``parent`` forms the full - database name of the form - ``projects//instances//databases/``. - - This corresponds to the ``database_id`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - backup (:class:`str`): - Name of the backup from which to restore. Values are of - the form - ``projects//instances//backups/``. - - This corresponds to the ``backup`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.spanner_admin_database_v1.types.Database` - A Cloud Spanner database. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, database_id, backup]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_database_admin.RestoreDatabaseRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if database_id is not None: - request.database_id = database_id - if backup is not None: - request.backup = backup - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.restore_database, - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - spanner_database_admin.Database, - metadata_type=spanner_database_admin.RestoreDatabaseMetadata, - ) - - # Done; return the response. - return response - - async def list_database_operations(self, - request: Optional[Union[spanner_database_admin.ListDatabaseOperationsRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListDatabaseOperationsAsyncPager: - r"""Lists database - [longrunning-operations][google.longrunning.Operation]. A - database operation has a name of the form - ``projects//instances//databases//operations/``. - The long-running operation - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - Operations returned include those that have - completed/failed/canceled within the last 7 days, and pending - operations. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_list_database_operations(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListDatabaseOperationsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_database_operations(request=request) - - # Handle the response - async for response in page_result: - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest, dict]]): - The request object. The request for - [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. - parent (:class:`str`): - Required. The instance of the database operations. - Values are of the form - ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseOperationsAsyncPager: - The response for - [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_database_admin.ListDatabaseOperationsRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_database_operations, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListDatabaseOperationsAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def list_backup_operations(self, - request: Optional[Union[backup.ListBackupOperationsRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListBackupOperationsAsyncPager: - r"""Lists the backup [long-running - operations][google.longrunning.Operation] in the given instance. - A backup operation has a name of the form - ``projects//instances//backups//operations/``. - The long-running operation - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - Operations returned include those that have - completed/failed/canceled within the last 7 days, and pending - operations. Operations returned are ordered by - ``operation.metadata.value.progress.start_time`` in descending - order starting from the most recently started operation. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_list_backup_operations(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListBackupOperationsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_backup_operations(request=request) - - # Handle the response - async for response in page_result: - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest, dict]]): - The request object. The request for - [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. - parent (:class:`str`): - Required. The instance of the backup operations. Values - are of the form - ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupOperationsAsyncPager: - The response for - [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = backup.ListBackupOperationsRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_backup_operations, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListBackupOperationsAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def list_database_roles(self, - request: Optional[Union[spanner_database_admin.ListDatabaseRolesRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListDatabaseRolesAsyncPager: - r"""Lists Cloud Spanner database roles. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - async def sample_list_database_roles(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListDatabaseRolesRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_database_roles(request=request) - - # Handle the response - async for response in page_result: - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest, dict]]): - The request object. The request for - [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. - parent (:class:`str`): - Required. The database whose roles should be listed. - Values are of the form - ``projects//instances//databases//databaseRoles``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseRolesAsyncPager: - The response for - [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_database_admin.ListDatabaseRolesRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_database_roles, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListDatabaseRolesAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def list_operations( - self, - request: Optional[operations_pb2.ListOperationsRequest] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operations_pb2.ListOperationsResponse: - r"""Lists operations that match the specified filter in the request. - - Args: - request (:class:`~.operations_pb2.ListOperationsRequest`): - The request object. Request message for - `ListOperations` method. - retry (google.api_core.retry.Retry): Designation of what errors, - if any, should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - Returns: - ~.operations_pb2.ListOperationsResponse: - Response message for ``ListOperations`` method. - """ - # Create or coerce a protobuf request object. - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._client._transport.list_operations, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) - - # Send the request. - response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) - - # Done; return the response. - return response - - async def get_operation( - self, - request: Optional[operations_pb2.GetOperationRequest] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operations_pb2.Operation: - r"""Gets the latest state of a long-running operation. - - Args: - request (:class:`~.operations_pb2.GetOperationRequest`): - The request object. Request message for - `GetOperation` method. - retry (google.api_core.retry.Retry): Designation of what errors, - if any, should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - Returns: - ~.operations_pb2.Operation: - An ``Operation`` object. - """ - # Create or coerce a protobuf request object. - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._client._transport.get_operation, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) - - # Send the request. - response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) - - # Done; return the response. - return response - - async def delete_operation( - self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Deletes a long-running operation. - - This method indicates that the client is no longer interested - in the operation result. It does not cancel the operation. - If the server doesn't support this method, it returns - `google.rpc.Code.UNIMPLEMENTED`. - - Args: - request (:class:`~.operations_pb2.DeleteOperationRequest`): - The request object. Request message for - `DeleteOperation` method. - retry (google.api_core.retry.Retry): Designation of what errors, - if any, should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - Returns: - None - """ - # Create or coerce a protobuf request object. - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._client._transport.delete_operation, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) - - # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) - - async def cancel_operation( - self, - request: Optional[operations_pb2.CancelOperationRequest] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Starts asynchronous cancellation on a long-running operation. - - The server makes a best effort to cancel the operation, but success - is not guaranteed. If the server doesn't support this method, it returns - `google.rpc.Code.UNIMPLEMENTED`. - - Args: - request (:class:`~.operations_pb2.CancelOperationRequest`): - The request object. Request message for - `CancelOperation` method. - retry (google.api_core.retry.Retry): Designation of what errors, - if any, should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - Returns: - None - """ - # Create or coerce a protobuf request object. - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._client._transport.cancel_operation, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) - - # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) - - async def __aenter__(self): - return self - - async def __aexit__(self, exc_type, exc, tb): - await self.transport.close() - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - - -__all__ = ( - "DatabaseAdminAsyncClient", -) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/client.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/client.py deleted file mode 100644 index 52705b426e..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/client.py +++ /dev/null @@ -1,3296 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -import os -import re -from typing import Dict, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast - -from google.cloud.spanner_admin_database_v1 import gapic_version as package_version - -from google.api_core import client_options as client_options_lib -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport import mtls # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore -from google.oauth2 import service_account # type: ignore - -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object] # type: ignore - -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.cloud.spanner_admin_database_v1.services.database_admin import pagers -from google.cloud.spanner_admin_database_v1.types import backup -from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup -from google.cloud.spanner_admin_database_v1.types import common -from google.cloud.spanner_admin_database_v1.types import spanner_database_admin -from google.iam.v1 import iam_policy_pb2 # type: ignore -from google.iam.v1 import policy_pb2 # type: ignore -from google.longrunning import operations_pb2 -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from .transports.base import DatabaseAdminTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import DatabaseAdminGrpcTransport -from .transports.grpc_asyncio import DatabaseAdminGrpcAsyncIOTransport -from .transports.rest import DatabaseAdminRestTransport - - -class DatabaseAdminClientMeta(type): - """Metaclass for the DatabaseAdmin client. - - This provides class-level methods for building and retrieving - support objects (e.g. transport) without polluting the client instance - objects. - """ - _transport_registry = OrderedDict() # type: Dict[str, Type[DatabaseAdminTransport]] - _transport_registry["grpc"] = DatabaseAdminGrpcTransport - _transport_registry["grpc_asyncio"] = DatabaseAdminGrpcAsyncIOTransport - _transport_registry["rest"] = DatabaseAdminRestTransport - - def get_transport_class(cls, - label: Optional[str] = None, - ) -> Type[DatabaseAdminTransport]: - """Returns an appropriate transport class. - - Args: - label: The name of the desired transport. If none is - provided, then the first transport in the registry is used. - - Returns: - The transport class to use. - """ - # If a specific transport is requested, return that one. - if label: - return cls._transport_registry[label] - - # No transport is requested; return the default (that is, the first one - # in the dictionary). - return next(iter(cls._transport_registry.values())) - - -class DatabaseAdminClient(metaclass=DatabaseAdminClientMeta): - """Cloud Spanner Database Admin API - - The Cloud Spanner Database Admin API can be used to: - - - create, drop, and list databases - - update the schema of pre-existing databases - - create, delete and list backups for a database - - restore a database from an existing backup - """ - - @staticmethod - def _get_default_mtls_endpoint(api_endpoint): - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - str: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - DEFAULT_ENDPOINT = "spanner.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DatabaseAdminClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_info(info) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - DatabaseAdminClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_file( - filename) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> DatabaseAdminTransport: - """Returns the transport used by the client instance. - - Returns: - DatabaseAdminTransport: The transport used by the client - instance. - """ - return self._transport - - @staticmethod - def backup_path(project: str,instance: str,backup: str,) -> str: - """Returns a fully-qualified backup string.""" - return "projects/{project}/instances/{instance}/backups/{backup}".format(project=project, instance=instance, backup=backup, ) - - @staticmethod - def parse_backup_path(path: str) -> Dict[str,str]: - """Parses a backup path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)/backups/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def crypto_key_path(project: str,location: str,key_ring: str,crypto_key: str,) -> str: - """Returns a fully-qualified crypto_key string.""" - return "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}".format(project=project, location=location, key_ring=key_ring, crypto_key=crypto_key, ) - - @staticmethod - def parse_crypto_key_path(path: str) -> Dict[str,str]: - """Parses a crypto_key path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/keyRings/(?P.+?)/cryptoKeys/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def crypto_key_version_path(project: str,location: str,key_ring: str,crypto_key: str,crypto_key_version: str,) -> str: - """Returns a fully-qualified crypto_key_version string.""" - return "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version}".format(project=project, location=location, key_ring=key_ring, crypto_key=crypto_key, crypto_key_version=crypto_key_version, ) - - @staticmethod - def parse_crypto_key_version_path(path: str) -> Dict[str,str]: - """Parses a crypto_key_version path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)/keyRings/(?P.+?)/cryptoKeys/(?P.+?)/cryptoKeyVersions/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def database_path(project: str,instance: str,database: str,) -> str: - """Returns a fully-qualified database string.""" - return "projects/{project}/instances/{instance}/databases/{database}".format(project=project, instance=instance, database=database, ) - - @staticmethod - def parse_database_path(path: str) -> Dict[str,str]: - """Parses a database path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)/databases/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def database_role_path(project: str,instance: str,database: str,role: str,) -> str: - """Returns a fully-qualified database_role string.""" - return "projects/{project}/instances/{instance}/databases/{database}/databaseRoles/{role}".format(project=project, instance=instance, database=database, role=role, ) - - @staticmethod - def parse_database_role_path(path: str) -> Dict[str,str]: - """Parses a database_role path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)/databases/(?P.+?)/databaseRoles/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def instance_path(project: str,instance: str,) -> str: - """Returns a fully-qualified instance string.""" - return "projects/{project}/instances/{instance}".format(project=project, instance=instance, ) - - @staticmethod - def parse_instance_path(path: str) -> Dict[str,str]: - """Parses a instance path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_billing_account_path(billing_account: str, ) -> str: - """Returns a fully-qualified billing_account string.""" - return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - - @staticmethod - def parse_common_billing_account_path(path: str) -> Dict[str,str]: - """Parse a billing_account path into its component segments.""" - m = re.match(r"^billingAccounts/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_folder_path(folder: str, ) -> str: - """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder, ) - - @staticmethod - def parse_common_folder_path(path: str) -> Dict[str,str]: - """Parse a folder path into its component segments.""" - m = re.match(r"^folders/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_organization_path(organization: str, ) -> str: - """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization, ) - - @staticmethod - def parse_common_organization_path(path: str) -> Dict[str,str]: - """Parse a organization path into its component segments.""" - m = re.match(r"^organizations/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_project_path(project: str, ) -> str: - """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project, ) - - @staticmethod - def parse_common_project_path(path: str) -> Dict[str,str]: - """Parse a project path into its component segments.""" - m = re.match(r"^projects/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_location_path(project: str, location: str, ) -> str: - """Returns a fully-qualified location string.""" - return "projects/{project}/locations/{location}".format(project=project, location=location, ) - - @staticmethod - def parse_common_location_path(path: str) -> Dict[str,str]: - """Parse a location path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) - return m.groupdict() if m else {} - - @classmethod - def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_options_lib.ClientOptions] = None): - """Return the API endpoint and client cert source for mutual TLS. - - The client cert source is determined in the following order: - (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the - client cert source is None. - (2) if `client_options.client_cert_source` is provided, use the provided one; if the - default client cert source exists, use the default one; otherwise the client cert - source is None. - - The API endpoint is determined in the following order: - (1) if `client_options.api_endpoint` if provided, use the provided one. - (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the - default mTLS endpoint; if the environment variable is "never", use the default API - endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise - use the default API endpoint. - - More details can be found at https://google.aip.dev/auth/4114. - - Args: - client_options (google.api_core.client_options.ClientOptions): Custom options for the - client. Only the `api_endpoint` and `client_cert_source` properties may be used - in this method. - - Returns: - Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the - client cert source to use. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If any errors happen. - """ - if client_options is None: - client_options = client_options_lib.ClientOptions() - use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_client_cert not in ("true", "false"): - raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") - - # Figure out the client cert source to use. - client_cert_source = None - if use_client_cert == "true": - if client_options.client_cert_source: - client_cert_source = client_options.client_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): - api_endpoint = cls.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = cls.DEFAULT_ENDPOINT - - return api_endpoint, client_cert_source - - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Optional[Union[str, DatabaseAdminTransport]] = None, - client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the database admin client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Union[str, DatabaseAdminTransport]): The - transport to use. If set to None, a transport is chosen - automatically. - client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the - client. It won't take effect if a ``transport`` instance is provided. - (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT - environment variable can also be used to override the endpoint: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto switch to the - default mTLS endpoint if client certificate is present, this is - the default value). However, the ``api_endpoint`` property takes - precedence if provided. - (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide client certificate for mutual TLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - """ - if isinstance(client_options, dict): - client_options = client_options_lib.from_dict(client_options) - if client_options is None: - client_options = client_options_lib.ClientOptions() - client_options = cast(client_options_lib.ClientOptions, client_options) - - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source(client_options) - - api_key_value = getattr(client_options, "api_key", None) - if api_key_value and credentials: - raise ValueError("client_options.api_key and credentials are mutually exclusive") - - # Save or instantiate the transport. - # Ordinarily, we provide the transport, but allowing a custom transport - # instance provides an extensibility point for unusual situations. - if isinstance(transport, DatabaseAdminTransport): - # transport is a DatabaseAdminTransport instance. - if credentials or client_options.credentials_file or api_key_value: - raise ValueError("When providing a transport instance, " - "provide its credentials directly.") - if client_options.scopes: - raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." - ) - self._transport = transport - else: - import google.auth._default # type: ignore - - if api_key_value and hasattr(google.auth._default, "get_api_key_credentials"): - credentials = google.auth._default.get_api_key_credentials(api_key_value) - - Transport = type(self).get_transport_class(transport) - self._transport = Transport( - credentials=credentials, - credentials_file=client_options.credentials_file, - host=api_endpoint, - scopes=client_options.scopes, - client_cert_source_for_mtls=client_cert_source_func, - quota_project_id=client_options.quota_project_id, - client_info=client_info, - always_use_jwt_access=True, - api_audience=client_options.api_audience, - ) - - def list_databases(self, - request: Optional[Union[spanner_database_admin.ListDatabasesRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListDatabasesPager: - r"""Lists Cloud Spanner databases. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_list_databases(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListDatabasesRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_databases(request=request) - - # Handle the response - for response in page_result: - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest, dict]): - The request object. The request for - [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. - parent (str): - Required. The instance whose databases should be listed. - Values are of the form - ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabasesPager: - The response for - [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_database_admin.ListDatabasesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_database_admin.ListDatabasesRequest): - request = spanner_database_admin.ListDatabasesRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_databases] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListDatabasesPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def create_database(self, - request: Optional[Union[spanner_database_admin.CreateDatabaseRequest, dict]] = None, - *, - parent: Optional[str] = None, - create_statement: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Creates a new Cloud Spanner database and starts to prepare it - for serving. The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and can be - used to track preparation of the database. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateDatabaseMetadata][google.spanner.admin.database.v1.CreateDatabaseMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Database][google.spanner.admin.database.v1.Database], if - successful. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_create_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.CreateDatabaseRequest( - parent="parent_value", - create_statement="create_statement_value", - ) - - # Make the request - operation = client.create_database(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.CreateDatabaseRequest, dict]): - The request object. The request for - [CreateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase]. - parent (str): - Required. The name of the instance that will serve the - new database. Values are of the form - ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - create_statement (str): - Required. A ``CREATE DATABASE`` statement, which - specifies the ID of the new database. The database ID - must conform to the regular expression - ``[a-z][a-z0-9_\-]*[a-z0-9]`` and be between 2 and 30 - characters in length. If the database ID is a reserved - word or if it contains a hyphen, the database ID must be - enclosed in backticks (:literal:`\``). - - This corresponds to the ``create_statement`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.spanner_admin_database_v1.types.Database` - A Cloud Spanner database. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, create_statement]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_database_admin.CreateDatabaseRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_database_admin.CreateDatabaseRequest): - request = spanner_database_admin.CreateDatabaseRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if create_statement is not None: - request.create_statement = create_statement - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_database] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - spanner_database_admin.Database, - metadata_type=spanner_database_admin.CreateDatabaseMetadata, - ) - - # Done; return the response. - return response - - def get_database(self, - request: Optional[Union[spanner_database_admin.GetDatabaseRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner_database_admin.Database: - r"""Gets the state of a Cloud Spanner database. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_get_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.GetDatabaseRequest( - name="name_value", - ) - - # Make the request - response = client.get_database(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.GetDatabaseRequest, dict]): - The request object. The request for - [GetDatabase][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase]. - name (str): - Required. The name of the requested database. Values are - of the form - ``projects//instances//databases/``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.types.Database: - A Cloud Spanner database. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_database_admin.GetDatabaseRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_database_admin.GetDatabaseRequest): - request = spanner_database_admin.GetDatabaseRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.get_database] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def update_database(self, - request: Optional[Union[spanner_database_admin.UpdateDatabaseRequest, dict]] = None, - *, - database: Optional[spanner_database_admin.Database] = None, - update_mask: Optional[field_mask_pb2.FieldMask] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Updates a Cloud Spanner database. The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of updating the database. If the named database - does not exist, returns ``NOT_FOUND``. - - While the operation is pending: - - - The database's - [reconciling][google.spanner.admin.database.v1.Database.reconciling] - field is set to true. - - Cancelling the operation is best-effort. If the cancellation - succeeds, the operation metadata's - [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] - is set, the updates are reverted, and the operation - terminates with a ``CANCELLED`` status. - - New UpdateDatabase requests will return a - ``FAILED_PRECONDITION`` error until the pending operation is - done (returns successfully or with error). - - Reading the database via the API continues to give the - pre-request values. - - Upon completion of the returned operation: - - - The new values are in effect and readable via the API. - - The database's - [reconciling][google.spanner.admin.database.v1.Database.reconciling] - field becomes false. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format - ``projects//instances//databases//operations/`` - and can be used to track the database modification. The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Database][google.spanner.admin.database.v1.Database], if - successful. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_update_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - database = spanner_admin_database_v1.Database() - database.name = "name_value" - - request = spanner_admin_database_v1.UpdateDatabaseRequest( - database=database, - ) - - # Make the request - operation = client.update_database(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest, dict]): - The request object. The request for - [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. - database (google.cloud.spanner_admin_database_v1.types.Database): - Required. The database to update. The ``name`` field of - the database is of the form - ``projects//instances//databases/``. - - This corresponds to the ``database`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. The list of fields to update. Currently, only - ``enable_drop_protection`` field can be updated. - - This corresponds to the ``update_mask`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.spanner_admin_database_v1.types.Database` - A Cloud Spanner database. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([database, update_mask]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_database_admin.UpdateDatabaseRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_database_admin.UpdateDatabaseRequest): - request = spanner_database_admin.UpdateDatabaseRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if database is not None: - request.database = database - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.update_database] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("database.name", request.database.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - spanner_database_admin.Database, - metadata_type=spanner_database_admin.UpdateDatabaseMetadata, - ) - - # Done; return the response. - return response - - def update_database_ddl(self, - request: Optional[Union[spanner_database_admin.UpdateDatabaseDdlRequest, dict]] = None, - *, - database: Optional[str] = None, - statements: Optional[MutableSequence[str]] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Updates the schema of a Cloud Spanner database by - creating/altering/dropping tables, columns, indexes, etc. The - returned [long-running operation][google.longrunning.Operation] - will have a name of the format - ``/operations/`` and can be used to - track execution of the schema change(s). The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateDatabaseDdlMetadata][google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata]. - The operation has no response. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_update_database_ddl(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.UpdateDatabaseDdlRequest( - database="database_value", - statements=['statements_value1', 'statements_value2'], - ) - - # Make the request - operation = client.update_database_ddl(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.UpdateDatabaseDdlRequest, dict]): - The request object. Enqueues the given DDL statements to be applied, in - order but not necessarily all at once, to the database - schema at some point (or points) in the future. The - server checks that the statements are executable - (syntactically valid, name tables that exist, etc.) - before enqueueing them, but they may still fail upon - later execution (e.g., if a statement from another batch - of statements is applied first and it conflicts in some - way, or if there is some data-related problem like a - ``NULL`` value in a column to which ``NOT NULL`` would - be added). If a statement fails, all subsequent - statements in the batch are automatically cancelled. - - Each batch of statements is assigned a name which can be - used with the - [Operations][google.longrunning.Operations] API to - monitor progress. See the - [operation_id][google.spanner.admin.database.v1.UpdateDatabaseDdlRequest.operation_id] - field for more details. - database (str): - Required. The database to update. - This corresponds to the ``database`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - statements (MutableSequence[str]): - Required. DDL statements to be - applied to the database. - - This corresponds to the ``statements`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - 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 - empty messages in your APIs. A typical example is to - use it as the request or the response type of an API - method. For instance: - - service Foo { - rpc Bar(google.protobuf.Empty) returns - (google.protobuf.Empty); - - } - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([database, statements]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_database_admin.UpdateDatabaseDdlRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_database_admin.UpdateDatabaseDdlRequest): - request = spanner_database_admin.UpdateDatabaseDdlRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if database is not None: - request.database = database - if statements is not None: - request.statements = statements - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.update_database_ddl] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("database", request.database), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - empty_pb2.Empty, - metadata_type=spanner_database_admin.UpdateDatabaseDdlMetadata, - ) - - # Done; return the response. - return response - - def drop_database(self, - request: Optional[Union[spanner_database_admin.DropDatabaseRequest, dict]] = None, - *, - database: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Drops (aka deletes) a Cloud Spanner database. Completed backups - for the database will be retained according to their - ``expire_time``. Note: Cloud Spanner might continue to accept - requests for a few seconds after the database has been deleted. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_drop_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.DropDatabaseRequest( - database="database_value", - ) - - # Make the request - client.drop_database(request=request) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.DropDatabaseRequest, dict]): - The request object. The request for - [DropDatabase][google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase]. - database (str): - Required. The database to be dropped. - This corresponds to the ``database`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([database]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_database_admin.DropDatabaseRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_database_admin.DropDatabaseRequest): - request = spanner_database_admin.DropDatabaseRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if database is not None: - request.database = database - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.drop_database] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("database", request.database), - )), - ) - - # Send the request. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def get_database_ddl(self, - request: Optional[Union[spanner_database_admin.GetDatabaseDdlRequest, dict]] = None, - *, - database: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner_database_admin.GetDatabaseDdlResponse: - r"""Returns the schema of a Cloud Spanner database as a list of - formatted DDL statements. This method does not show pending - schema updates, those may be queried using the - [Operations][google.longrunning.Operations] API. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_get_database_ddl(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.GetDatabaseDdlRequest( - database="database_value", - ) - - # Make the request - response = client.get_database_ddl(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlRequest, dict]): - The request object. The request for - [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. - database (str): - Required. The database whose schema we wish to get. - Values are of the form - ``projects//instances//databases/`` - - This corresponds to the ``database`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlResponse: - The response for - [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([database]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_database_admin.GetDatabaseDdlRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_database_admin.GetDatabaseDdlRequest): - request = spanner_database_admin.GetDatabaseDdlRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if database is not None: - request.database = database - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.get_database_ddl] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("database", request.database), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def set_iam_policy(self, - request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, - *, - resource: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> policy_pb2.Policy: - r"""Sets the access control policy on a database or backup resource. - Replaces any existing policy. - - Authorization requires ``spanner.databases.setIamPolicy`` - permission on - [resource][google.iam.v1.SetIamPolicyRequest.resource]. For - backups, authorization requires ``spanner.backups.setIamPolicy`` - permission on - [resource][google.iam.v1.SetIamPolicyRequest.resource]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - from google.iam.v1 import iam_policy_pb2 # type: ignore - - def sample_set_iam_policy(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = iam_policy_pb2.SetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = client.set_iam_policy(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]): - The request object. Request message for ``SetIamPolicy`` method. - resource (str): - REQUIRED: The resource for which the - policy is being specified. See the - operation documentation for the - appropriate value for this field. - - This corresponds to the ``resource`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.iam.v1.policy_pb2.Policy: - An Identity and Access Management (IAM) policy, which specifies access - controls for Google Cloud resources. - - A Policy is a collection of bindings. A binding binds - one or more members, or principals, to a single role. - Principals can be user accounts, service accounts, - Google groups, and domains (such as G Suite). A role - is a named list of permissions; each role can be an - IAM predefined role or a user-created custom role. - - For some types of Google Cloud resources, a binding - can also specify a condition, which is a logical - expression that allows access to a resource only if - the expression evaluates to true. A condition can add - constraints based on attributes of the request, the - resource, or both. To learn which resources support - conditions in their IAM policies, see the [IAM - documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). - - **JSON example:** - - { - "bindings": [ - { - "role": - "roles/resourcemanager.organizationAdmin", - "members": [ "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - - }, { "role": - "roles/resourcemanager.organizationViewer", - "members": [ "user:eve@example.com" ], - "condition": { "title": "expirable access", - "description": "Does not grant access after - Sep 2020", "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", } } - - ], "etag": "BwWWja0YfJA=", "version": 3 - - } - - **YAML example:** - - bindings: - members: - user:\ mike@example.com - - group:\ admins@example.com - domain:google.com - - serviceAccount:\ my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - user:\ eve@example.com role: - roles/resourcemanager.organizationViewer - condition: title: expirable access description: - Does not grant access after Sep 2020 expression: - request.time < - timestamp('2020-10-01T00:00:00.000Z') etag: - BwWWja0YfJA= version: 3 - - For a description of IAM and its features, see the - [IAM - documentation](\ https://cloud.google.com/iam/docs/). - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([resource]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - if isinstance(request, dict): - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - request = iam_policy_pb2.SetIamPolicyRequest(**request) - elif not request: - # Null request, just make one. - request = iam_policy_pb2.SetIamPolicyRequest() - if resource is not None: - request.resource = resource - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.set_iam_policy] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("resource", request.resource), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def get_iam_policy(self, - request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, - *, - resource: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> policy_pb2.Policy: - r"""Gets the access control policy for a database or backup - resource. Returns an empty policy if a database or backup exists - but does not have a policy set. - - Authorization requires ``spanner.databases.getIamPolicy`` - permission on - [resource][google.iam.v1.GetIamPolicyRequest.resource]. For - backups, authorization requires ``spanner.backups.getIamPolicy`` - permission on - [resource][google.iam.v1.GetIamPolicyRequest.resource]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - from google.iam.v1 import iam_policy_pb2 # type: ignore - - def sample_get_iam_policy(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = iam_policy_pb2.GetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = client.get_iam_policy(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]): - The request object. Request message for ``GetIamPolicy`` method. - resource (str): - REQUIRED: The resource for which the - policy is being requested. See the - operation documentation for the - appropriate value for this field. - - This corresponds to the ``resource`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.iam.v1.policy_pb2.Policy: - An Identity and Access Management (IAM) policy, which specifies access - controls for Google Cloud resources. - - A Policy is a collection of bindings. A binding binds - one or more members, or principals, to a single role. - Principals can be user accounts, service accounts, - Google groups, and domains (such as G Suite). A role - is a named list of permissions; each role can be an - IAM predefined role or a user-created custom role. - - For some types of Google Cloud resources, a binding - can also specify a condition, which is a logical - expression that allows access to a resource only if - the expression evaluates to true. A condition can add - constraints based on attributes of the request, the - resource, or both. To learn which resources support - conditions in their IAM policies, see the [IAM - documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). - - **JSON example:** - - { - "bindings": [ - { - "role": - "roles/resourcemanager.organizationAdmin", - "members": [ "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - - }, { "role": - "roles/resourcemanager.organizationViewer", - "members": [ "user:eve@example.com" ], - "condition": { "title": "expirable access", - "description": "Does not grant access after - Sep 2020", "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", } } - - ], "etag": "BwWWja0YfJA=", "version": 3 - - } - - **YAML example:** - - bindings: - members: - user:\ mike@example.com - - group:\ admins@example.com - domain:google.com - - serviceAccount:\ my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - user:\ eve@example.com role: - roles/resourcemanager.organizationViewer - condition: title: expirable access description: - Does not grant access after Sep 2020 expression: - request.time < - timestamp('2020-10-01T00:00:00.000Z') etag: - BwWWja0YfJA= version: 3 - - For a description of IAM and its features, see the - [IAM - documentation](\ https://cloud.google.com/iam/docs/). - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([resource]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - if isinstance(request, dict): - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - request = iam_policy_pb2.GetIamPolicyRequest(**request) - elif not request: - # Null request, just make one. - request = iam_policy_pb2.GetIamPolicyRequest() - if resource is not None: - request.resource = resource - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.get_iam_policy] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("resource", request.resource), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def test_iam_permissions(self, - request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, - *, - resource: Optional[str] = None, - permissions: Optional[MutableSequence[str]] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> iam_policy_pb2.TestIamPermissionsResponse: - r"""Returns permissions that the caller has on the specified - database or backup resource. - - Attempting this RPC on a non-existent Cloud Spanner database - will result in a NOT_FOUND error if the user has - ``spanner.databases.list`` permission on the containing Cloud - Spanner instance. Otherwise returns an empty set of permissions. - Calling this method on a backup that does not exist will result - in a NOT_FOUND error if the user has ``spanner.backups.list`` - permission on the containing instance. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - from google.iam.v1 import iam_policy_pb2 # type: ignore - - def sample_test_iam_permissions(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = iam_policy_pb2.TestIamPermissionsRequest( - resource="resource_value", - permissions=['permissions_value1', 'permissions_value2'], - ) - - # Make the request - response = client.test_iam_permissions(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]): - The request object. Request message for ``TestIamPermissions`` method. - resource (str): - REQUIRED: The resource for which the - policy detail is being requested. See - the operation documentation for the - appropriate value for this field. - - This corresponds to the ``resource`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - permissions (MutableSequence[str]): - The set of permissions to check for the ``resource``. - Permissions with wildcards (such as '*' or 'storage.*') - are not allowed. For more information see `IAM - Overview `__. - - This corresponds to the ``permissions`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: - Response message for TestIamPermissions method. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([resource, permissions]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - if isinstance(request, dict): - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - request = iam_policy_pb2.TestIamPermissionsRequest(**request) - elif not request: - # Null request, just make one. - request = iam_policy_pb2.TestIamPermissionsRequest() - if resource is not None: - request.resource = resource - if permissions: - request.permissions.extend(permissions) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("resource", request.resource), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def create_backup(self, - request: Optional[Union[gsad_backup.CreateBackupRequest, dict]] = None, - *, - parent: Optional[str] = None, - backup: Optional[gsad_backup.Backup] = None, - backup_id: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Starts creating a new Cloud Spanner Backup. The returned backup - [long-running operation][google.longrunning.Operation] will have - a name of the format - ``projects//instances//backups//operations/`` - and can be used to track creation of the backup. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Backup][google.spanner.admin.database.v1.Backup], if - successful. Cancelling the returned operation will stop the - creation and delete the backup. There can be only one pending - backup creation per database. Backup creation of different - databases can run concurrently. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_create_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.CreateBackupRequest( - parent="parent_value", - backup_id="backup_id_value", - ) - - # Make the request - operation = client.create_backup(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.CreateBackupRequest, dict]): - The request object. The request for - [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup]. - parent (str): - Required. The name of the instance in which the backup - will be created. This must be the same instance that - contains the database the backup will be created from. - The backup will be stored in the location(s) specified - in the instance configuration of this instance. Values - are of the form - ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - backup (google.cloud.spanner_admin_database_v1.types.Backup): - Required. The backup to create. - This corresponds to the ``backup`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - backup_id (str): - Required. The id of the backup to be created. The - ``backup_id`` appended to ``parent`` forms the full - backup name of the form - ``projects//instances//backups/``. - - This corresponds to the ``backup_id`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.spanner_admin_database_v1.types.Backup` - A backup of a Cloud Spanner database. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, backup, backup_id]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a gsad_backup.CreateBackupRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, gsad_backup.CreateBackupRequest): - request = gsad_backup.CreateBackupRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if backup is not None: - request.backup = backup - if backup_id is not None: - request.backup_id = backup_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_backup] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - gsad_backup.Backup, - metadata_type=gsad_backup.CreateBackupMetadata, - ) - - # Done; return the response. - return response - - def copy_backup(self, - request: Optional[Union[backup.CopyBackupRequest, dict]] = None, - *, - parent: Optional[str] = None, - backup_id: Optional[str] = None, - source_backup: Optional[str] = None, - expire_time: Optional[timestamp_pb2.Timestamp] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Starts copying a Cloud Spanner Backup. The returned backup - [long-running operation][google.longrunning.Operation] will have - a name of the format - ``projects//instances//backups//operations/`` - and can be used to track copying of the backup. The operation is - associated with the destination backup. The - [metadata][google.longrunning.Operation.metadata] field type is - [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Backup][google.spanner.admin.database.v1.Backup], if - successful. Cancelling the returned operation will stop the - copying and delete the backup. Concurrent CopyBackup requests - can run on the same source backup. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_copy_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.CopyBackupRequest( - parent="parent_value", - backup_id="backup_id_value", - source_backup="source_backup_value", - ) - - # Make the request - operation = client.copy_backup(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.CopyBackupRequest, dict]): - The request object. The request for - [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup]. - parent (str): - Required. The name of the destination instance that will - contain the backup copy. Values are of the form: - ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - backup_id (str): - Required. The id of the backup copy. The ``backup_id`` - appended to ``parent`` forms the full backup_uri of the - form - ``projects//instances//backups/``. - - This corresponds to the ``backup_id`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - source_backup (str): - Required. The source backup to be copied. The source - backup needs to be in READY state for it to be copied. - Once CopyBackup is in progress, the source backup cannot - be deleted or cleaned up on expiration until CopyBackup - is finished. Values are of the form: - ``projects//instances//backups/``. - - This corresponds to the ``source_backup`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - expire_time (google.protobuf.timestamp_pb2.Timestamp): - Required. The expiration time of the backup in - microsecond granularity. The expiration time must be at - least 6 hours and at most 366 days from the - ``create_time`` of the source backup. Once the - ``expire_time`` has passed, the backup is eligible to be - automatically deleted by Cloud Spanner to free the - resources used by the backup. - - This corresponds to the ``expire_time`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.spanner_admin_database_v1.types.Backup` - A backup of a Cloud Spanner database. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, backup_id, source_backup, expire_time]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a backup.CopyBackupRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, backup.CopyBackupRequest): - request = backup.CopyBackupRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if backup_id is not None: - request.backup_id = backup_id - if source_backup is not None: - request.source_backup = source_backup - if expire_time is not None: - request.expire_time = expire_time - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.copy_backup] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - backup.Backup, - metadata_type=backup.CopyBackupMetadata, - ) - - # Done; return the response. - return response - - def get_backup(self, - request: Optional[Union[backup.GetBackupRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> backup.Backup: - r"""Gets metadata on a pending or completed - [Backup][google.spanner.admin.database.v1.Backup]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_get_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.GetBackupRequest( - name="name_value", - ) - - # Make the request - response = client.get_backup(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.GetBackupRequest, dict]): - The request object. The request for - [GetBackup][google.spanner.admin.database.v1.DatabaseAdmin.GetBackup]. - name (str): - Required. Name of the backup. Values are of the form - ``projects//instances//backups/``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.types.Backup: - A backup of a Cloud Spanner database. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a backup.GetBackupRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, backup.GetBackupRequest): - request = backup.GetBackupRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.get_backup] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def update_backup(self, - request: Optional[Union[gsad_backup.UpdateBackupRequest, dict]] = None, - *, - backup: Optional[gsad_backup.Backup] = None, - update_mask: Optional[field_mask_pb2.FieldMask] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> gsad_backup.Backup: - r"""Updates a pending or completed - [Backup][google.spanner.admin.database.v1.Backup]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_update_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.UpdateBackupRequest( - ) - - # Make the request - response = client.update_backup(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.UpdateBackupRequest, dict]): - The request object. The request for - [UpdateBackup][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup]. - backup (google.cloud.spanner_admin_database_v1.types.Backup): - Required. The backup to update. ``backup.name``, and the - fields to be updated as specified by ``update_mask`` are - required. Other fields are ignored. Update is only - supported for the following fields: - - - ``backup.expire_time``. - - This corresponds to the ``backup`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. A mask specifying which fields (e.g. - ``expire_time``) in the Backup resource should be - updated. This mask is relative to the Backup resource, - not to the request message. The field mask must always - be specified; this prevents any future fields from being - erased accidentally by clients that do not know about - them. - - This corresponds to the ``update_mask`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.types.Backup: - A backup of a Cloud Spanner database. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([backup, update_mask]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a gsad_backup.UpdateBackupRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, gsad_backup.UpdateBackupRequest): - request = gsad_backup.UpdateBackupRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if backup is not None: - request.backup = backup - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.update_backup] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("backup.name", request.backup.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def delete_backup(self, - request: Optional[Union[backup.DeleteBackupRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Deletes a pending or completed - [Backup][google.spanner.admin.database.v1.Backup]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_delete_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.DeleteBackupRequest( - name="name_value", - ) - - # Make the request - client.delete_backup(request=request) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.DeleteBackupRequest, dict]): - The request object. The request for - [DeleteBackup][google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup]. - name (str): - Required. Name of the backup to delete. Values are of - the form - ``projects//instances//backups/``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a backup.DeleteBackupRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, backup.DeleteBackupRequest): - request = backup.DeleteBackupRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.delete_backup] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def list_backups(self, - request: Optional[Union[backup.ListBackupsRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListBackupsPager: - r"""Lists completed and pending backups. Backups returned are - ordered by ``create_time`` in descending order, starting from - the most recent ``create_time``. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_list_backups(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListBackupsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_backups(request=request) - - # Handle the response - for response in page_result: - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.ListBackupsRequest, dict]): - The request object. The request for - [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. - parent (str): - Required. The instance to list backups from. Values are - of the form ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupsPager: - The response for - [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a backup.ListBackupsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, backup.ListBackupsRequest): - request = backup.ListBackupsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_backups] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListBackupsPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def restore_database(self, - request: Optional[Union[spanner_database_admin.RestoreDatabaseRequest, dict]] = None, - *, - parent: Optional[str] = None, - database_id: Optional[str] = None, - backup: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Create a new database by restoring from a completed backup. The - new database must be in the same project and in an instance with - the same instance configuration as the instance containing the - backup. The returned database [long-running - operation][google.longrunning.Operation] has a name of the - format - ``projects//instances//databases//operations/``, - and can be used to track the progress of the operation, and to - cancel it. The [metadata][google.longrunning.Operation.metadata] - field type is - [RestoreDatabaseMetadata][google.spanner.admin.database.v1.RestoreDatabaseMetadata]. - The [response][google.longrunning.Operation.response] type is - [Database][google.spanner.admin.database.v1.Database], if - successful. Cancelling the returned operation will stop the - restore and delete the database. There can be only one database - being restored into an instance at a time. Once the restore - operation completes, a new restore operation can be initiated, - without waiting for the optimize operation associated with the - first restore to complete. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_restore_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.RestoreDatabaseRequest( - backup="backup_value", - parent="parent_value", - database_id="database_id_value", - ) - - # Make the request - operation = client.restore_database(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.RestoreDatabaseRequest, dict]): - The request object. The request for - [RestoreDatabase][google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase]. - parent (str): - Required. The name of the instance in which to create - the restored database. This instance must be in the same - project and have the same instance configuration as the - instance containing the source backup. Values are of the - form ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - database_id (str): - Required. The id of the database to create and restore - to. This database must not already exist. The - ``database_id`` appended to ``parent`` forms the full - database name of the form - ``projects//instances//databases/``. - - This corresponds to the ``database_id`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - backup (str): - Name of the backup from which to restore. Values are of - the form - ``projects//instances//backups/``. - - This corresponds to the ``backup`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.spanner_admin_database_v1.types.Database` - A Cloud Spanner database. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, database_id, backup]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_database_admin.RestoreDatabaseRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_database_admin.RestoreDatabaseRequest): - request = spanner_database_admin.RestoreDatabaseRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if database_id is not None: - request.database_id = database_id - if backup is not None: - request.backup = backup - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.restore_database] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - spanner_database_admin.Database, - metadata_type=spanner_database_admin.RestoreDatabaseMetadata, - ) - - # Done; return the response. - return response - - def list_database_operations(self, - request: Optional[Union[spanner_database_admin.ListDatabaseOperationsRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListDatabaseOperationsPager: - r"""Lists database - [longrunning-operations][google.longrunning.Operation]. A - database operation has a name of the form - ``projects//instances//databases//operations/``. - The long-running operation - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - Operations returned include those that have - completed/failed/canceled within the last 7 days, and pending - operations. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_list_database_operations(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListDatabaseOperationsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_database_operations(request=request) - - # Handle the response - for response in page_result: - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest, dict]): - The request object. The request for - [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. - parent (str): - Required. The instance of the database operations. - Values are of the form - ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseOperationsPager: - The response for - [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_database_admin.ListDatabaseOperationsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_database_admin.ListDatabaseOperationsRequest): - request = spanner_database_admin.ListDatabaseOperationsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_database_operations] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListDatabaseOperationsPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def list_backup_operations(self, - request: Optional[Union[backup.ListBackupOperationsRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListBackupOperationsPager: - r"""Lists the backup [long-running - operations][google.longrunning.Operation] in the given instance. - A backup operation has a name of the form - ``projects//instances//backups//operations/``. - The long-running operation - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - Operations returned include those that have - completed/failed/canceled within the last 7 days, and pending - operations. Operations returned are ordered by - ``operation.metadata.value.progress.start_time`` in descending - order starting from the most recently started operation. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_list_backup_operations(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListBackupOperationsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_backup_operations(request=request) - - # Handle the response - for response in page_result: - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest, dict]): - The request object. The request for - [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. - parent (str): - Required. The instance of the backup operations. Values - are of the form - ``projects//instances/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupOperationsPager: - The response for - [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a backup.ListBackupOperationsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, backup.ListBackupOperationsRequest): - request = backup.ListBackupOperationsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_backup_operations] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListBackupOperationsPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def list_database_roles(self, - request: Optional[Union[spanner_database_admin.ListDatabaseRolesRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListDatabaseRolesPager: - r"""Lists Cloud Spanner database roles. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_database_v1 - - def sample_list_database_roles(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListDatabaseRolesRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_database_roles(request=request) - - # Handle the response - for response in page_result: - print(response) - - Args: - request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest, dict]): - The request object. The request for - [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. - parent (str): - Required. The database whose roles should be listed. - Values are of the form - ``projects//instances//databases//databaseRoles``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseRolesPager: - The response for - [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_database_admin.ListDatabaseRolesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_database_admin.ListDatabaseRolesRequest): - request = spanner_database_admin.ListDatabaseRolesRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_database_roles] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListDatabaseRolesPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def __enter__(self) -> "DatabaseAdminClient": - return self - - def __exit__(self, type, value, traceback): - """Releases underlying transport's resources. - - .. warning:: - ONLY use as a context manager if the transport is NOT shared - with other clients! Exiting the with block will CLOSE the transport - and may cause errors in other clients! - """ - self.transport.close() - - def list_operations( - self, - request: Optional[operations_pb2.ListOperationsRequest] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operations_pb2.ListOperationsResponse: - r"""Lists operations that match the specified filter in the request. - - Args: - request (:class:`~.operations_pb2.ListOperationsRequest`): - The request object. Request message for - `ListOperations` method. - retry (google.api_core.retry.Retry): Designation of what errors, - if any, should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - Returns: - ~.operations_pb2.ListOperationsResponse: - Response message for ``ListOperations`` method. - """ - # Create or coerce a protobuf request object. - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.list_operations, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) - - # Send the request. - response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) - - # Done; return the response. - return response - - def get_operation( - self, - request: Optional[operations_pb2.GetOperationRequest] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operations_pb2.Operation: - r"""Gets the latest state of a long-running operation. - - Args: - request (:class:`~.operations_pb2.GetOperationRequest`): - The request object. Request message for - `GetOperation` method. - retry (google.api_core.retry.Retry): Designation of what errors, - if any, should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - Returns: - ~.operations_pb2.Operation: - An ``Operation`` object. - """ - # Create or coerce a protobuf request object. - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.get_operation, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) - - # Send the request. - response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) - - # Done; return the response. - return response - - def delete_operation( - self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Deletes a long-running operation. - - This method indicates that the client is no longer interested - in the operation result. It does not cancel the operation. - If the server doesn't support this method, it returns - `google.rpc.Code.UNIMPLEMENTED`. - - Args: - request (:class:`~.operations_pb2.DeleteOperationRequest`): - The request object. Request message for - `DeleteOperation` method. - retry (google.api_core.retry.Retry): Designation of what errors, - if any, should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - Returns: - None - """ - # Create or coerce a protobuf request object. - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.delete_operation, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) - - # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) - - def cancel_operation( - self, - request: Optional[operations_pb2.CancelOperationRequest] = None, - *, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Starts asynchronous cancellation on a long-running operation. - - The server makes a best effort to cancel the operation, but success - is not guaranteed. If the server doesn't support this method, it returns - `google.rpc.Code.UNIMPLEMENTED`. - - Args: - request (:class:`~.operations_pb2.CancelOperationRequest`): - The request object. Request message for - `CancelOperation` method. - retry (google.api_core.retry.Retry): Designation of what errors, - if any, should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - Returns: - None - """ - # Create or coerce a protobuf request object. - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method.wrap_method( - self._transport.cancel_operation, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), - ) - - # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) - - - - - - - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - - -__all__ = ( - "DatabaseAdminClient", -) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py deleted file mode 100644 index 67c2213658..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py +++ /dev/null @@ -1,625 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from typing import Any, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator - -from google.cloud.spanner_admin_database_v1.types import backup -from google.cloud.spanner_admin_database_v1.types import spanner_database_admin -from google.longrunning import operations_pb2 # type: ignore - - -class ListDatabasesPager: - """A pager for iterating through ``list_databases`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_database_v1.types.ListDatabasesResponse` object, and - provides an ``__iter__`` method to iterate through its - ``databases`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListDatabases`` requests and continue to iterate - through the ``databases`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListDatabasesResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., spanner_database_admin.ListDatabasesResponse], - request: spanner_database_admin.ListDatabasesRequest, - response: spanner_database_admin.ListDatabasesResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest): - The initial request object. - response (google.cloud.spanner_admin_database_v1.types.ListDatabasesResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = spanner_database_admin.ListDatabasesRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[spanner_database_admin.ListDatabasesResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, metadata=self._metadata) - yield self._response - - def __iter__(self) -> Iterator[spanner_database_admin.Database]: - for page in self.pages: - yield from page.databases - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListDatabasesAsyncPager: - """A pager for iterating through ``list_databases`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_database_v1.types.ListDatabasesResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``databases`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListDatabases`` requests and continue to iterate - through the ``databases`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListDatabasesResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., Awaitable[spanner_database_admin.ListDatabasesResponse]], - request: spanner_database_admin.ListDatabasesRequest, - response: spanner_database_admin.ListDatabasesResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiates the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest): - The initial request object. - response (google.cloud.spanner_admin_database_v1.types.ListDatabasesResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = spanner_database_admin.ListDatabasesRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[spanner_database_admin.ListDatabasesResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, metadata=self._metadata) - yield self._response - def __aiter__(self) -> AsyncIterator[spanner_database_admin.Database]: - async def async_generator(): - async for page in self.pages: - for response in page.databases: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListBackupsPager: - """A pager for iterating through ``list_backups`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_database_v1.types.ListBackupsResponse` object, and - provides an ``__iter__`` method to iterate through its - ``backups`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListBackups`` requests and continue to iterate - through the ``backups`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListBackupsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., backup.ListBackupsResponse], - request: backup.ListBackupsRequest, - response: backup.ListBackupsResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_database_v1.types.ListBackupsRequest): - The initial request object. - response (google.cloud.spanner_admin_database_v1.types.ListBackupsResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = backup.ListBackupsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[backup.ListBackupsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, metadata=self._metadata) - yield self._response - - def __iter__(self) -> Iterator[backup.Backup]: - for page in self.pages: - yield from page.backups - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListBackupsAsyncPager: - """A pager for iterating through ``list_backups`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_database_v1.types.ListBackupsResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``backups`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListBackups`` requests and continue to iterate - through the ``backups`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListBackupsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., Awaitable[backup.ListBackupsResponse]], - request: backup.ListBackupsRequest, - response: backup.ListBackupsResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiates the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_database_v1.types.ListBackupsRequest): - The initial request object. - response (google.cloud.spanner_admin_database_v1.types.ListBackupsResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = backup.ListBackupsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[backup.ListBackupsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, metadata=self._metadata) - yield self._response - def __aiter__(self) -> AsyncIterator[backup.Backup]: - async def async_generator(): - async for page in self.pages: - for response in page.backups: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListDatabaseOperationsPager: - """A pager for iterating through ``list_database_operations`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsResponse` object, and - provides an ``__iter__`` method to iterate through its - ``operations`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListDatabaseOperations`` requests and continue to iterate - through the ``operations`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., spanner_database_admin.ListDatabaseOperationsResponse], - request: spanner_database_admin.ListDatabaseOperationsRequest, - response: spanner_database_admin.ListDatabaseOperationsResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest): - The initial request object. - response (google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = spanner_database_admin.ListDatabaseOperationsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[spanner_database_admin.ListDatabaseOperationsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, metadata=self._metadata) - yield self._response - - def __iter__(self) -> Iterator[operations_pb2.Operation]: - for page in self.pages: - yield from page.operations - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListDatabaseOperationsAsyncPager: - """A pager for iterating through ``list_database_operations`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``operations`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListDatabaseOperations`` requests and continue to iterate - through the ``operations`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., Awaitable[spanner_database_admin.ListDatabaseOperationsResponse]], - request: spanner_database_admin.ListDatabaseOperationsRequest, - response: spanner_database_admin.ListDatabaseOperationsResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiates the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest): - The initial request object. - response (google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = spanner_database_admin.ListDatabaseOperationsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[spanner_database_admin.ListDatabaseOperationsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, metadata=self._metadata) - yield self._response - def __aiter__(self) -> AsyncIterator[operations_pb2.Operation]: - async def async_generator(): - async for page in self.pages: - for response in page.operations: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListBackupOperationsPager: - """A pager for iterating through ``list_backup_operations`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_database_v1.types.ListBackupOperationsResponse` object, and - provides an ``__iter__`` method to iterate through its - ``operations`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListBackupOperations`` requests and continue to iterate - through the ``operations`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListBackupOperationsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., backup.ListBackupOperationsResponse], - request: backup.ListBackupOperationsRequest, - response: backup.ListBackupOperationsResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest): - The initial request object. - response (google.cloud.spanner_admin_database_v1.types.ListBackupOperationsResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = backup.ListBackupOperationsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[backup.ListBackupOperationsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, metadata=self._metadata) - yield self._response - - def __iter__(self) -> Iterator[operations_pb2.Operation]: - for page in self.pages: - yield from page.operations - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListBackupOperationsAsyncPager: - """A pager for iterating through ``list_backup_operations`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_database_v1.types.ListBackupOperationsResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``operations`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListBackupOperations`` requests and continue to iterate - through the ``operations`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListBackupOperationsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., Awaitable[backup.ListBackupOperationsResponse]], - request: backup.ListBackupOperationsRequest, - response: backup.ListBackupOperationsResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiates the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest): - The initial request object. - response (google.cloud.spanner_admin_database_v1.types.ListBackupOperationsResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = backup.ListBackupOperationsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[backup.ListBackupOperationsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, metadata=self._metadata) - yield self._response - def __aiter__(self) -> AsyncIterator[operations_pb2.Operation]: - async def async_generator(): - async for page in self.pages: - for response in page.operations: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListDatabaseRolesPager: - """A pager for iterating through ``list_database_roles`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesResponse` object, and - provides an ``__iter__`` method to iterate through its - ``database_roles`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListDatabaseRoles`` requests and continue to iterate - through the ``database_roles`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., spanner_database_admin.ListDatabaseRolesResponse], - request: spanner_database_admin.ListDatabaseRolesRequest, - response: spanner_database_admin.ListDatabaseRolesResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest): - The initial request object. - response (google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = spanner_database_admin.ListDatabaseRolesRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[spanner_database_admin.ListDatabaseRolesResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, metadata=self._metadata) - yield self._response - - def __iter__(self) -> Iterator[spanner_database_admin.DatabaseRole]: - for page in self.pages: - yield from page.database_roles - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListDatabaseRolesAsyncPager: - """A pager for iterating through ``list_database_roles`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``database_roles`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListDatabaseRoles`` requests and continue to iterate - through the ``database_roles`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., Awaitable[spanner_database_admin.ListDatabaseRolesResponse]], - request: spanner_database_admin.ListDatabaseRolesRequest, - response: spanner_database_admin.ListDatabaseRolesResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiates the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest): - The initial request object. - response (google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = spanner_database_admin.ListDatabaseRolesRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[spanner_database_admin.ListDatabaseRolesResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, metadata=self._metadata) - yield self._response - def __aiter__(self) -> AsyncIterator[spanner_database_admin.DatabaseRole]: - async def async_generator(): - async for page in self.pages: - for response in page.database_roles: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py deleted file mode 100644 index 1a310698cc..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py +++ /dev/null @@ -1,38 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -from typing import Dict, Type - -from .base import DatabaseAdminTransport -from .grpc import DatabaseAdminGrpcTransport -from .grpc_asyncio import DatabaseAdminGrpcAsyncIOTransport -from .rest import DatabaseAdminRestTransport -from .rest import DatabaseAdminRestInterceptor - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[DatabaseAdminTransport]] -_transport_registry['grpc'] = DatabaseAdminGrpcTransport -_transport_registry['grpc_asyncio'] = DatabaseAdminGrpcAsyncIOTransport -_transport_registry['rest'] = DatabaseAdminRestTransport - -__all__ = ( - 'DatabaseAdminTransport', - 'DatabaseAdminGrpcTransport', - 'DatabaseAdminGrpcAsyncIOTransport', - 'DatabaseAdminRestTransport', - 'DatabaseAdminRestInterceptor', -) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py deleted file mode 100644 index 591d9a5768..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py +++ /dev/null @@ -1,562 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union - -from google.cloud.spanner_admin_database_v1 import gapic_version as package_version - -import google.auth # type: ignore -import google.api_core -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry as retries -from google.api_core import operations_v1 -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore - -from google.cloud.spanner_admin_database_v1.types import backup -from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup -from google.cloud.spanner_admin_database_v1.types import spanner_database_admin -from google.iam.v1 import iam_policy_pb2 # type: ignore -from google.iam.v1 import policy_pb2 # type: ignore -from google.longrunning import operations_pb2 -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - - -class DatabaseAdminTransport(abc.ABC): - """Abstract transport class for DatabaseAdmin.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.admin', - ) - - DEFAULT_HOST: str = 'spanner.googleapis.com' - def __init__( - self, *, - host: str = DEFAULT_HOST, - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - **kwargs, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A list of scopes. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - """ - - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - - # Save the scopes. - self._scopes = scopes - - # If no credentials are provided, then determine the appropriate - # defaults. - if credentials and credentials_file: - raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") - - if credentials_file is not None: - credentials, _ = google.auth.load_credentials_from_file( - credentials_file, - **scopes_kwargs, - quota_project_id=quota_project_id - ) - elif credentials is None: - credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) - # Don't apply audience if the credentials file passed from user. - if hasattr(credentials, "with_gdch_audience"): - credentials = credentials.with_gdch_audience(api_audience if api_audience else host) - - # If the credentials are service account credentials, then always try to use self signed JWT. - if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): - credentials = credentials.with_always_use_jwt_access(True) - - # Save the credentials. - self._credentials = credentials - - # Save the hostname. Default to port 443 (HTTPS) if none is specified. - if ':' not in host: - host += ':443' - self._host = host - - def _prep_wrapped_messages(self, client_info): - # Precompute the wrapped methods. - self._wrapped_methods = { - self.list_databases: gapic_v1.method.wrap_method( - self.list_databases, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.create_database: gapic_v1.method.wrap_method( - self.create_database, - default_timeout=3600.0, - client_info=client_info, - ), - self.get_database: gapic_v1.method.wrap_method( - self.get_database, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.update_database: gapic_v1.method.wrap_method( - self.update_database, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.update_database_ddl: gapic_v1.method.wrap_method( - self.update_database_ddl, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.drop_database: gapic_v1.method.wrap_method( - self.drop_database, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.get_database_ddl: gapic_v1.method.wrap_method( - self.get_database_ddl, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.set_iam_policy: gapic_v1.method.wrap_method( - self.set_iam_policy, - default_timeout=30.0, - client_info=client_info, - ), - self.get_iam_policy: gapic_v1.method.wrap_method( - self.get_iam_policy, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=client_info, - ), - self.test_iam_permissions: gapic_v1.method.wrap_method( - self.test_iam_permissions, - default_timeout=30.0, - client_info=client_info, - ), - self.create_backup: gapic_v1.method.wrap_method( - self.create_backup, - default_timeout=3600.0, - client_info=client_info, - ), - self.copy_backup: gapic_v1.method.wrap_method( - self.copy_backup, - default_timeout=3600.0, - client_info=client_info, - ), - self.get_backup: gapic_v1.method.wrap_method( - self.get_backup, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.update_backup: gapic_v1.method.wrap_method( - self.update_backup, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.delete_backup: gapic_v1.method.wrap_method( - self.delete_backup, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.list_backups: gapic_v1.method.wrap_method( - self.list_backups, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.restore_database: gapic_v1.method.wrap_method( - self.restore_database, - default_timeout=3600.0, - client_info=client_info, - ), - self.list_database_operations: gapic_v1.method.wrap_method( - self.list_database_operations, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.list_backup_operations: gapic_v1.method.wrap_method( - self.list_backup_operations, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.list_database_roles: gapic_v1.method.wrap_method( - self.list_database_roles, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - } - - def close(self): - """Closes resources associated with the transport. - - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! - """ - raise NotImplementedError() - - @property - def operations_client(self): - """Return the client designed to process long-running operations.""" - raise NotImplementedError() - - @property - def list_databases(self) -> Callable[ - [spanner_database_admin.ListDatabasesRequest], - Union[ - spanner_database_admin.ListDatabasesResponse, - Awaitable[spanner_database_admin.ListDatabasesResponse] - ]]: - raise NotImplementedError() - - @property - def create_database(self) -> Callable[ - [spanner_database_admin.CreateDatabaseRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def get_database(self) -> Callable[ - [spanner_database_admin.GetDatabaseRequest], - Union[ - spanner_database_admin.Database, - Awaitable[spanner_database_admin.Database] - ]]: - raise NotImplementedError() - - @property - def update_database(self) -> Callable[ - [spanner_database_admin.UpdateDatabaseRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def update_database_ddl(self) -> Callable[ - [spanner_database_admin.UpdateDatabaseDdlRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def drop_database(self) -> Callable[ - [spanner_database_admin.DropDatabaseRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def get_database_ddl(self) -> Callable[ - [spanner_database_admin.GetDatabaseDdlRequest], - Union[ - spanner_database_admin.GetDatabaseDdlResponse, - Awaitable[spanner_database_admin.GetDatabaseDdlResponse] - ]]: - raise NotImplementedError() - - @property - def set_iam_policy(self) -> Callable[ - [iam_policy_pb2.SetIamPolicyRequest], - Union[ - policy_pb2.Policy, - Awaitable[policy_pb2.Policy] - ]]: - raise NotImplementedError() - - @property - def get_iam_policy(self) -> Callable[ - [iam_policy_pb2.GetIamPolicyRequest], - Union[ - policy_pb2.Policy, - Awaitable[policy_pb2.Policy] - ]]: - raise NotImplementedError() - - @property - def test_iam_permissions(self) -> Callable[ - [iam_policy_pb2.TestIamPermissionsRequest], - Union[ - iam_policy_pb2.TestIamPermissionsResponse, - Awaitable[iam_policy_pb2.TestIamPermissionsResponse] - ]]: - raise NotImplementedError() - - @property - def create_backup(self) -> Callable[ - [gsad_backup.CreateBackupRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def copy_backup(self) -> Callable[ - [backup.CopyBackupRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def get_backup(self) -> Callable[ - [backup.GetBackupRequest], - Union[ - backup.Backup, - Awaitable[backup.Backup] - ]]: - raise NotImplementedError() - - @property - def update_backup(self) -> Callable[ - [gsad_backup.UpdateBackupRequest], - Union[ - gsad_backup.Backup, - Awaitable[gsad_backup.Backup] - ]]: - raise NotImplementedError() - - @property - def delete_backup(self) -> Callable[ - [backup.DeleteBackupRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def list_backups(self) -> Callable[ - [backup.ListBackupsRequest], - Union[ - backup.ListBackupsResponse, - Awaitable[backup.ListBackupsResponse] - ]]: - raise NotImplementedError() - - @property - def restore_database(self) -> Callable[ - [spanner_database_admin.RestoreDatabaseRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def list_database_operations(self) -> Callable[ - [spanner_database_admin.ListDatabaseOperationsRequest], - Union[ - spanner_database_admin.ListDatabaseOperationsResponse, - Awaitable[spanner_database_admin.ListDatabaseOperationsResponse] - ]]: - raise NotImplementedError() - - @property - def list_backup_operations(self) -> Callable[ - [backup.ListBackupOperationsRequest], - Union[ - backup.ListBackupOperationsResponse, - Awaitable[backup.ListBackupOperationsResponse] - ]]: - raise NotImplementedError() - - @property - def list_database_roles(self) -> Callable[ - [spanner_database_admin.ListDatabaseRolesRequest], - Union[ - spanner_database_admin.ListDatabaseRolesResponse, - Awaitable[spanner_database_admin.ListDatabaseRolesResponse] - ]]: - raise NotImplementedError() - - @property - def list_operations( - self, - ) -> Callable[ - [operations_pb2.ListOperationsRequest], - Union[operations_pb2.ListOperationsResponse, Awaitable[operations_pb2.ListOperationsResponse]], - ]: - raise NotImplementedError() - - @property - def get_operation( - self, - ) -> Callable[ - [operations_pb2.GetOperationRequest], - Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], - ]: - raise NotImplementedError() - - @property - def cancel_operation( - self, - ) -> Callable[ - [operations_pb2.CancelOperationRequest], - None, - ]: - raise NotImplementedError() - - @property - def delete_operation( - self, - ) -> Callable[ - [operations_pb2.DeleteOperationRequest], - None, - ]: - raise NotImplementedError() - - @property - def kind(self) -> str: - raise NotImplementedError() - - -__all__ = ( - 'DatabaseAdminTransport', -) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py deleted file mode 100644 index 002a37a5d3..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py +++ /dev/null @@ -1,1015 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import grpc_helpers -from google.api_core import operations_v1 -from google.api_core import gapic_v1 -import google.auth # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore - -import grpc # type: ignore - -from google.cloud.spanner_admin_database_v1.types import backup -from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup -from google.cloud.spanner_admin_database_v1.types import spanner_database_admin -from google.iam.v1 import iam_policy_pb2 # type: ignore -from google.iam.v1 import policy_pb2 # type: ignore -from google.longrunning import operations_pb2 -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from .base import DatabaseAdminTransport, DEFAULT_CLIENT_INFO - - -class DatabaseAdminGrpcTransport(DatabaseAdminTransport): - """gRPC backend transport for DatabaseAdmin. - - Cloud Spanner Database Admin API - - The Cloud Spanner Database Admin API can be used to: - - - create, drop, and list databases - - update the schema of pre-existing databases - - create, delete and list backups for a database - - restore a database from an existing backup - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - _stubs: Dict[str, Callable] - - def __init__(self, *, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: Optional[grpc.Channel] = None, - api_mtls_endpoint: Optional[str] = None, - client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, - client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if ``channel`` is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - channel (Optional[grpc.Channel]): A ``Channel`` instance through - which to make calls. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or application default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if ``channel`` is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - self._operations_client: Optional[operations_v1.OperationsClient] = None - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if channel: - # Ignore credentials if a channel was passed. - credentials = False - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience, - ) - - if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( - self._host, - # use the credentials which are saved - credentials=self._credentials, - # Set ``credentials_file`` to ``None`` here as - # the credentials that we saved earlier should be used. - credentials_file=None, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Wrap messages. This must be done after self._grpc_channel exists - self._prep_wrapped_messages(client_info) - - @classmethod - def create_channel(cls, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> grpc.Channel: - """Create and return a gRPC channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - grpc.Channel: A gRPC channel object. - - Raises: - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - - return grpc_helpers.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - @property - def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ - return self._grpc_channel - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Create the client designed to process long-running operations. - - This property caches on the instance; repeated calls return the same - client. - """ - # Quick check: Only create a new client if we do not already have one. - if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient( - self.grpc_channel - ) - - # Return the client from cache. - return self._operations_client - - @property - def list_databases(self) -> Callable[ - [spanner_database_admin.ListDatabasesRequest], - spanner_database_admin.ListDatabasesResponse]: - r"""Return a callable for the list databases method over gRPC. - - Lists Cloud Spanner databases. - - Returns: - Callable[[~.ListDatabasesRequest], - ~.ListDatabasesResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_databases' not in self._stubs: - self._stubs['list_databases'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/ListDatabases', - request_serializer=spanner_database_admin.ListDatabasesRequest.serialize, - response_deserializer=spanner_database_admin.ListDatabasesResponse.deserialize, - ) - return self._stubs['list_databases'] - - @property - def create_database(self) -> Callable[ - [spanner_database_admin.CreateDatabaseRequest], - operations_pb2.Operation]: - r"""Return a callable for the create database method over gRPC. - - Creates a new Cloud Spanner database and starts to prepare it - for serving. The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and can be - used to track preparation of the database. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateDatabaseMetadata][google.spanner.admin.database.v1.CreateDatabaseMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Database][google.spanner.admin.database.v1.Database], if - successful. - - Returns: - Callable[[~.CreateDatabaseRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'create_database' not in self._stubs: - self._stubs['create_database'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/CreateDatabase', - request_serializer=spanner_database_admin.CreateDatabaseRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['create_database'] - - @property - def get_database(self) -> Callable[ - [spanner_database_admin.GetDatabaseRequest], - spanner_database_admin.Database]: - r"""Return a callable for the get database method over gRPC. - - Gets the state of a Cloud Spanner database. - - Returns: - Callable[[~.GetDatabaseRequest], - ~.Database]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_database' not in self._stubs: - self._stubs['get_database'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/GetDatabase', - request_serializer=spanner_database_admin.GetDatabaseRequest.serialize, - response_deserializer=spanner_database_admin.Database.deserialize, - ) - return self._stubs['get_database'] - - @property - def update_database(self) -> Callable[ - [spanner_database_admin.UpdateDatabaseRequest], - operations_pb2.Operation]: - r"""Return a callable for the update database method over gRPC. - - Updates a Cloud Spanner database. The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of updating the database. If the named database - does not exist, returns ``NOT_FOUND``. - - While the operation is pending: - - - The database's - [reconciling][google.spanner.admin.database.v1.Database.reconciling] - field is set to true. - - Cancelling the operation is best-effort. If the cancellation - succeeds, the operation metadata's - [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] - is set, the updates are reverted, and the operation - terminates with a ``CANCELLED`` status. - - New UpdateDatabase requests will return a - ``FAILED_PRECONDITION`` error until the pending operation is - done (returns successfully or with error). - - Reading the database via the API continues to give the - pre-request values. - - Upon completion of the returned operation: - - - The new values are in effect and readable via the API. - - The database's - [reconciling][google.spanner.admin.database.v1.Database.reconciling] - field becomes false. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format - ``projects//instances//databases//operations/`` - and can be used to track the database modification. The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Database][google.spanner.admin.database.v1.Database], if - successful. - - Returns: - Callable[[~.UpdateDatabaseRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'update_database' not in self._stubs: - self._stubs['update_database'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/UpdateDatabase', - request_serializer=spanner_database_admin.UpdateDatabaseRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['update_database'] - - @property - def update_database_ddl(self) -> Callable[ - [spanner_database_admin.UpdateDatabaseDdlRequest], - operations_pb2.Operation]: - r"""Return a callable for the update database ddl method over gRPC. - - Updates the schema of a Cloud Spanner database by - creating/altering/dropping tables, columns, indexes, etc. The - returned [long-running operation][google.longrunning.Operation] - will have a name of the format - ``/operations/`` and can be used to - track execution of the schema change(s). The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateDatabaseDdlMetadata][google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata]. - The operation has no response. - - Returns: - Callable[[~.UpdateDatabaseDdlRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'update_database_ddl' not in self._stubs: - self._stubs['update_database_ddl'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/UpdateDatabaseDdl', - request_serializer=spanner_database_admin.UpdateDatabaseDdlRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['update_database_ddl'] - - @property - def drop_database(self) -> Callable[ - [spanner_database_admin.DropDatabaseRequest], - empty_pb2.Empty]: - r"""Return a callable for the drop database method over gRPC. - - Drops (aka deletes) a Cloud Spanner database. Completed backups - for the database will be retained according to their - ``expire_time``. Note: Cloud Spanner might continue to accept - requests for a few seconds after the database has been deleted. - - Returns: - Callable[[~.DropDatabaseRequest], - ~.Empty]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'drop_database' not in self._stubs: - self._stubs['drop_database'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/DropDatabase', - request_serializer=spanner_database_admin.DropDatabaseRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['drop_database'] - - @property - def get_database_ddl(self) -> Callable[ - [spanner_database_admin.GetDatabaseDdlRequest], - spanner_database_admin.GetDatabaseDdlResponse]: - r"""Return a callable for the get database ddl method over gRPC. - - Returns the schema of a Cloud Spanner database as a list of - formatted DDL statements. This method does not show pending - schema updates, those may be queried using the - [Operations][google.longrunning.Operations] API. - - Returns: - Callable[[~.GetDatabaseDdlRequest], - ~.GetDatabaseDdlResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_database_ddl' not in self._stubs: - self._stubs['get_database_ddl'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/GetDatabaseDdl', - request_serializer=spanner_database_admin.GetDatabaseDdlRequest.serialize, - response_deserializer=spanner_database_admin.GetDatabaseDdlResponse.deserialize, - ) - return self._stubs['get_database_ddl'] - - @property - def set_iam_policy(self) -> Callable[ - [iam_policy_pb2.SetIamPolicyRequest], - policy_pb2.Policy]: - r"""Return a callable for the set iam policy method over gRPC. - - Sets the access control policy on a database or backup resource. - Replaces any existing policy. - - Authorization requires ``spanner.databases.setIamPolicy`` - permission on - [resource][google.iam.v1.SetIamPolicyRequest.resource]. For - backups, authorization requires ``spanner.backups.setIamPolicy`` - permission on - [resource][google.iam.v1.SetIamPolicyRequest.resource]. - - Returns: - Callable[[~.SetIamPolicyRequest], - ~.Policy]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'set_iam_policy' not in self._stubs: - self._stubs['set_iam_policy'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/SetIamPolicy', - request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, - response_deserializer=policy_pb2.Policy.FromString, - ) - return self._stubs['set_iam_policy'] - - @property - def get_iam_policy(self) -> Callable[ - [iam_policy_pb2.GetIamPolicyRequest], - policy_pb2.Policy]: - r"""Return a callable for the get iam policy method over gRPC. - - Gets the access control policy for a database or backup - resource. Returns an empty policy if a database or backup exists - but does not have a policy set. - - Authorization requires ``spanner.databases.getIamPolicy`` - permission on - [resource][google.iam.v1.GetIamPolicyRequest.resource]. For - backups, authorization requires ``spanner.backups.getIamPolicy`` - permission on - [resource][google.iam.v1.GetIamPolicyRequest.resource]. - - Returns: - Callable[[~.GetIamPolicyRequest], - ~.Policy]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_iam_policy' not in self._stubs: - self._stubs['get_iam_policy'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/GetIamPolicy', - request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, - response_deserializer=policy_pb2.Policy.FromString, - ) - return self._stubs['get_iam_policy'] - - @property - def test_iam_permissions(self) -> Callable[ - [iam_policy_pb2.TestIamPermissionsRequest], - iam_policy_pb2.TestIamPermissionsResponse]: - r"""Return a callable for the test iam permissions method over gRPC. - - Returns permissions that the caller has on the specified - database or backup resource. - - Attempting this RPC on a non-existent Cloud Spanner database - will result in a NOT_FOUND error if the user has - ``spanner.databases.list`` permission on the containing Cloud - Spanner instance. Otherwise returns an empty set of permissions. - Calling this method on a backup that does not exist will result - in a NOT_FOUND error if the user has ``spanner.backups.list`` - permission on the containing instance. - - Returns: - Callable[[~.TestIamPermissionsRequest], - ~.TestIamPermissionsResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'test_iam_permissions' not in self._stubs: - self._stubs['test_iam_permissions'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/TestIamPermissions', - request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, - response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, - ) - return self._stubs['test_iam_permissions'] - - @property - def create_backup(self) -> Callable[ - [gsad_backup.CreateBackupRequest], - operations_pb2.Operation]: - r"""Return a callable for the create backup method over gRPC. - - Starts creating a new Cloud Spanner Backup. The returned backup - [long-running operation][google.longrunning.Operation] will have - a name of the format - ``projects//instances//backups//operations/`` - and can be used to track creation of the backup. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Backup][google.spanner.admin.database.v1.Backup], if - successful. Cancelling the returned operation will stop the - creation and delete the backup. There can be only one pending - backup creation per database. Backup creation of different - databases can run concurrently. - - Returns: - Callable[[~.CreateBackupRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'create_backup' not in self._stubs: - self._stubs['create_backup'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/CreateBackup', - request_serializer=gsad_backup.CreateBackupRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['create_backup'] - - @property - def copy_backup(self) -> Callable[ - [backup.CopyBackupRequest], - operations_pb2.Operation]: - r"""Return a callable for the copy backup method over gRPC. - - Starts copying a Cloud Spanner Backup. The returned backup - [long-running operation][google.longrunning.Operation] will have - a name of the format - ``projects//instances//backups//operations/`` - and can be used to track copying of the backup. The operation is - associated with the destination backup. The - [metadata][google.longrunning.Operation.metadata] field type is - [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Backup][google.spanner.admin.database.v1.Backup], if - successful. Cancelling the returned operation will stop the - copying and delete the backup. Concurrent CopyBackup requests - can run on the same source backup. - - Returns: - Callable[[~.CopyBackupRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'copy_backup' not in self._stubs: - self._stubs['copy_backup'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/CopyBackup', - request_serializer=backup.CopyBackupRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['copy_backup'] - - @property - def get_backup(self) -> Callable[ - [backup.GetBackupRequest], - backup.Backup]: - r"""Return a callable for the get backup method over gRPC. - - Gets metadata on a pending or completed - [Backup][google.spanner.admin.database.v1.Backup]. - - Returns: - Callable[[~.GetBackupRequest], - ~.Backup]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_backup' not in self._stubs: - self._stubs['get_backup'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/GetBackup', - request_serializer=backup.GetBackupRequest.serialize, - response_deserializer=backup.Backup.deserialize, - ) - return self._stubs['get_backup'] - - @property - def update_backup(self) -> Callable[ - [gsad_backup.UpdateBackupRequest], - gsad_backup.Backup]: - r"""Return a callable for the update backup method over gRPC. - - Updates a pending or completed - [Backup][google.spanner.admin.database.v1.Backup]. - - Returns: - Callable[[~.UpdateBackupRequest], - ~.Backup]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'update_backup' not in self._stubs: - self._stubs['update_backup'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/UpdateBackup', - request_serializer=gsad_backup.UpdateBackupRequest.serialize, - response_deserializer=gsad_backup.Backup.deserialize, - ) - return self._stubs['update_backup'] - - @property - def delete_backup(self) -> Callable[ - [backup.DeleteBackupRequest], - empty_pb2.Empty]: - r"""Return a callable for the delete backup method over gRPC. - - Deletes a pending or completed - [Backup][google.spanner.admin.database.v1.Backup]. - - Returns: - Callable[[~.DeleteBackupRequest], - ~.Empty]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'delete_backup' not in self._stubs: - self._stubs['delete_backup'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/DeleteBackup', - request_serializer=backup.DeleteBackupRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_backup'] - - @property - def list_backups(self) -> Callable[ - [backup.ListBackupsRequest], - backup.ListBackupsResponse]: - r"""Return a callable for the list backups method over gRPC. - - Lists completed and pending backups. Backups returned are - ordered by ``create_time`` in descending order, starting from - the most recent ``create_time``. - - Returns: - Callable[[~.ListBackupsRequest], - ~.ListBackupsResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_backups' not in self._stubs: - self._stubs['list_backups'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/ListBackups', - request_serializer=backup.ListBackupsRequest.serialize, - response_deserializer=backup.ListBackupsResponse.deserialize, - ) - return self._stubs['list_backups'] - - @property - def restore_database(self) -> Callable[ - [spanner_database_admin.RestoreDatabaseRequest], - operations_pb2.Operation]: - r"""Return a callable for the restore database method over gRPC. - - Create a new database by restoring from a completed backup. The - new database must be in the same project and in an instance with - the same instance configuration as the instance containing the - backup. The returned database [long-running - operation][google.longrunning.Operation] has a name of the - format - ``projects//instances//databases//operations/``, - and can be used to track the progress of the operation, and to - cancel it. The [metadata][google.longrunning.Operation.metadata] - field type is - [RestoreDatabaseMetadata][google.spanner.admin.database.v1.RestoreDatabaseMetadata]. - The [response][google.longrunning.Operation.response] type is - [Database][google.spanner.admin.database.v1.Database], if - successful. Cancelling the returned operation will stop the - restore and delete the database. There can be only one database - being restored into an instance at a time. Once the restore - operation completes, a new restore operation can be initiated, - without waiting for the optimize operation associated with the - first restore to complete. - - Returns: - Callable[[~.RestoreDatabaseRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'restore_database' not in self._stubs: - self._stubs['restore_database'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/RestoreDatabase', - request_serializer=spanner_database_admin.RestoreDatabaseRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['restore_database'] - - @property - def list_database_operations(self) -> Callable[ - [spanner_database_admin.ListDatabaseOperationsRequest], - spanner_database_admin.ListDatabaseOperationsResponse]: - r"""Return a callable for the list database operations method over gRPC. - - Lists database - [longrunning-operations][google.longrunning.Operation]. A - database operation has a name of the form - ``projects//instances//databases//operations/``. - The long-running operation - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - Operations returned include those that have - completed/failed/canceled within the last 7 days, and pending - operations. - - Returns: - Callable[[~.ListDatabaseOperationsRequest], - ~.ListDatabaseOperationsResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_database_operations' not in self._stubs: - self._stubs['list_database_operations'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/ListDatabaseOperations', - request_serializer=spanner_database_admin.ListDatabaseOperationsRequest.serialize, - response_deserializer=spanner_database_admin.ListDatabaseOperationsResponse.deserialize, - ) - return self._stubs['list_database_operations'] - - @property - def list_backup_operations(self) -> Callable[ - [backup.ListBackupOperationsRequest], - backup.ListBackupOperationsResponse]: - r"""Return a callable for the list backup operations method over gRPC. - - Lists the backup [long-running - operations][google.longrunning.Operation] in the given instance. - A backup operation has a name of the form - ``projects//instances//backups//operations/``. - The long-running operation - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - Operations returned include those that have - completed/failed/canceled within the last 7 days, and pending - operations. Operations returned are ordered by - ``operation.metadata.value.progress.start_time`` in descending - order starting from the most recently started operation. - - Returns: - Callable[[~.ListBackupOperationsRequest], - ~.ListBackupOperationsResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_backup_operations' not in self._stubs: - self._stubs['list_backup_operations'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/ListBackupOperations', - request_serializer=backup.ListBackupOperationsRequest.serialize, - response_deserializer=backup.ListBackupOperationsResponse.deserialize, - ) - return self._stubs['list_backup_operations'] - - @property - def list_database_roles(self) -> Callable[ - [spanner_database_admin.ListDatabaseRolesRequest], - spanner_database_admin.ListDatabaseRolesResponse]: - r"""Return a callable for the list database roles method over gRPC. - - Lists Cloud Spanner database roles. - - Returns: - Callable[[~.ListDatabaseRolesRequest], - ~.ListDatabaseRolesResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_database_roles' not in self._stubs: - self._stubs['list_database_roles'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/ListDatabaseRoles', - request_serializer=spanner_database_admin.ListDatabaseRolesRequest.serialize, - response_deserializer=spanner_database_admin.ListDatabaseRolesResponse.deserialize, - ) - return self._stubs['list_database_roles'] - - def close(self): - self.grpc_channel.close() - - @property - def delete_operation( - self, - ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: - r"""Return a callable for the delete_operation method over gRPC. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "delete_operation" not in self._stubs: - self._stubs["delete_operation"] = self.grpc_channel.unary_unary( - "/google.longrunning.Operations/DeleteOperation", - request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, - response_deserializer=None, - ) - return self._stubs["delete_operation"] - - @property - def cancel_operation( - self, - ) -> Callable[[operations_pb2.CancelOperationRequest], None]: - r"""Return a callable for the cancel_operation method over gRPC. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "cancel_operation" not in self._stubs: - self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( - "/google.longrunning.Operations/CancelOperation", - request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, - response_deserializer=None, - ) - return self._stubs["cancel_operation"] - - @property - def get_operation( - self, - ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: - r"""Return a callable for the get_operation method over gRPC. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( - "/google.longrunning.Operations/GetOperation", - request_serializer=operations_pb2.GetOperationRequest.SerializeToString, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs["get_operation"] - - @property - def list_operations( - self, - ) -> Callable[[operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse]: - r"""Return a callable for the list_operations method over gRPC. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( - "/google.longrunning.Operations/ListOperations", - request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, - response_deserializer=operations_pb2.ListOperationsResponse.FromString, - ) - return self._stubs["list_operations"] - - @property - def kind(self) -> str: - return "grpc" - - -__all__ = ( - 'DatabaseAdminGrpcTransport', -) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py deleted file mode 100644 index 6942dd3a30..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py +++ /dev/null @@ -1,1014 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers_async -from google.api_core import operations_v1 -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore - -import grpc # type: ignore -from grpc.experimental import aio # type: ignore - -from google.cloud.spanner_admin_database_v1.types import backup -from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup -from google.cloud.spanner_admin_database_v1.types import spanner_database_admin -from google.iam.v1 import iam_policy_pb2 # type: ignore -from google.iam.v1 import policy_pb2 # type: ignore -from google.longrunning import operations_pb2 -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from .base import DatabaseAdminTransport, DEFAULT_CLIENT_INFO -from .grpc import DatabaseAdminGrpcTransport - - -class DatabaseAdminGrpcAsyncIOTransport(DatabaseAdminTransport): - """gRPC AsyncIO backend transport for DatabaseAdmin. - - Cloud Spanner Database Admin API - - The Cloud Spanner Database Admin API can be used to: - - - create, drop, and list databases - - update the schema of pre-existing databases - - create, delete and list backups for a database - - restore a database from an existing backup - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - - _grpc_channel: aio.Channel - _stubs: Dict[str, Callable] = {} - - @classmethod - def create_channel(cls, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> aio.Channel: - """Create and return a gRPC AsyncIO channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - aio.Channel: A gRPC AsyncIO channel object. - """ - - return grpc_helpers_async.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - def __init__(self, *, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: Optional[aio.Channel] = None, - api_mtls_endpoint: Optional[str] = None, - client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, - client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if ``channel`` is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - channel (Optional[aio.Channel]): A ``Channel`` instance through - which to make calls. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or application default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if ``channel`` is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if channel: - # Ignore credentials if a channel was passed. - credentials = False - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience, - ) - - if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( - self._host, - # use the credentials which are saved - credentials=self._credentials, - # Set ``credentials_file`` to ``None`` here as - # the credentials that we saved earlier should be used. - credentials_file=None, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Wrap messages. This must be done after self._grpc_channel exists - self._prep_wrapped_messages(client_info) - - @property - def grpc_channel(self) -> aio.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. - """ - # Return the channel from cache. - return self._grpc_channel - - @property - def operations_client(self) -> operations_v1.OperationsAsyncClient: - """Create the client designed to process long-running operations. - - This property caches on the instance; repeated calls return the same - client. - """ - # Quick check: Only create a new client if we do not already have one. - if self._operations_client is None: - self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel - ) - - # Return the client from cache. - return self._operations_client - - @property - def list_databases(self) -> Callable[ - [spanner_database_admin.ListDatabasesRequest], - Awaitable[spanner_database_admin.ListDatabasesResponse]]: - r"""Return a callable for the list databases method over gRPC. - - Lists Cloud Spanner databases. - - Returns: - Callable[[~.ListDatabasesRequest], - Awaitable[~.ListDatabasesResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_databases' not in self._stubs: - self._stubs['list_databases'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/ListDatabases', - request_serializer=spanner_database_admin.ListDatabasesRequest.serialize, - response_deserializer=spanner_database_admin.ListDatabasesResponse.deserialize, - ) - return self._stubs['list_databases'] - - @property - def create_database(self) -> Callable[ - [spanner_database_admin.CreateDatabaseRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the create database method over gRPC. - - Creates a new Cloud Spanner database and starts to prepare it - for serving. The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and can be - used to track preparation of the database. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateDatabaseMetadata][google.spanner.admin.database.v1.CreateDatabaseMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Database][google.spanner.admin.database.v1.Database], if - successful. - - Returns: - Callable[[~.CreateDatabaseRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'create_database' not in self._stubs: - self._stubs['create_database'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/CreateDatabase', - request_serializer=spanner_database_admin.CreateDatabaseRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['create_database'] - - @property - def get_database(self) -> Callable[ - [spanner_database_admin.GetDatabaseRequest], - Awaitable[spanner_database_admin.Database]]: - r"""Return a callable for the get database method over gRPC. - - Gets the state of a Cloud Spanner database. - - Returns: - Callable[[~.GetDatabaseRequest], - Awaitable[~.Database]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_database' not in self._stubs: - self._stubs['get_database'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/GetDatabase', - request_serializer=spanner_database_admin.GetDatabaseRequest.serialize, - response_deserializer=spanner_database_admin.Database.deserialize, - ) - return self._stubs['get_database'] - - @property - def update_database(self) -> Callable[ - [spanner_database_admin.UpdateDatabaseRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the update database method over gRPC. - - Updates a Cloud Spanner database. The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of updating the database. If the named database - does not exist, returns ``NOT_FOUND``. - - While the operation is pending: - - - The database's - [reconciling][google.spanner.admin.database.v1.Database.reconciling] - field is set to true. - - Cancelling the operation is best-effort. If the cancellation - succeeds, the operation metadata's - [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time] - is set, the updates are reverted, and the operation - terminates with a ``CANCELLED`` status. - - New UpdateDatabase requests will return a - ``FAILED_PRECONDITION`` error until the pending operation is - done (returns successfully or with error). - - Reading the database via the API continues to give the - pre-request values. - - Upon completion of the returned operation: - - - The new values are in effect and readable via the API. - - The database's - [reconciling][google.spanner.admin.database.v1.Database.reconciling] - field becomes false. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format - ``projects//instances//databases//operations/`` - and can be used to track the database modification. The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Database][google.spanner.admin.database.v1.Database], if - successful. - - Returns: - Callable[[~.UpdateDatabaseRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'update_database' not in self._stubs: - self._stubs['update_database'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/UpdateDatabase', - request_serializer=spanner_database_admin.UpdateDatabaseRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['update_database'] - - @property - def update_database_ddl(self) -> Callable[ - [spanner_database_admin.UpdateDatabaseDdlRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the update database ddl method over gRPC. - - Updates the schema of a Cloud Spanner database by - creating/altering/dropping tables, columns, indexes, etc. The - returned [long-running operation][google.longrunning.Operation] - will have a name of the format - ``/operations/`` and can be used to - track execution of the schema change(s). The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateDatabaseDdlMetadata][google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata]. - The operation has no response. - - Returns: - Callable[[~.UpdateDatabaseDdlRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'update_database_ddl' not in self._stubs: - self._stubs['update_database_ddl'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/UpdateDatabaseDdl', - request_serializer=spanner_database_admin.UpdateDatabaseDdlRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['update_database_ddl'] - - @property - def drop_database(self) -> Callable[ - [spanner_database_admin.DropDatabaseRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the drop database method over gRPC. - - Drops (aka deletes) a Cloud Spanner database. Completed backups - for the database will be retained according to their - ``expire_time``. Note: Cloud Spanner might continue to accept - requests for a few seconds after the database has been deleted. - - Returns: - Callable[[~.DropDatabaseRequest], - Awaitable[~.Empty]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'drop_database' not in self._stubs: - self._stubs['drop_database'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/DropDatabase', - request_serializer=spanner_database_admin.DropDatabaseRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['drop_database'] - - @property - def get_database_ddl(self) -> Callable[ - [spanner_database_admin.GetDatabaseDdlRequest], - Awaitable[spanner_database_admin.GetDatabaseDdlResponse]]: - r"""Return a callable for the get database ddl method over gRPC. - - Returns the schema of a Cloud Spanner database as a list of - formatted DDL statements. This method does not show pending - schema updates, those may be queried using the - [Operations][google.longrunning.Operations] API. - - Returns: - Callable[[~.GetDatabaseDdlRequest], - Awaitable[~.GetDatabaseDdlResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_database_ddl' not in self._stubs: - self._stubs['get_database_ddl'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/GetDatabaseDdl', - request_serializer=spanner_database_admin.GetDatabaseDdlRequest.serialize, - response_deserializer=spanner_database_admin.GetDatabaseDdlResponse.deserialize, - ) - return self._stubs['get_database_ddl'] - - @property - def set_iam_policy(self) -> Callable[ - [iam_policy_pb2.SetIamPolicyRequest], - Awaitable[policy_pb2.Policy]]: - r"""Return a callable for the set iam policy method over gRPC. - - Sets the access control policy on a database or backup resource. - Replaces any existing policy. - - Authorization requires ``spanner.databases.setIamPolicy`` - permission on - [resource][google.iam.v1.SetIamPolicyRequest.resource]. For - backups, authorization requires ``spanner.backups.setIamPolicy`` - permission on - [resource][google.iam.v1.SetIamPolicyRequest.resource]. - - Returns: - Callable[[~.SetIamPolicyRequest], - Awaitable[~.Policy]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'set_iam_policy' not in self._stubs: - self._stubs['set_iam_policy'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/SetIamPolicy', - request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, - response_deserializer=policy_pb2.Policy.FromString, - ) - return self._stubs['set_iam_policy'] - - @property - def get_iam_policy(self) -> Callable[ - [iam_policy_pb2.GetIamPolicyRequest], - Awaitable[policy_pb2.Policy]]: - r"""Return a callable for the get iam policy method over gRPC. - - Gets the access control policy for a database or backup - resource. Returns an empty policy if a database or backup exists - but does not have a policy set. - - Authorization requires ``spanner.databases.getIamPolicy`` - permission on - [resource][google.iam.v1.GetIamPolicyRequest.resource]. For - backups, authorization requires ``spanner.backups.getIamPolicy`` - permission on - [resource][google.iam.v1.GetIamPolicyRequest.resource]. - - Returns: - Callable[[~.GetIamPolicyRequest], - Awaitable[~.Policy]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_iam_policy' not in self._stubs: - self._stubs['get_iam_policy'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/GetIamPolicy', - request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, - response_deserializer=policy_pb2.Policy.FromString, - ) - return self._stubs['get_iam_policy'] - - @property - def test_iam_permissions(self) -> Callable[ - [iam_policy_pb2.TestIamPermissionsRequest], - Awaitable[iam_policy_pb2.TestIamPermissionsResponse]]: - r"""Return a callable for the test iam permissions method over gRPC. - - Returns permissions that the caller has on the specified - database or backup resource. - - Attempting this RPC on a non-existent Cloud Spanner database - will result in a NOT_FOUND error if the user has - ``spanner.databases.list`` permission on the containing Cloud - Spanner instance. Otherwise returns an empty set of permissions. - Calling this method on a backup that does not exist will result - in a NOT_FOUND error if the user has ``spanner.backups.list`` - permission on the containing instance. - - Returns: - Callable[[~.TestIamPermissionsRequest], - Awaitable[~.TestIamPermissionsResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'test_iam_permissions' not in self._stubs: - self._stubs['test_iam_permissions'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/TestIamPermissions', - request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, - response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, - ) - return self._stubs['test_iam_permissions'] - - @property - def create_backup(self) -> Callable[ - [gsad_backup.CreateBackupRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the create backup method over gRPC. - - Starts creating a new Cloud Spanner Backup. The returned backup - [long-running operation][google.longrunning.Operation] will have - a name of the format - ``projects//instances//backups//operations/`` - and can be used to track creation of the backup. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Backup][google.spanner.admin.database.v1.Backup], if - successful. Cancelling the returned operation will stop the - creation and delete the backup. There can be only one pending - backup creation per database. Backup creation of different - databases can run concurrently. - - Returns: - Callable[[~.CreateBackupRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'create_backup' not in self._stubs: - self._stubs['create_backup'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/CreateBackup', - request_serializer=gsad_backup.CreateBackupRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['create_backup'] - - @property - def copy_backup(self) -> Callable[ - [backup.CopyBackupRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the copy backup method over gRPC. - - Starts copying a Cloud Spanner Backup. The returned backup - [long-running operation][google.longrunning.Operation] will have - a name of the format - ``projects//instances//backups//operations/`` - and can be used to track copying of the backup. The operation is - associated with the destination backup. The - [metadata][google.longrunning.Operation.metadata] field type is - [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Backup][google.spanner.admin.database.v1.Backup], if - successful. Cancelling the returned operation will stop the - copying and delete the backup. Concurrent CopyBackup requests - can run on the same source backup. - - Returns: - Callable[[~.CopyBackupRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'copy_backup' not in self._stubs: - self._stubs['copy_backup'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/CopyBackup', - request_serializer=backup.CopyBackupRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['copy_backup'] - - @property - def get_backup(self) -> Callable[ - [backup.GetBackupRequest], - Awaitable[backup.Backup]]: - r"""Return a callable for the get backup method over gRPC. - - Gets metadata on a pending or completed - [Backup][google.spanner.admin.database.v1.Backup]. - - Returns: - Callable[[~.GetBackupRequest], - Awaitable[~.Backup]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_backup' not in self._stubs: - self._stubs['get_backup'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/GetBackup', - request_serializer=backup.GetBackupRequest.serialize, - response_deserializer=backup.Backup.deserialize, - ) - return self._stubs['get_backup'] - - @property - def update_backup(self) -> Callable[ - [gsad_backup.UpdateBackupRequest], - Awaitable[gsad_backup.Backup]]: - r"""Return a callable for the update backup method over gRPC. - - Updates a pending or completed - [Backup][google.spanner.admin.database.v1.Backup]. - - Returns: - Callable[[~.UpdateBackupRequest], - Awaitable[~.Backup]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'update_backup' not in self._stubs: - self._stubs['update_backup'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/UpdateBackup', - request_serializer=gsad_backup.UpdateBackupRequest.serialize, - response_deserializer=gsad_backup.Backup.deserialize, - ) - return self._stubs['update_backup'] - - @property - def delete_backup(self) -> Callable[ - [backup.DeleteBackupRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the delete backup method over gRPC. - - Deletes a pending or completed - [Backup][google.spanner.admin.database.v1.Backup]. - - Returns: - Callable[[~.DeleteBackupRequest], - Awaitable[~.Empty]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'delete_backup' not in self._stubs: - self._stubs['delete_backup'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/DeleteBackup', - request_serializer=backup.DeleteBackupRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_backup'] - - @property - def list_backups(self) -> Callable[ - [backup.ListBackupsRequest], - Awaitable[backup.ListBackupsResponse]]: - r"""Return a callable for the list backups method over gRPC. - - Lists completed and pending backups. Backups returned are - ordered by ``create_time`` in descending order, starting from - the most recent ``create_time``. - - Returns: - Callable[[~.ListBackupsRequest], - Awaitable[~.ListBackupsResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_backups' not in self._stubs: - self._stubs['list_backups'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/ListBackups', - request_serializer=backup.ListBackupsRequest.serialize, - response_deserializer=backup.ListBackupsResponse.deserialize, - ) - return self._stubs['list_backups'] - - @property - def restore_database(self) -> Callable[ - [spanner_database_admin.RestoreDatabaseRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the restore database method over gRPC. - - Create a new database by restoring from a completed backup. The - new database must be in the same project and in an instance with - the same instance configuration as the instance containing the - backup. The returned database [long-running - operation][google.longrunning.Operation] has a name of the - format - ``projects//instances//databases//operations/``, - and can be used to track the progress of the operation, and to - cancel it. The [metadata][google.longrunning.Operation.metadata] - field type is - [RestoreDatabaseMetadata][google.spanner.admin.database.v1.RestoreDatabaseMetadata]. - The [response][google.longrunning.Operation.response] type is - [Database][google.spanner.admin.database.v1.Database], if - successful. Cancelling the returned operation will stop the - restore and delete the database. There can be only one database - being restored into an instance at a time. Once the restore - operation completes, a new restore operation can be initiated, - without waiting for the optimize operation associated with the - first restore to complete. - - Returns: - Callable[[~.RestoreDatabaseRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'restore_database' not in self._stubs: - self._stubs['restore_database'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/RestoreDatabase', - request_serializer=spanner_database_admin.RestoreDatabaseRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['restore_database'] - - @property - def list_database_operations(self) -> Callable[ - [spanner_database_admin.ListDatabaseOperationsRequest], - Awaitable[spanner_database_admin.ListDatabaseOperationsResponse]]: - r"""Return a callable for the list database operations method over gRPC. - - Lists database - [longrunning-operations][google.longrunning.Operation]. A - database operation has a name of the form - ``projects//instances//databases//operations/``. - The long-running operation - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - Operations returned include those that have - completed/failed/canceled within the last 7 days, and pending - operations. - - Returns: - Callable[[~.ListDatabaseOperationsRequest], - Awaitable[~.ListDatabaseOperationsResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_database_operations' not in self._stubs: - self._stubs['list_database_operations'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/ListDatabaseOperations', - request_serializer=spanner_database_admin.ListDatabaseOperationsRequest.serialize, - response_deserializer=spanner_database_admin.ListDatabaseOperationsResponse.deserialize, - ) - return self._stubs['list_database_operations'] - - @property - def list_backup_operations(self) -> Callable[ - [backup.ListBackupOperationsRequest], - Awaitable[backup.ListBackupOperationsResponse]]: - r"""Return a callable for the list backup operations method over gRPC. - - Lists the backup [long-running - operations][google.longrunning.Operation] in the given instance. - A backup operation has a name of the form - ``projects//instances//backups//operations/``. - The long-running operation - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - Operations returned include those that have - completed/failed/canceled within the last 7 days, and pending - operations. Operations returned are ordered by - ``operation.metadata.value.progress.start_time`` in descending - order starting from the most recently started operation. - - Returns: - Callable[[~.ListBackupOperationsRequest], - Awaitable[~.ListBackupOperationsResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_backup_operations' not in self._stubs: - self._stubs['list_backup_operations'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/ListBackupOperations', - request_serializer=backup.ListBackupOperationsRequest.serialize, - response_deserializer=backup.ListBackupOperationsResponse.deserialize, - ) - return self._stubs['list_backup_operations'] - - @property - def list_database_roles(self) -> Callable[ - [spanner_database_admin.ListDatabaseRolesRequest], - Awaitable[spanner_database_admin.ListDatabaseRolesResponse]]: - r"""Return a callable for the list database roles method over gRPC. - - Lists Cloud Spanner database roles. - - Returns: - Callable[[~.ListDatabaseRolesRequest], - Awaitable[~.ListDatabaseRolesResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_database_roles' not in self._stubs: - self._stubs['list_database_roles'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.database.v1.DatabaseAdmin/ListDatabaseRoles', - request_serializer=spanner_database_admin.ListDatabaseRolesRequest.serialize, - response_deserializer=spanner_database_admin.ListDatabaseRolesResponse.deserialize, - ) - return self._stubs['list_database_roles'] - - def close(self): - return self.grpc_channel.close() - - @property - def delete_operation( - self, - ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: - r"""Return a callable for the delete_operation method over gRPC. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "delete_operation" not in self._stubs: - self._stubs["delete_operation"] = self.grpc_channel.unary_unary( - "/google.longrunning.Operations/DeleteOperation", - request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, - response_deserializer=None, - ) - return self._stubs["delete_operation"] - - @property - def cancel_operation( - self, - ) -> Callable[[operations_pb2.CancelOperationRequest], None]: - r"""Return a callable for the cancel_operation method over gRPC. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "cancel_operation" not in self._stubs: - self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( - "/google.longrunning.Operations/CancelOperation", - request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, - response_deserializer=None, - ) - return self._stubs["cancel_operation"] - - @property - def get_operation( - self, - ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: - r"""Return a callable for the get_operation method over gRPC. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "get_operation" not in self._stubs: - self._stubs["get_operation"] = self.grpc_channel.unary_unary( - "/google.longrunning.Operations/GetOperation", - request_serializer=operations_pb2.GetOperationRequest.SerializeToString, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs["get_operation"] - - @property - def list_operations( - self, - ) -> Callable[[operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse]: - r"""Return a callable for the list_operations method over gRPC. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if "list_operations" not in self._stubs: - self._stubs["list_operations"] = self.grpc_channel.unary_unary( - "/google.longrunning.Operations/ListOperations", - request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, - response_deserializer=operations_pb2.ListOperationsResponse.FromString, - ) - return self._stubs["list_operations"] - - -__all__ = ( - 'DatabaseAdminGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py deleted file mode 100644 index ad9d98696f..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py +++ /dev/null @@ -1,3132 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from google.auth.transport.requests import AuthorizedSession # type: ignore -import json # type: ignore -import grpc # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.api_core import exceptions as core_exceptions -from google.api_core import retry as retries -from google.api_core import rest_helpers -from google.api_core import rest_streaming -from google.api_core import path_template -from google.api_core import gapic_v1 - -from google.protobuf import json_format -from google.api_core import operations_v1 -from google.longrunning import operations_pb2 -from requests import __version__ as requests_version -import dataclasses -import re -from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union -import warnings - -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object] # type: ignore - - -from google.cloud.spanner_admin_database_v1.types import backup -from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup -from google.cloud.spanner_admin_database_v1.types import spanner_database_admin -from google.iam.v1 import iam_policy_pb2 # type: ignore -from google.iam.v1 import policy_pb2 # type: ignore -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore - -from .base import DatabaseAdminTransport, DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO - - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, - grpc_version=None, - rest_version=requests_version, -) - - -class DatabaseAdminRestInterceptor: - """Interceptor for DatabaseAdmin. - - Interceptors are used to manipulate requests, request metadata, and responses - in arbitrary ways. - Example use cases include: - * Logging - * Verifying requests according to service or custom semantics - * Stripping extraneous information from responses - - These use cases and more can be enabled by injecting an - instance of a custom subclass when constructing the DatabaseAdminRestTransport. - - .. code-block:: python - class MyCustomDatabaseAdminInterceptor(DatabaseAdminRestInterceptor): - def pre_copy_backup(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_copy_backup(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_create_backup(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_create_backup(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_create_database(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_create_database(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_delete_backup(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def pre_drop_database(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def pre_get_backup(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_get_backup(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_get_database(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_get_database(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_get_database_ddl(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_get_database_ddl(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_get_iam_policy(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_get_iam_policy(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_list_backup_operations(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_list_backup_operations(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_list_backups(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_list_backups(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_list_database_operations(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_list_database_operations(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_list_database_roles(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_list_database_roles(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_list_databases(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_list_databases(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_restore_database(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_restore_database(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_set_iam_policy(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_set_iam_policy(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_test_iam_permissions(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_test_iam_permissions(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_update_backup(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_update_backup(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_update_database(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_update_database(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_update_database_ddl(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_update_database_ddl(self, response): - logging.log(f"Received response: {response}") - return response - - transport = DatabaseAdminRestTransport(interceptor=MyCustomDatabaseAdminInterceptor()) - client = DatabaseAdminClient(transport=transport) - - - """ - def pre_copy_backup(self, request: backup.CopyBackupRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[backup.CopyBackupRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for copy_backup - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_copy_backup(self, response: operations_pb2.Operation) -> operations_pb2.Operation: - """Post-rpc interceptor for copy_backup - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_create_backup(self, request: gsad_backup.CreateBackupRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[gsad_backup.CreateBackupRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for create_backup - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_create_backup(self, response: operations_pb2.Operation) -> operations_pb2.Operation: - """Post-rpc interceptor for create_backup - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_create_database(self, request: spanner_database_admin.CreateDatabaseRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.CreateDatabaseRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for create_database - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_create_database(self, response: operations_pb2.Operation) -> operations_pb2.Operation: - """Post-rpc interceptor for create_database - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_delete_backup(self, request: backup.DeleteBackupRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[backup.DeleteBackupRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for delete_backup - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def pre_drop_database(self, request: spanner_database_admin.DropDatabaseRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.DropDatabaseRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for drop_database - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def pre_get_backup(self, request: backup.GetBackupRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[backup.GetBackupRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for get_backup - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_get_backup(self, response: backup.Backup) -> backup.Backup: - """Post-rpc interceptor for get_backup - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_get_database(self, request: spanner_database_admin.GetDatabaseRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.GetDatabaseRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for get_database - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_get_database(self, response: spanner_database_admin.Database) -> spanner_database_admin.Database: - """Post-rpc interceptor for get_database - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_get_database_ddl(self, request: spanner_database_admin.GetDatabaseDdlRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.GetDatabaseDdlRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for get_database_ddl - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_get_database_ddl(self, response: spanner_database_admin.GetDatabaseDdlResponse) -> spanner_database_admin.GetDatabaseDdlResponse: - """Post-rpc interceptor for get_database_ddl - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_get_iam_policy(self, request: iam_policy_pb2.GetIamPolicyRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for get_iam_policy - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_get_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: - """Post-rpc interceptor for get_iam_policy - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_list_backup_operations(self, request: backup.ListBackupOperationsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[backup.ListBackupOperationsRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for list_backup_operations - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_list_backup_operations(self, response: backup.ListBackupOperationsResponse) -> backup.ListBackupOperationsResponse: - """Post-rpc interceptor for list_backup_operations - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_list_backups(self, request: backup.ListBackupsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[backup.ListBackupsRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for list_backups - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_list_backups(self, response: backup.ListBackupsResponse) -> backup.ListBackupsResponse: - """Post-rpc interceptor for list_backups - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_list_database_operations(self, request: spanner_database_admin.ListDatabaseOperationsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.ListDatabaseOperationsRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for list_database_operations - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_list_database_operations(self, response: spanner_database_admin.ListDatabaseOperationsResponse) -> spanner_database_admin.ListDatabaseOperationsResponse: - """Post-rpc interceptor for list_database_operations - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_list_database_roles(self, request: spanner_database_admin.ListDatabaseRolesRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.ListDatabaseRolesRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for list_database_roles - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_list_database_roles(self, response: spanner_database_admin.ListDatabaseRolesResponse) -> spanner_database_admin.ListDatabaseRolesResponse: - """Post-rpc interceptor for list_database_roles - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_list_databases(self, request: spanner_database_admin.ListDatabasesRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.ListDatabasesRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for list_databases - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_list_databases(self, response: spanner_database_admin.ListDatabasesResponse) -> spanner_database_admin.ListDatabasesResponse: - """Post-rpc interceptor for list_databases - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_restore_database(self, request: spanner_database_admin.RestoreDatabaseRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.RestoreDatabaseRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for restore_database - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_restore_database(self, response: operations_pb2.Operation) -> operations_pb2.Operation: - """Post-rpc interceptor for restore_database - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_set_iam_policy(self, request: iam_policy_pb2.SetIamPolicyRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for set_iam_policy - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_set_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: - """Post-rpc interceptor for set_iam_policy - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_test_iam_permissions(self, request: iam_policy_pb2.TestIamPermissionsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[iam_policy_pb2.TestIamPermissionsRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for test_iam_permissions - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_test_iam_permissions(self, response: iam_policy_pb2.TestIamPermissionsResponse) -> iam_policy_pb2.TestIamPermissionsResponse: - """Post-rpc interceptor for test_iam_permissions - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_update_backup(self, request: gsad_backup.UpdateBackupRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[gsad_backup.UpdateBackupRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for update_backup - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_update_backup(self, response: gsad_backup.Backup) -> gsad_backup.Backup: - """Post-rpc interceptor for update_backup - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_update_database(self, request: spanner_database_admin.UpdateDatabaseRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.UpdateDatabaseRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for update_database - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_update_database(self, response: operations_pb2.Operation) -> operations_pb2.Operation: - """Post-rpc interceptor for update_database - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_update_database_ddl(self, request: spanner_database_admin.UpdateDatabaseDdlRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_database_admin.UpdateDatabaseDdlRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for update_database_ddl - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_update_database_ddl(self, response: operations_pb2.Operation) -> operations_pb2.Operation: - """Post-rpc interceptor for update_database_ddl - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - - def pre_cancel_operation( - self, request: operations_pb2.CancelOperationRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[operations_pb2.CancelOperationRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for cancel_operation - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_cancel_operation( - self, response: None - ) -> None: - """Post-rpc interceptor for cancel_operation - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_delete_operation( - self, request: operations_pb2.DeleteOperationRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for delete_operation - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_delete_operation( - self, response: None - ) -> None: - """Post-rpc interceptor for delete_operation - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_get_operation( - self, request: operations_pb2.GetOperationRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[operations_pb2.GetOperationRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for get_operation - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_get_operation( - self, response: operations_pb2.Operation - ) -> operations_pb2.Operation: - """Post-rpc interceptor for get_operation - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - def pre_list_operations( - self, request: operations_pb2.ListOperationsRequest, metadata: Sequence[Tuple[str, str]] - ) -> Tuple[operations_pb2.ListOperationsRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for list_operations - - Override in a subclass to manipulate the request or metadata - before they are sent to the DatabaseAdmin server. - """ - return request, metadata - - def post_list_operations( - self, response: operations_pb2.ListOperationsResponse - ) -> operations_pb2.ListOperationsResponse: - """Post-rpc interceptor for list_operations - - Override in a subclass to manipulate the response - after it is returned by the DatabaseAdmin server but before - it is returned to user code. - """ - return response - - -@dataclasses.dataclass -class DatabaseAdminRestStub: - _session: AuthorizedSession - _host: str - _interceptor: DatabaseAdminRestInterceptor - - -class DatabaseAdminRestTransport(DatabaseAdminTransport): - """REST backend transport for DatabaseAdmin. - - Cloud Spanner Database Admin API - - The Cloud Spanner Database Admin API can be used to: - - - create, drop, and list databases - - update the schema of pre-existing databases - - create, delete and list backups for a database - - restore a database from an existing backup - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends JSON representations of protocol buffers over HTTP/1.1 - - """ - - def __init__(self, *, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - client_cert_source_for_mtls: Optional[Callable[[ - ], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - url_scheme: str = 'https', - interceptor: Optional[DatabaseAdminRestInterceptor] = None, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client - certificate to configure mutual TLS HTTP channel. It is ignored - if ``channel`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you are developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - url_scheme: the protocol scheme for the API endpoint. Normally - "https", but for testing or local servers, - "http" can be specified. - """ - # Run the base constructor - # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. - # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the - # credentials object - maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) - if maybe_url_match is None: - raise ValueError(f"Unexpected hostname structure: {host}") # pragma: NO COVER - - url_match_items = maybe_url_match.groupdict() - - host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host - - super().__init__( - host=host, - credentials=credentials, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience - ) - self._session = AuthorizedSession( - self._credentials, default_host=self.DEFAULT_HOST) - self._operations_client: Optional[operations_v1.AbstractOperationsClient] = None - if client_cert_source_for_mtls: - self._session.configure_mtls_channel(client_cert_source_for_mtls) - self._interceptor = interceptor or DatabaseAdminRestInterceptor() - self._prep_wrapped_messages(client_info) - - @property - def operations_client(self) -> operations_v1.AbstractOperationsClient: - """Create the client designed to process long-running operations. - - This property caches on the instance; repeated calls return the same - client. - """ - # Only create a new client if we do not already have one. - if self._operations_client is None: - http_options: Dict[str, List[Dict[str, str]]] = { - 'google.longrunning.Operations.CancelOperation': [ - { - 'method': 'post', - 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}:cancel', - }, - { - 'method': 'post', - 'uri': '/v1/{name=projects/*/instances/*/operations/*}:cancel', - }, - { - 'method': 'post', - 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations/*}:cancel', - }, - { - 'method': 'post', - 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations/*}:cancel', - }, - ], - 'google.longrunning.Operations.DeleteOperation': [ - { - 'method': 'delete', - 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}', - }, - { - 'method': 'delete', - 'uri': '/v1/{name=projects/*/instances/*/operations/*}', - }, - { - 'method': 'delete', - 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations/*}', - }, - { - 'method': 'delete', - 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations/*}', - }, - ], - 'google.longrunning.Operations.GetOperation': [ - { - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}', - }, - { - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/operations/*}', - }, - { - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations/*}', - }, - { - 'method': 'get', - 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations/*}', - }, - ], - 'google.longrunning.Operations.ListOperations': [ - { - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations}', - }, - { - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/operations}', - }, - { - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations}', - }, - { - 'method': 'get', - 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations}', - }, - ], - } - - rest_transport = operations_v1.OperationsRestTransport( - host=self._host, - # use the credentials which are saved - credentials=self._credentials, - scopes=self._scopes, - http_options=http_options, - path_prefix="v1") - - self._operations_client = operations_v1.AbstractOperationsClient(transport=rest_transport) - - # Return the client from cache. - return self._operations_client - - class _CopyBackup(DatabaseAdminRestStub): - def __hash__(self): - return hash("CopyBackup") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: backup.CopyBackupRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> operations_pb2.Operation: - r"""Call the copy backup method over HTTP. - - Args: - request (~.backup.CopyBackupRequest): - The request object. The request for - [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.operations_pb2.Operation: - This resource represents a - long-running operation that is the - result of a network API call. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{parent=projects/*/instances/*}/backups:copy', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_copy_backup(request, metadata) - pb_request = backup.CopyBackupRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = operations_pb2.Operation() - json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_copy_backup(resp) - return resp - - class _CreateBackup(DatabaseAdminRestStub): - def __hash__(self): - return hash("CreateBackup") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - "backupId" : "", } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: gsad_backup.CreateBackupRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> operations_pb2.Operation: - r"""Call the create backup method over HTTP. - - Args: - request (~.gsad_backup.CreateBackupRequest): - The request object. The request for - [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.operations_pb2.Operation: - This resource represents a - long-running operation that is the - result of a network API call. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{parent=projects/*/instances/*}/backups', - 'body': 'backup', - }, - ] - request, metadata = self._interceptor.pre_create_backup(request, metadata) - pb_request = gsad_backup.CreateBackupRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = operations_pb2.Operation() - json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_create_backup(resp) - return resp - - class _CreateDatabase(DatabaseAdminRestStub): - def __hash__(self): - return hash("CreateDatabase") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_database_admin.CreateDatabaseRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> operations_pb2.Operation: - r"""Call the create database method over HTTP. - - Args: - request (~.spanner_database_admin.CreateDatabaseRequest): - The request object. The request for - [CreateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.operations_pb2.Operation: - This resource represents a - long-running operation that is the - result of a network API call. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{parent=projects/*/instances/*}/databases', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_create_database(request, metadata) - pb_request = spanner_database_admin.CreateDatabaseRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = operations_pb2.Operation() - json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_create_database(resp) - return resp - - class _DeleteBackup(DatabaseAdminRestStub): - def __hash__(self): - return hash("DeleteBackup") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: backup.DeleteBackupRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ): - r"""Call the delete backup method over HTTP. - - Args: - request (~.backup.DeleteBackupRequest): - The request object. The request for - [DeleteBackup][google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'delete', - 'uri': '/v1/{name=projects/*/instances/*/backups/*}', - }, - ] - request, metadata = self._interceptor.pre_delete_backup(request, metadata) - pb_request = backup.DeleteBackupRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - class _DropDatabase(DatabaseAdminRestStub): - def __hash__(self): - return hash("DropDatabase") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_database_admin.DropDatabaseRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ): - r"""Call the drop database method over HTTP. - - Args: - request (~.spanner_database_admin.DropDatabaseRequest): - The request object. The request for - [DropDatabase][google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'delete', - 'uri': '/v1/{database=projects/*/instances/*/databases/*}', - }, - ] - request, metadata = self._interceptor.pre_drop_database(request, metadata) - pb_request = spanner_database_admin.DropDatabaseRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - class _GetBackup(DatabaseAdminRestStub): - def __hash__(self): - return hash("GetBackup") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: backup.GetBackupRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> backup.Backup: - r"""Call the get backup method over HTTP. - - Args: - request (~.backup.GetBackupRequest): - The request object. The request for - [GetBackup][google.spanner.admin.database.v1.DatabaseAdmin.GetBackup]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.backup.Backup: - A backup of a Cloud Spanner database. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/backups/*}', - }, - ] - request, metadata = self._interceptor.pre_get_backup(request, metadata) - pb_request = backup.GetBackupRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = backup.Backup() - pb_resp = backup.Backup.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_backup(resp) - return resp - - class _GetDatabase(DatabaseAdminRestStub): - def __hash__(self): - return hash("GetDatabase") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_database_admin.GetDatabaseRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner_database_admin.Database: - r"""Call the get database method over HTTP. - - Args: - request (~.spanner_database_admin.GetDatabaseRequest): - The request object. The request for - [GetDatabase][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner_database_admin.Database: - A Cloud Spanner database. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/databases/*}', - }, - ] - request, metadata = self._interceptor.pre_get_database(request, metadata) - pb_request = spanner_database_admin.GetDatabaseRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner_database_admin.Database() - pb_resp = spanner_database_admin.Database.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_database(resp) - return resp - - class _GetDatabaseDdl(DatabaseAdminRestStub): - def __hash__(self): - return hash("GetDatabaseDdl") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_database_admin.GetDatabaseDdlRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner_database_admin.GetDatabaseDdlResponse: - r"""Call the get database ddl method over HTTP. - - Args: - request (~.spanner_database_admin.GetDatabaseDdlRequest): - The request object. The request for - [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner_database_admin.GetDatabaseDdlResponse: - The response for - [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{database=projects/*/instances/*/databases/*}/ddl', - }, - ] - request, metadata = self._interceptor.pre_get_database_ddl(request, metadata) - pb_request = spanner_database_admin.GetDatabaseDdlRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner_database_admin.GetDatabaseDdlResponse() - pb_resp = spanner_database_admin.GetDatabaseDdlResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_database_ddl(resp) - return resp - - class _GetIamPolicy(DatabaseAdminRestStub): - def __hash__(self): - return hash("GetIamPolicy") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: iam_policy_pb2.GetIamPolicyRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> policy_pb2.Policy: - r"""Call the get iam policy method over HTTP. - - Args: - request (~.iam_policy_pb2.GetIamPolicyRequest): - The request object. Request message for ``GetIamPolicy`` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.policy_pb2.Policy: - An Identity and Access Management (IAM) policy, which - specifies access controls for Google Cloud resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members``, or - principals, to a single ``role``. Principals can be user - accounts, service accounts, Google groups, and domains - (such as G Suite). A ``role`` is a named list of - permissions; each ``role`` can be an IAM predefined role - or a user-created custom role. - - For some types of Google Cloud resources, a ``binding`` - can also specify a ``condition``, which is a logical - expression that allows access to a resource only if the - expression evaluates to ``true``. A condition can add - constraints based on attributes of the request, the - resource, or both. To learn which resources support - conditions in their IAM policies, see the `IAM - documentation `__. - - **JSON example:** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": [ - "user:eve@example.com" - ], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ], - "etag": "BwWWja0YfJA=", - "version": 3 - } - - **YAML example:** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - etag: BwWWja0YfJA= - version: 3 - - For a description of IAM and its features, see the `IAM - documentation `__. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{resource=projects/*/instances/*/databases/*}:getIamPolicy', - 'body': '*', - }, -{ - 'method': 'post', - 'uri': '/v1/{resource=projects/*/instances/*/backups/*}:getIamPolicy', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_get_iam_policy(request, metadata) - pb_request = request - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = policy_pb2.Policy() - pb_resp = resp - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_iam_policy(resp) - return resp - - class _ListBackupOperations(DatabaseAdminRestStub): - def __hash__(self): - return hash("ListBackupOperations") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: backup.ListBackupOperationsRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> backup.ListBackupOperationsResponse: - r"""Call the list backup operations method over HTTP. - - Args: - request (~.backup.ListBackupOperationsRequest): - The request object. The request for - [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.backup.ListBackupOperationsResponse: - The response for - [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{parent=projects/*/instances/*}/backupOperations', - }, - ] - request, metadata = self._interceptor.pre_list_backup_operations(request, metadata) - pb_request = backup.ListBackupOperationsRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = backup.ListBackupOperationsResponse() - pb_resp = backup.ListBackupOperationsResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_backup_operations(resp) - return resp - - class _ListBackups(DatabaseAdminRestStub): - def __hash__(self): - return hash("ListBackups") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: backup.ListBackupsRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> backup.ListBackupsResponse: - r"""Call the list backups method over HTTP. - - Args: - request (~.backup.ListBackupsRequest): - The request object. The request for - [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.backup.ListBackupsResponse: - The response for - [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{parent=projects/*/instances/*}/backups', - }, - ] - request, metadata = self._interceptor.pre_list_backups(request, metadata) - pb_request = backup.ListBackupsRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = backup.ListBackupsResponse() - pb_resp = backup.ListBackupsResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_backups(resp) - return resp - - class _ListDatabaseOperations(DatabaseAdminRestStub): - def __hash__(self): - return hash("ListDatabaseOperations") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_database_admin.ListDatabaseOperationsRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner_database_admin.ListDatabaseOperationsResponse: - r"""Call the list database operations method over HTTP. - - Args: - request (~.spanner_database_admin.ListDatabaseOperationsRequest): - The request object. The request for - [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner_database_admin.ListDatabaseOperationsResponse: - The response for - [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{parent=projects/*/instances/*}/databaseOperations', - }, - ] - request, metadata = self._interceptor.pre_list_database_operations(request, metadata) - pb_request = spanner_database_admin.ListDatabaseOperationsRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner_database_admin.ListDatabaseOperationsResponse() - pb_resp = spanner_database_admin.ListDatabaseOperationsResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_database_operations(resp) - return resp - - class _ListDatabaseRoles(DatabaseAdminRestStub): - def __hash__(self): - return hash("ListDatabaseRoles") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_database_admin.ListDatabaseRolesRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner_database_admin.ListDatabaseRolesResponse: - r"""Call the list database roles method over HTTP. - - Args: - request (~.spanner_database_admin.ListDatabaseRolesRequest): - The request object. The request for - [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner_database_admin.ListDatabaseRolesResponse: - The response for - [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{parent=projects/*/instances/*/databases/*}/databaseRoles', - }, - ] - request, metadata = self._interceptor.pre_list_database_roles(request, metadata) - pb_request = spanner_database_admin.ListDatabaseRolesRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner_database_admin.ListDatabaseRolesResponse() - pb_resp = spanner_database_admin.ListDatabaseRolesResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_database_roles(resp) - return resp - - class _ListDatabases(DatabaseAdminRestStub): - def __hash__(self): - return hash("ListDatabases") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_database_admin.ListDatabasesRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner_database_admin.ListDatabasesResponse: - r"""Call the list databases method over HTTP. - - Args: - request (~.spanner_database_admin.ListDatabasesRequest): - The request object. The request for - [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner_database_admin.ListDatabasesResponse: - The response for - [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{parent=projects/*/instances/*}/databases', - }, - ] - request, metadata = self._interceptor.pre_list_databases(request, metadata) - pb_request = spanner_database_admin.ListDatabasesRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner_database_admin.ListDatabasesResponse() - pb_resp = spanner_database_admin.ListDatabasesResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_databases(resp) - return resp - - class _RestoreDatabase(DatabaseAdminRestStub): - def __hash__(self): - return hash("RestoreDatabase") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_database_admin.RestoreDatabaseRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> operations_pb2.Operation: - r"""Call the restore database method over HTTP. - - Args: - request (~.spanner_database_admin.RestoreDatabaseRequest): - The request object. The request for - [RestoreDatabase][google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.operations_pb2.Operation: - This resource represents a - long-running operation that is the - result of a network API call. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{parent=projects/*/instances/*}/databases:restore', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_restore_database(request, metadata) - pb_request = spanner_database_admin.RestoreDatabaseRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = operations_pb2.Operation() - json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_restore_database(resp) - return resp - - class _SetIamPolicy(DatabaseAdminRestStub): - def __hash__(self): - return hash("SetIamPolicy") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: iam_policy_pb2.SetIamPolicyRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> policy_pb2.Policy: - r"""Call the set iam policy method over HTTP. - - Args: - request (~.iam_policy_pb2.SetIamPolicyRequest): - The request object. Request message for ``SetIamPolicy`` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.policy_pb2.Policy: - An Identity and Access Management (IAM) policy, which - specifies access controls for Google Cloud resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members``, or - principals, to a single ``role``. Principals can be user - accounts, service accounts, Google groups, and domains - (such as G Suite). A ``role`` is a named list of - permissions; each ``role`` can be an IAM predefined role - or a user-created custom role. - - For some types of Google Cloud resources, a ``binding`` - can also specify a ``condition``, which is a logical - expression that allows access to a resource only if the - expression evaluates to ``true``. A condition can add - constraints based on attributes of the request, the - resource, or both. To learn which resources support - conditions in their IAM policies, see the `IAM - documentation `__. - - **JSON example:** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": [ - "user:eve@example.com" - ], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ], - "etag": "BwWWja0YfJA=", - "version": 3 - } - - **YAML example:** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - etag: BwWWja0YfJA= - version: 3 - - For a description of IAM and its features, see the `IAM - documentation `__. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{resource=projects/*/instances/*/databases/*}:setIamPolicy', - 'body': '*', - }, -{ - 'method': 'post', - 'uri': '/v1/{resource=projects/*/instances/*/backups/*}:setIamPolicy', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_set_iam_policy(request, metadata) - pb_request = request - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = policy_pb2.Policy() - pb_resp = resp - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_set_iam_policy(resp) - return resp - - class _TestIamPermissions(DatabaseAdminRestStub): - def __hash__(self): - return hash("TestIamPermissions") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: iam_policy_pb2.TestIamPermissionsRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> iam_policy_pb2.TestIamPermissionsResponse: - r"""Call the test iam permissions method over HTTP. - - Args: - request (~.iam_policy_pb2.TestIamPermissionsRequest): - The request object. Request message for ``TestIamPermissions`` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.iam_policy_pb2.TestIamPermissionsResponse: - Response message for ``TestIamPermissions`` method. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{resource=projects/*/instances/*/databases/*}:testIamPermissions', - 'body': '*', - }, -{ - 'method': 'post', - 'uri': '/v1/{resource=projects/*/instances/*/backups/*}:testIamPermissions', - 'body': '*', - }, -{ - 'method': 'post', - 'uri': '/v1/{resource=projects/*/instances/*/databases/*/databaseRoles/*}:testIamPermissions', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_test_iam_permissions(request, metadata) - pb_request = request - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = iam_policy_pb2.TestIamPermissionsResponse() - pb_resp = resp - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_test_iam_permissions(resp) - return resp - - class _UpdateBackup(DatabaseAdminRestStub): - def __hash__(self): - return hash("UpdateBackup") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - "updateMask" : {}, } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: gsad_backup.UpdateBackupRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> gsad_backup.Backup: - r"""Call the update backup method over HTTP. - - Args: - request (~.gsad_backup.UpdateBackupRequest): - The request object. The request for - [UpdateBackup][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.gsad_backup.Backup: - A backup of a Cloud Spanner database. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'patch', - 'uri': '/v1/{backup.name=projects/*/instances/*/backups/*}', - 'body': 'backup', - }, - ] - request, metadata = self._interceptor.pre_update_backup(request, metadata) - pb_request = gsad_backup.UpdateBackupRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = gsad_backup.Backup() - pb_resp = gsad_backup.Backup.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_update_backup(resp) - return resp - - class _UpdateDatabase(DatabaseAdminRestStub): - def __hash__(self): - return hash("UpdateDatabase") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - "updateMask" : {}, } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_database_admin.UpdateDatabaseRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> operations_pb2.Operation: - r"""Call the update database method over HTTP. - - Args: - request (~.spanner_database_admin.UpdateDatabaseRequest): - The request object. The request for - [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.operations_pb2.Operation: - This resource represents a - long-running operation that is the - result of a network API call. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'patch', - 'uri': '/v1/{database.name=projects/*/instances/*/databases/*}', - 'body': 'database', - }, - ] - request, metadata = self._interceptor.pre_update_database(request, metadata) - pb_request = spanner_database_admin.UpdateDatabaseRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = operations_pb2.Operation() - json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_update_database(resp) - return resp - - class _UpdateDatabaseDdl(DatabaseAdminRestStub): - def __hash__(self): - return hash("UpdateDatabaseDdl") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_database_admin.UpdateDatabaseDdlRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> operations_pb2.Operation: - r"""Call the update database ddl method over HTTP. - - Args: - request (~.spanner_database_admin.UpdateDatabaseDdlRequest): - The request object. Enqueues the given DDL statements to be applied, in - order but not necessarily all at once, to the database - schema at some point (or points) in the future. The - server checks that the statements are executable - (syntactically valid, name tables that exist, etc.) - before enqueueing them, but they may still fail upon - later execution (e.g., if a statement from another batch - of statements is applied first and it conflicts in some - way, or if there is some data-related problem like a - ``NULL`` value in a column to which ``NOT NULL`` would - be added). If a statement fails, all subsequent - statements in the batch are automatically cancelled. - - Each batch of statements is assigned a name which can be - used with the - [Operations][google.longrunning.Operations] API to - monitor progress. See the - [operation_id][google.spanner.admin.database.v1.UpdateDatabaseDdlRequest.operation_id] - field for more details. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.operations_pb2.Operation: - This resource represents a - long-running operation that is the - result of a network API call. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'patch', - 'uri': '/v1/{database=projects/*/instances/*/databases/*}/ddl', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_update_database_ddl(request, metadata) - pb_request = spanner_database_admin.UpdateDatabaseDdlRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = operations_pb2.Operation() - json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_update_database_ddl(resp) - return resp - - @property - def copy_backup(self) -> Callable[ - [backup.CopyBackupRequest], - operations_pb2.Operation]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._CopyBackup(self._session, self._host, self._interceptor) # type: ignore - - @property - def create_backup(self) -> Callable[ - [gsad_backup.CreateBackupRequest], - operations_pb2.Operation]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._CreateBackup(self._session, self._host, self._interceptor) # type: ignore - - @property - def create_database(self) -> Callable[ - [spanner_database_admin.CreateDatabaseRequest], - operations_pb2.Operation]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._CreateDatabase(self._session, self._host, self._interceptor) # type: ignore - - @property - def delete_backup(self) -> Callable[ - [backup.DeleteBackupRequest], - empty_pb2.Empty]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._DeleteBackup(self._session, self._host, self._interceptor) # type: ignore - - @property - def drop_database(self) -> Callable[ - [spanner_database_admin.DropDatabaseRequest], - empty_pb2.Empty]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._DropDatabase(self._session, self._host, self._interceptor) # type: ignore - - @property - def get_backup(self) -> Callable[ - [backup.GetBackupRequest], - backup.Backup]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._GetBackup(self._session, self._host, self._interceptor) # type: ignore - - @property - def get_database(self) -> Callable[ - [spanner_database_admin.GetDatabaseRequest], - spanner_database_admin.Database]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._GetDatabase(self._session, self._host, self._interceptor) # type: ignore - - @property - def get_database_ddl(self) -> Callable[ - [spanner_database_admin.GetDatabaseDdlRequest], - spanner_database_admin.GetDatabaseDdlResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._GetDatabaseDdl(self._session, self._host, self._interceptor) # type: ignore - - @property - def get_iam_policy(self) -> Callable[ - [iam_policy_pb2.GetIamPolicyRequest], - policy_pb2.Policy]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._GetIamPolicy(self._session, self._host, self._interceptor) # type: ignore - - @property - def list_backup_operations(self) -> Callable[ - [backup.ListBackupOperationsRequest], - backup.ListBackupOperationsResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._ListBackupOperations(self._session, self._host, self._interceptor) # type: ignore - - @property - def list_backups(self) -> Callable[ - [backup.ListBackupsRequest], - backup.ListBackupsResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._ListBackups(self._session, self._host, self._interceptor) # type: ignore - - @property - def list_database_operations(self) -> Callable[ - [spanner_database_admin.ListDatabaseOperationsRequest], - spanner_database_admin.ListDatabaseOperationsResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._ListDatabaseOperations(self._session, self._host, self._interceptor) # type: ignore - - @property - def list_database_roles(self) -> Callable[ - [spanner_database_admin.ListDatabaseRolesRequest], - spanner_database_admin.ListDatabaseRolesResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._ListDatabaseRoles(self._session, self._host, self._interceptor) # type: ignore - - @property - def list_databases(self) -> Callable[ - [spanner_database_admin.ListDatabasesRequest], - spanner_database_admin.ListDatabasesResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._ListDatabases(self._session, self._host, self._interceptor) # type: ignore - - @property - def restore_database(self) -> Callable[ - [spanner_database_admin.RestoreDatabaseRequest], - operations_pb2.Operation]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._RestoreDatabase(self._session, self._host, self._interceptor) # type: ignore - - @property - def set_iam_policy(self) -> Callable[ - [iam_policy_pb2.SetIamPolicyRequest], - policy_pb2.Policy]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._SetIamPolicy(self._session, self._host, self._interceptor) # type: ignore - - @property - def test_iam_permissions(self) -> Callable[ - [iam_policy_pb2.TestIamPermissionsRequest], - iam_policy_pb2.TestIamPermissionsResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._TestIamPermissions(self._session, self._host, self._interceptor) # type: ignore - - @property - def update_backup(self) -> Callable[ - [gsad_backup.UpdateBackupRequest], - gsad_backup.Backup]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._UpdateBackup(self._session, self._host, self._interceptor) # type: ignore - - @property - def update_database(self) -> Callable[ - [spanner_database_admin.UpdateDatabaseRequest], - operations_pb2.Operation]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._UpdateDatabase(self._session, self._host, self._interceptor) # type: ignore - - @property - def update_database_ddl(self) -> Callable[ - [spanner_database_admin.UpdateDatabaseDdlRequest], - operations_pb2.Operation]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._UpdateDatabaseDdl(self._session, self._host, self._interceptor) # type: ignore - - @property - def cancel_operation(self): - return self._CancelOperation(self._session, self._host, self._interceptor) # type: ignore - - class _CancelOperation(DatabaseAdminRestStub): - def __call__(self, - request: operations_pb2.CancelOperationRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> None: - - r"""Call the cancel operation method over HTTP. - - Args: - request (operations_pb2.CancelOperationRequest): - The request object for CancelOperation method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}:cancel', - }, -{ - 'method': 'post', - 'uri': '/v1/{name=projects/*/instances/*/operations/*}:cancel', - }, -{ - 'method': 'post', - 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations/*}:cancel', - }, -{ - 'method': 'post', - 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations/*}:cancel', - }, - ] - - request, metadata = self._interceptor.pre_cancel_operation(request, metadata) - request_kwargs = json_format.MessageToDict(request) - transcoded_request = path_template.transcode( - http_options, **request_kwargs) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json.dumps(transcoded_request['query_params'])) - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - return self._interceptor.post_cancel_operation(None) - - @property - def delete_operation(self): - return self._DeleteOperation(self._session, self._host, self._interceptor) # type: ignore - - class _DeleteOperation(DatabaseAdminRestStub): - def __call__(self, - request: operations_pb2.DeleteOperationRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> None: - - r"""Call the delete operation method over HTTP. - - Args: - request (operations_pb2.DeleteOperationRequest): - The request object for DeleteOperation method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'delete', - 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}', - }, -{ - 'method': 'delete', - 'uri': '/v1/{name=projects/*/instances/*/operations/*}', - }, -{ - 'method': 'delete', - 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations/*}', - }, -{ - 'method': 'delete', - 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations/*}', - }, - ] - - request, metadata = self._interceptor.pre_delete_operation(request, metadata) - request_kwargs = json_format.MessageToDict(request) - transcoded_request = path_template.transcode( - http_options, **request_kwargs) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json.dumps(transcoded_request['query_params'])) - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - return self._interceptor.post_delete_operation(None) - - @property - def get_operation(self): - return self._GetOperation(self._session, self._host, self._interceptor) # type: ignore - - class _GetOperation(DatabaseAdminRestStub): - def __call__(self, - request: operations_pb2.GetOperationRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> operations_pb2.Operation: - - r"""Call the get operation method over HTTP. - - Args: - request (operations_pb2.GetOperationRequest): - The request object for GetOperation method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - operations_pb2.Operation: Response from GetOperation method. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}', - }, -{ - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/operations/*}', - }, -{ - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations/*}', - }, -{ - 'method': 'get', - 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations/*}', - }, - ] - - request, metadata = self._interceptor.pre_get_operation(request, metadata) - request_kwargs = json_format.MessageToDict(request) - transcoded_request = path_template.transcode( - http_options, **request_kwargs) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json.dumps(transcoded_request['query_params'])) - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - resp = operations_pb2.Operation() - resp = json_format.Parse(response.content.decode("utf-8"), resp) - resp = self._interceptor.post_get_operation(resp) - return resp - - @property - def list_operations(self): - return self._ListOperations(self._session, self._host, self._interceptor) # type: ignore - - class _ListOperations(DatabaseAdminRestStub): - def __call__(self, - request: operations_pb2.ListOperationsRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> operations_pb2.ListOperationsResponse: - - r"""Call the list operations method over HTTP. - - Args: - request (operations_pb2.ListOperationsRequest): - The request object for ListOperations method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - operations_pb2.ListOperationsResponse: Response from ListOperations method. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations}', - }, -{ - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/operations}', - }, -{ - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/backups/*/operations}', - }, -{ - 'method': 'get', - 'uri': '/v1/{name=projects/*/instanceConfigs/*/operations}', - }, - ] - - request, metadata = self._interceptor.pre_list_operations(request, metadata) - request_kwargs = json_format.MessageToDict(request) - transcoded_request = path_template.transcode( - http_options, **request_kwargs) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json.dumps(transcoded_request['query_params'])) - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - resp = operations_pb2.ListOperationsResponse() - resp = json_format.Parse(response.content.decode("utf-8"), resp) - resp = self._interceptor.post_list_operations(resp) - return resp - - @property - def kind(self) -> str: - return "rest" - - def close(self): - self._session.close() - - -__all__=( - 'DatabaseAdminRestTransport', -) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/__init__.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/__init__.py deleted file mode 100644 index c9fb52da51..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/__init__.py +++ /dev/null @@ -1,110 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .backup import ( - Backup, - BackupInfo, - CopyBackupEncryptionConfig, - CopyBackupMetadata, - CopyBackupRequest, - CreateBackupEncryptionConfig, - CreateBackupMetadata, - CreateBackupRequest, - DeleteBackupRequest, - GetBackupRequest, - ListBackupOperationsRequest, - ListBackupOperationsResponse, - ListBackupsRequest, - ListBackupsResponse, - UpdateBackupRequest, -) -from .common import ( - EncryptionConfig, - EncryptionInfo, - OperationProgress, - DatabaseDialect, -) -from .spanner_database_admin import ( - CreateDatabaseMetadata, - CreateDatabaseRequest, - Database, - DatabaseRole, - DropDatabaseRequest, - GetDatabaseDdlRequest, - GetDatabaseDdlResponse, - GetDatabaseRequest, - ListDatabaseOperationsRequest, - ListDatabaseOperationsResponse, - ListDatabaseRolesRequest, - ListDatabaseRolesResponse, - ListDatabasesRequest, - ListDatabasesResponse, - OptimizeRestoredDatabaseMetadata, - RestoreDatabaseEncryptionConfig, - RestoreDatabaseMetadata, - RestoreDatabaseRequest, - RestoreInfo, - UpdateDatabaseDdlMetadata, - UpdateDatabaseDdlRequest, - UpdateDatabaseMetadata, - UpdateDatabaseRequest, - RestoreSourceType, -) - -__all__ = ( - 'Backup', - 'BackupInfo', - 'CopyBackupEncryptionConfig', - 'CopyBackupMetadata', - 'CopyBackupRequest', - 'CreateBackupEncryptionConfig', - 'CreateBackupMetadata', - 'CreateBackupRequest', - 'DeleteBackupRequest', - 'GetBackupRequest', - 'ListBackupOperationsRequest', - 'ListBackupOperationsResponse', - 'ListBackupsRequest', - 'ListBackupsResponse', - 'UpdateBackupRequest', - 'EncryptionConfig', - 'EncryptionInfo', - 'OperationProgress', - 'DatabaseDialect', - 'CreateDatabaseMetadata', - 'CreateDatabaseRequest', - 'Database', - 'DatabaseRole', - 'DropDatabaseRequest', - 'GetDatabaseDdlRequest', - 'GetDatabaseDdlResponse', - 'GetDatabaseRequest', - 'ListDatabaseOperationsRequest', - 'ListDatabaseOperationsResponse', - 'ListDatabaseRolesRequest', - 'ListDatabaseRolesResponse', - 'ListDatabasesRequest', - 'ListDatabasesResponse', - 'OptimizeRestoredDatabaseMetadata', - 'RestoreDatabaseEncryptionConfig', - 'RestoreDatabaseMetadata', - 'RestoreDatabaseRequest', - 'RestoreInfo', - 'UpdateDatabaseDdlMetadata', - 'UpdateDatabaseDdlRequest', - 'UpdateDatabaseMetadata', - 'UpdateDatabaseRequest', - 'RestoreSourceType', -) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/backup.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/backup.py deleted file mode 100644 index 667938e242..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/backup.py +++ /dev/null @@ -1,906 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.cloud.spanner_admin_database_v1.types import common -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.spanner.admin.database.v1', - manifest={ - 'Backup', - 'CreateBackupRequest', - 'CreateBackupMetadata', - 'CopyBackupRequest', - 'CopyBackupMetadata', - 'UpdateBackupRequest', - 'GetBackupRequest', - 'DeleteBackupRequest', - 'ListBackupsRequest', - 'ListBackupsResponse', - 'ListBackupOperationsRequest', - 'ListBackupOperationsResponse', - 'BackupInfo', - 'CreateBackupEncryptionConfig', - 'CopyBackupEncryptionConfig', - }, -) - - -class Backup(proto.Message): - r"""A backup of a Cloud Spanner database. - - Attributes: - database (str): - Required for the - [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup] - operation. Name of the database from which this backup was - created. This needs to be in the same instance as the - backup. Values are of the form - ``projects//instances//databases/``. - version_time (google.protobuf.timestamp_pb2.Timestamp): - The backup will contain an externally consistent copy of the - database at the timestamp specified by ``version_time``. If - ``version_time`` is not specified, the system will set - ``version_time`` to the ``create_time`` of the backup. - expire_time (google.protobuf.timestamp_pb2.Timestamp): - Required for the - [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup] - operation. The expiration time of the backup, with - microseconds granularity that must be at least 6 hours and - at most 366 days from the time the CreateBackup request is - processed. Once the ``expire_time`` has passed, the backup - is eligible to be automatically deleted by Cloud Spanner to - free the resources used by the backup. - name (str): - Output only for the - [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup] - operation. Required for the - [UpdateBackup][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup] - operation. - - A globally unique identifier for the backup which cannot be - changed. Values are of the form - ``projects//instances//backups/[a-z][a-z0-9_\-]*[a-z0-9]`` - The final segment of the name must be between 2 and 60 - characters in length. - - The backup is stored in the location(s) specified in the - instance configuration of the instance containing the - backup, identified by the prefix of the backup name of the - form ``projects//instances/``. - create_time (google.protobuf.timestamp_pb2.Timestamp): - Output only. The time the - [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup] - request is received. If the request does not specify - ``version_time``, the ``version_time`` of the backup will be - equivalent to the ``create_time``. - size_bytes (int): - Output only. Size of the backup in bytes. - state (google.cloud.spanner_admin_database_v1.types.Backup.State): - Output only. The current state of the backup. - referencing_databases (MutableSequence[str]): - Output only. The names of the restored databases that - reference the backup. The database names are of the form - ``projects//instances//databases/``. - Referencing databases may exist in different instances. The - existence of any referencing database prevents the backup - from being deleted. When a restored database from the backup - enters the ``READY`` state, the reference to the backup is - removed. - encryption_info (google.cloud.spanner_admin_database_v1.types.EncryptionInfo): - Output only. The encryption information for - the backup. - database_dialect (google.cloud.spanner_admin_database_v1.types.DatabaseDialect): - Output only. The database dialect information - for the backup. - referencing_backups (MutableSequence[str]): - Output only. The names of the destination backups being - created by copying this source backup. The backup names are - of the form - ``projects//instances//backups/``. - Referencing backups may exist in different instances. The - existence of any referencing backup prevents the backup from - being deleted. When the copy operation is done (either - successfully completed or cancelled or the destination - backup is deleted), the reference to the backup is removed. - max_expire_time (google.protobuf.timestamp_pb2.Timestamp): - Output only. The max allowed expiration time of the backup, - with microseconds granularity. A backup's expiration time - can be configured in multiple APIs: CreateBackup, - UpdateBackup, CopyBackup. When updating or copying an - existing backup, the expiration time specified must be less - than ``Backup.max_expire_time``. - """ - class State(proto.Enum): - r"""Indicates the current state of the backup. - - Values: - STATE_UNSPECIFIED (0): - Not specified. - CREATING (1): - The pending backup is still being created. Operations on the - backup may fail with ``FAILED_PRECONDITION`` in this state. - READY (2): - The backup is complete and ready for use. - """ - STATE_UNSPECIFIED = 0 - CREATING = 1 - READY = 2 - - database: str = proto.Field( - proto.STRING, - number=2, - ) - version_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=9, - message=timestamp_pb2.Timestamp, - ) - expire_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - name: str = proto.Field( - proto.STRING, - number=1, - ) - create_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp_pb2.Timestamp, - ) - size_bytes: int = proto.Field( - proto.INT64, - number=5, - ) - state: State = proto.Field( - proto.ENUM, - number=6, - enum=State, - ) - referencing_databases: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=7, - ) - encryption_info: common.EncryptionInfo = proto.Field( - proto.MESSAGE, - number=8, - message=common.EncryptionInfo, - ) - database_dialect: common.DatabaseDialect = proto.Field( - proto.ENUM, - number=10, - enum=common.DatabaseDialect, - ) - referencing_backups: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=11, - ) - max_expire_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=12, - message=timestamp_pb2.Timestamp, - ) - - -class CreateBackupRequest(proto.Message): - r"""The request for - [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup]. - - Attributes: - parent (str): - Required. The name of the instance in which the backup will - be created. This must be the same instance that contains the - database the backup will be created from. The backup will be - stored in the location(s) specified in the instance - configuration of this instance. Values are of the form - ``projects//instances/``. - backup_id (str): - Required. The id of the backup to be created. The - ``backup_id`` appended to ``parent`` forms the full backup - name of the form - ``projects//instances//backups/``. - backup (google.cloud.spanner_admin_database_v1.types.Backup): - Required. The backup to create. - encryption_config (google.cloud.spanner_admin_database_v1.types.CreateBackupEncryptionConfig): - Optional. The encryption configuration used to encrypt the - backup. If this field is not specified, the backup will use - the same encryption configuration as the database by - default, namely - [encryption_type][google.spanner.admin.database.v1.CreateBackupEncryptionConfig.encryption_type] - = ``USE_DATABASE_ENCRYPTION``. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - backup_id: str = proto.Field( - proto.STRING, - number=2, - ) - backup: 'Backup' = proto.Field( - proto.MESSAGE, - number=3, - message='Backup', - ) - encryption_config: 'CreateBackupEncryptionConfig' = proto.Field( - proto.MESSAGE, - number=4, - message='CreateBackupEncryptionConfig', - ) - - -class CreateBackupMetadata(proto.Message): - r"""Metadata type for the operation returned by - [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup]. - - Attributes: - name (str): - The name of the backup being created. - database (str): - The name of the database the backup is - created from. - progress (google.cloud.spanner_admin_database_v1.types.OperationProgress): - The progress of the - [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup] - operation. - cancel_time (google.protobuf.timestamp_pb2.Timestamp): - The time at which cancellation of this operation was - received. - [Operations.CancelOperation][google.longrunning.Operations.CancelOperation] - starts asynchronous cancellation on a long-running - operation. The server makes a best effort to cancel the - operation, but success is not guaranteed. Clients can use - [Operations.GetOperation][google.longrunning.Operations.GetOperation] - or other methods to check whether the cancellation succeeded - or whether the operation completed despite cancellation. On - successful cancellation, the operation is not deleted; - instead, it becomes an operation with an - [Operation.error][google.longrunning.Operation.error] value - with a [google.rpc.Status.code][google.rpc.Status.code] of - 1, corresponding to ``Code.CANCELLED``. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - database: str = proto.Field( - proto.STRING, - number=2, - ) - progress: common.OperationProgress = proto.Field( - proto.MESSAGE, - number=3, - message=common.OperationProgress, - ) - cancel_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp_pb2.Timestamp, - ) - - -class CopyBackupRequest(proto.Message): - r"""The request for - [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup]. - - Attributes: - parent (str): - Required. The name of the destination instance that will - contain the backup copy. Values are of the form: - ``projects//instances/``. - backup_id (str): - Required. The id of the backup copy. The ``backup_id`` - appended to ``parent`` forms the full backup_uri of the form - ``projects//instances//backups/``. - source_backup (str): - Required. The source backup to be copied. The source backup - needs to be in READY state for it to be copied. Once - CopyBackup is in progress, the source backup cannot be - deleted or cleaned up on expiration until CopyBackup is - finished. Values are of the form: - ``projects//instances//backups/``. - expire_time (google.protobuf.timestamp_pb2.Timestamp): - Required. The expiration time of the backup in microsecond - granularity. The expiration time must be at least 6 hours - and at most 366 days from the ``create_time`` of the source - backup. Once the ``expire_time`` has passed, the backup is - eligible to be automatically deleted by Cloud Spanner to - free the resources used by the backup. - encryption_config (google.cloud.spanner_admin_database_v1.types.CopyBackupEncryptionConfig): - Optional. The encryption configuration used to encrypt the - backup. If this field is not specified, the backup will use - the same encryption configuration as the source backup by - default, namely - [encryption_type][google.spanner.admin.database.v1.CopyBackupEncryptionConfig.encryption_type] - = ``USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION``. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - backup_id: str = proto.Field( - proto.STRING, - number=2, - ) - source_backup: str = proto.Field( - proto.STRING, - number=3, - ) - expire_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp_pb2.Timestamp, - ) - encryption_config: 'CopyBackupEncryptionConfig' = proto.Field( - proto.MESSAGE, - number=5, - message='CopyBackupEncryptionConfig', - ) - - -class CopyBackupMetadata(proto.Message): - r"""Metadata type for the google.longrunning.Operation returned by - [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup]. - - Attributes: - name (str): - The name of the backup being created through the copy - operation. Values are of the form - ``projects//instances//backups/``. - source_backup (str): - The name of the source backup that is being copied. Values - are of the form - ``projects//instances//backups/``. - progress (google.cloud.spanner_admin_database_v1.types.OperationProgress): - The progress of the - [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup] - operation. - cancel_time (google.protobuf.timestamp_pb2.Timestamp): - The time at which cancellation of CopyBackup operation was - received. - [Operations.CancelOperation][google.longrunning.Operations.CancelOperation] - starts asynchronous cancellation on a long-running - operation. The server makes a best effort to cancel the - operation, but success is not guaranteed. Clients can use - [Operations.GetOperation][google.longrunning.Operations.GetOperation] - or other methods to check whether the cancellation succeeded - or whether the operation completed despite cancellation. On - successful cancellation, the operation is not deleted; - instead, it becomes an operation with an - [Operation.error][google.longrunning.Operation.error] value - with a [google.rpc.Status.code][google.rpc.Status.code] of - 1, corresponding to ``Code.CANCELLED``. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - source_backup: str = proto.Field( - proto.STRING, - number=2, - ) - progress: common.OperationProgress = proto.Field( - proto.MESSAGE, - number=3, - message=common.OperationProgress, - ) - cancel_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp_pb2.Timestamp, - ) - - -class UpdateBackupRequest(proto.Message): - r"""The request for - [UpdateBackup][google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup]. - - Attributes: - backup (google.cloud.spanner_admin_database_v1.types.Backup): - Required. The backup to update. ``backup.name``, and the - fields to be updated as specified by ``update_mask`` are - required. Other fields are ignored. Update is only supported - for the following fields: - - - ``backup.expire_time``. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. A mask specifying which fields (e.g. - ``expire_time``) in the Backup resource should be updated. - This mask is relative to the Backup resource, not to the - request message. The field mask must always be specified; - this prevents any future fields from being erased - accidentally by clients that do not know about them. - """ - - backup: 'Backup' = proto.Field( - proto.MESSAGE, - number=1, - message='Backup', - ) - update_mask: field_mask_pb2.FieldMask = proto.Field( - proto.MESSAGE, - number=2, - message=field_mask_pb2.FieldMask, - ) - - -class GetBackupRequest(proto.Message): - r"""The request for - [GetBackup][google.spanner.admin.database.v1.DatabaseAdmin.GetBackup]. - - Attributes: - name (str): - Required. Name of the backup. Values are of the form - ``projects//instances//backups/``. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - - -class DeleteBackupRequest(proto.Message): - r"""The request for - [DeleteBackup][google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup]. - - Attributes: - name (str): - Required. Name of the backup to delete. Values are of the - form - ``projects//instances//backups/``. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - - -class ListBackupsRequest(proto.Message): - r"""The request for - [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. - - Attributes: - parent (str): - Required. The instance to list backups from. Values are of - the form ``projects//instances/``. - filter (str): - An expression that filters the list of returned backups. - - A filter expression consists of a field name, a comparison - operator, and a value for filtering. The value must be a - string, a number, or a boolean. The comparison operator must - be one of: ``<``, ``>``, ``<=``, ``>=``, ``!=``, ``=``, or - ``:``. Colon ``:`` is the contains operator. Filter rules - are not case sensitive. - - The following fields in the - [Backup][google.spanner.admin.database.v1.Backup] are - eligible for filtering: - - - ``name`` - - ``database`` - - ``state`` - - ``create_time`` (and values are of the format - YYYY-MM-DDTHH:MM:SSZ) - - ``expire_time`` (and values are of the format - YYYY-MM-DDTHH:MM:SSZ) - - ``version_time`` (and values are of the format - YYYY-MM-DDTHH:MM:SSZ) - - ``size_bytes`` - - You can combine multiple expressions by enclosing each - expression in parentheses. By default, expressions are - combined with AND logic, but you can specify AND, OR, and - NOT logic explicitly. - - Here are a few examples: - - - ``name:Howl`` - The backup's name contains the string - "howl". - - ``database:prod`` - The database's name contains the - string "prod". - - ``state:CREATING`` - The backup is pending creation. - - ``state:READY`` - The backup is fully created and ready - for use. - - ``(name:howl) AND (create_time < \"2018-03-28T14:50:00Z\")`` - - The backup name contains the string "howl" and - ``create_time`` of the backup is before - 2018-03-28T14:50:00Z. - - ``expire_time < \"2018-03-28T14:50:00Z\"`` - The backup - ``expire_time`` is before 2018-03-28T14:50:00Z. - - ``size_bytes > 10000000000`` - The backup's size is - greater than 10GB - page_size (int): - Number of backups to be returned in the - response. If 0 or less, defaults to the server's - maximum allowed page size. - page_token (str): - If non-empty, ``page_token`` should contain a - [next_page_token][google.spanner.admin.database.v1.ListBackupsResponse.next_page_token] - from a previous - [ListBackupsResponse][google.spanner.admin.database.v1.ListBackupsResponse] - to the same ``parent`` and with the same ``filter``. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - filter: str = proto.Field( - proto.STRING, - number=2, - ) - page_size: int = proto.Field( - proto.INT32, - number=3, - ) - page_token: str = proto.Field( - proto.STRING, - number=4, - ) - - -class ListBackupsResponse(proto.Message): - r"""The response for - [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups]. - - Attributes: - backups (MutableSequence[google.cloud.spanner_admin_database_v1.types.Backup]): - The list of matching backups. Backups returned are ordered - by ``create_time`` in descending order, starting from the - most recent ``create_time``. - next_page_token (str): - ``next_page_token`` can be sent in a subsequent - [ListBackups][google.spanner.admin.database.v1.DatabaseAdmin.ListBackups] - call to fetch more of the matching backups. - """ - - @property - def raw_page(self): - return self - - backups: MutableSequence['Backup'] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Backup', - ) - next_page_token: str = proto.Field( - proto.STRING, - number=2, - ) - - -class ListBackupOperationsRequest(proto.Message): - r"""The request for - [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. - - Attributes: - parent (str): - Required. The instance of the backup operations. Values are - of the form ``projects//instances/``. - filter (str): - An expression that filters the list of returned backup - operations. - - A filter expression consists of a field name, a comparison - operator, and a value for filtering. The value must be a - string, a number, or a boolean. The comparison operator must - be one of: ``<``, ``>``, ``<=``, ``>=``, ``!=``, ``=``, or - ``:``. Colon ``:`` is the contains operator. Filter rules - are not case sensitive. - - The following fields in the - [operation][google.longrunning.Operation] are eligible for - filtering: - - - ``name`` - The name of the long-running operation - - ``done`` - False if the operation is in progress, else - true. - - ``metadata.@type`` - the type of metadata. For example, - the type string for - [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata] - is - ``type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata``. - - ``metadata.`` - any field in metadata.value. - ``metadata.@type`` must be specified first if filtering - on metadata fields. - - ``error`` - Error associated with the long-running - operation. - - ``response.@type`` - the type of response. - - ``response.`` - any field in response.value. - - You can combine multiple expressions by enclosing each - expression in parentheses. By default, expressions are - combined with AND logic, but you can specify AND, OR, and - NOT logic explicitly. - - Here are a few examples: - - - ``done:true`` - The operation is complete. - - ``(metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata) AND`` - ``metadata.database:prod`` - Returns operations where: - - - The operation's metadata type is - [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata]. - - The database the backup was taken from has a name - containing the string "prod". - - - ``(metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata) AND`` - ``(metadata.name:howl) AND`` - ``(metadata.progress.start_time < \"2018-03-28T14:50:00Z\") AND`` - ``(error:*)`` - Returns operations where: - - - The operation's metadata type is - [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata]. - - The backup name contains the string "howl". - - The operation started before 2018-03-28T14:50:00Z. - - The operation resulted in an error. - - - ``(metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CopyBackupMetadata) AND`` - ``(metadata.source_backup:test) AND`` - ``(metadata.progress.start_time < \"2022-01-18T14:50:00Z\") AND`` - ``(error:*)`` - Returns operations where: - - - The operation's metadata type is - [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata]. - - The source backup of the copied backup name contains - the string "test". - - The operation started before 2022-01-18T14:50:00Z. - - The operation resulted in an error. - - - ``((metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata) AND`` - ``(metadata.database:test_db)) OR`` - ``((metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CopyBackupMetadata) AND`` - ``(metadata.source_backup:test_bkp)) AND`` - ``(error:*)`` - Returns operations where: - - - The operation's metadata matches either of criteria: - - - The operation's metadata type is - [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata] - AND the database the backup was taken from has name - containing string "test_db" - - The operation's metadata type is - [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata] - AND the backup the backup was copied from has name - containing string "test_bkp" - - - The operation resulted in an error. - page_size (int): - Number of operations to be returned in the - response. If 0 or less, defaults to the server's - maximum allowed page size. - page_token (str): - If non-empty, ``page_token`` should contain a - [next_page_token][google.spanner.admin.database.v1.ListBackupOperationsResponse.next_page_token] - from a previous - [ListBackupOperationsResponse][google.spanner.admin.database.v1.ListBackupOperationsResponse] - to the same ``parent`` and with the same ``filter``. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - filter: str = proto.Field( - proto.STRING, - number=2, - ) - page_size: int = proto.Field( - proto.INT32, - number=3, - ) - page_token: str = proto.Field( - proto.STRING, - number=4, - ) - - -class ListBackupOperationsResponse(proto.Message): - r"""The response for - [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations]. - - Attributes: - operations (MutableSequence[google.longrunning.operations_pb2.Operation]): - The list of matching backup [long-running - operations][google.longrunning.Operation]. Each operation's - name will be prefixed by the backup's name. The operation's - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - Operations returned include those that are pending or have - completed/failed/canceled within the last 7 days. Operations - returned are ordered by - ``operation.metadata.value.progress.start_time`` in - descending order starting from the most recently started - operation. - next_page_token (str): - ``next_page_token`` can be sent in a subsequent - [ListBackupOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations] - call to fetch more of the matching metadata. - """ - - @property - def raw_page(self): - return self - - operations: MutableSequence[operations_pb2.Operation] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message=operations_pb2.Operation, - ) - next_page_token: str = proto.Field( - proto.STRING, - number=2, - ) - - -class BackupInfo(proto.Message): - r"""Information about a backup. - - Attributes: - backup (str): - Name of the backup. - version_time (google.protobuf.timestamp_pb2.Timestamp): - The backup contains an externally consistent copy of - ``source_database`` at the timestamp specified by - ``version_time``. If the - [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup] - request did not specify ``version_time``, the - ``version_time`` of the backup is equivalent to the - ``create_time``. - create_time (google.protobuf.timestamp_pb2.Timestamp): - The time the - [CreateBackup][google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup] - request was received. - source_database (str): - Name of the database the backup was created - from. - """ - - backup: str = proto.Field( - proto.STRING, - number=1, - ) - version_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp_pb2.Timestamp, - ) - create_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=2, - message=timestamp_pb2.Timestamp, - ) - source_database: str = proto.Field( - proto.STRING, - number=3, - ) - - -class CreateBackupEncryptionConfig(proto.Message): - r"""Encryption configuration for the backup to create. - - Attributes: - encryption_type (google.cloud.spanner_admin_database_v1.types.CreateBackupEncryptionConfig.EncryptionType): - Required. The encryption type of the backup. - kms_key_name (str): - Optional. The Cloud KMS key that will be used to protect the - backup. This field should be set only when - [encryption_type][google.spanner.admin.database.v1.CreateBackupEncryptionConfig.encryption_type] - is ``CUSTOMER_MANAGED_ENCRYPTION``. Values are of the form - ``projects//locations//keyRings//cryptoKeys/``. - """ - class EncryptionType(proto.Enum): - r"""Encryption types for the backup. - - Values: - ENCRYPTION_TYPE_UNSPECIFIED (0): - Unspecified. Do not use. - USE_DATABASE_ENCRYPTION (1): - Use the same encryption configuration as the database. This - is the default option when - [encryption_config][google.spanner.admin.database.v1.CreateBackupEncryptionConfig] - is empty. For example, if the database is using - ``Customer_Managed_Encryption``, the backup will be using - the same Cloud KMS key as the database. - GOOGLE_DEFAULT_ENCRYPTION (2): - Use Google default encryption. - CUSTOMER_MANAGED_ENCRYPTION (3): - Use customer managed encryption. If specified, - ``kms_key_name`` must contain a valid Cloud KMS key. - """ - ENCRYPTION_TYPE_UNSPECIFIED = 0 - USE_DATABASE_ENCRYPTION = 1 - GOOGLE_DEFAULT_ENCRYPTION = 2 - CUSTOMER_MANAGED_ENCRYPTION = 3 - - encryption_type: EncryptionType = proto.Field( - proto.ENUM, - number=1, - enum=EncryptionType, - ) - kms_key_name: str = proto.Field( - proto.STRING, - number=2, - ) - - -class CopyBackupEncryptionConfig(proto.Message): - r"""Encryption configuration for the copied backup. - - Attributes: - encryption_type (google.cloud.spanner_admin_database_v1.types.CopyBackupEncryptionConfig.EncryptionType): - Required. The encryption type of the backup. - kms_key_name (str): - Optional. The Cloud KMS key that will be used to protect the - backup. This field should be set only when - [encryption_type][google.spanner.admin.database.v1.CopyBackupEncryptionConfig.encryption_type] - is ``CUSTOMER_MANAGED_ENCRYPTION``. Values are of the form - ``projects//locations//keyRings//cryptoKeys/``. - """ - class EncryptionType(proto.Enum): - r"""Encryption types for the backup. - - Values: - ENCRYPTION_TYPE_UNSPECIFIED (0): - Unspecified. Do not use. - USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION (1): - This is the default option for - [CopyBackup][google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup] - when - [encryption_config][google.spanner.admin.database.v1.CopyBackupEncryptionConfig] - is not specified. For example, if the source backup is using - ``Customer_Managed_Encryption``, the backup will be using - the same Cloud KMS key as the source backup. - GOOGLE_DEFAULT_ENCRYPTION (2): - Use Google default encryption. - CUSTOMER_MANAGED_ENCRYPTION (3): - Use customer managed encryption. If specified, - ``kms_key_name`` must contain a valid Cloud KMS key. - """ - ENCRYPTION_TYPE_UNSPECIFIED = 0 - USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION = 1 - GOOGLE_DEFAULT_ENCRYPTION = 2 - CUSTOMER_MANAGED_ENCRYPTION = 3 - - encryption_type: EncryptionType = proto.Field( - proto.ENUM, - number=1, - enum=EncryptionType, - ) - kms_key_name: str = proto.Field( - proto.STRING, - number=2, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/common.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/common.py deleted file mode 100644 index 6a676425b2..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/common.py +++ /dev/null @@ -1,155 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.spanner.admin.database.v1', - manifest={ - 'DatabaseDialect', - 'OperationProgress', - 'EncryptionConfig', - 'EncryptionInfo', - }, -) - - -class DatabaseDialect(proto.Enum): - r"""Indicates the dialect type of a database. - - Values: - DATABASE_DIALECT_UNSPECIFIED (0): - Default value. This value will create a database with the - GOOGLE_STANDARD_SQL dialect. - GOOGLE_STANDARD_SQL (1): - Google standard SQL. - POSTGRESQL (2): - PostgreSQL supported SQL. - """ - DATABASE_DIALECT_UNSPECIFIED = 0 - GOOGLE_STANDARD_SQL = 1 - POSTGRESQL = 2 - - -class OperationProgress(proto.Message): - r"""Encapsulates progress related information for a Cloud Spanner - long running operation. - - Attributes: - progress_percent (int): - Percent completion of the operation. - Values are between 0 and 100 inclusive. - start_time (google.protobuf.timestamp_pb2.Timestamp): - Time the request was received. - end_time (google.protobuf.timestamp_pb2.Timestamp): - If set, the time at which this operation - failed or was completed successfully. - """ - - progress_percent: int = proto.Field( - proto.INT32, - number=1, - ) - start_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=2, - message=timestamp_pb2.Timestamp, - ) - end_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - - -class EncryptionConfig(proto.Message): - r"""Encryption configuration for a Cloud Spanner database. - - Attributes: - kms_key_name (str): - The Cloud KMS key to be used for encrypting and decrypting - the database. Values are of the form - ``projects//locations//keyRings//cryptoKeys/``. - """ - - kms_key_name: str = proto.Field( - proto.STRING, - number=2, - ) - - -class EncryptionInfo(proto.Message): - r"""Encryption information for a Cloud Spanner database or - backup. - - Attributes: - encryption_type (google.cloud.spanner_admin_database_v1.types.EncryptionInfo.Type): - Output only. The type of encryption. - encryption_status (google.rpc.status_pb2.Status): - Output only. If present, the status of a - recent encrypt/decrypt call on underlying data - for this database or backup. Regardless of - status, data is always encrypted at rest. - kms_key_version (str): - Output only. A Cloud KMS key version that is - being used to protect the database or backup. - """ - class Type(proto.Enum): - r"""Possible encryption types. - - Values: - TYPE_UNSPECIFIED (0): - Encryption type was not specified, though - data at rest remains encrypted. - GOOGLE_DEFAULT_ENCRYPTION (1): - The data is encrypted at rest with a key that - is fully managed by Google. No key version or - status will be populated. This is the default - state. - CUSTOMER_MANAGED_ENCRYPTION (2): - The data is encrypted at rest with a key that is managed by - the customer. The active version of the key. - ``kms_key_version`` will be populated, and - ``encryption_status`` may be populated. - """ - TYPE_UNSPECIFIED = 0 - GOOGLE_DEFAULT_ENCRYPTION = 1 - CUSTOMER_MANAGED_ENCRYPTION = 2 - - encryption_type: Type = proto.Field( - proto.ENUM, - number=3, - enum=Type, - ) - encryption_status: status_pb2.Status = proto.Field( - proto.MESSAGE, - number=4, - message=status_pb2.Status, - ) - kms_key_version: str = proto.Field( - proto.STRING, - number=2, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py b/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py deleted file mode 100644 index 4a37be71af..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py +++ /dev/null @@ -1,1059 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup -from google.cloud.spanner_admin_database_v1.types import common -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.spanner.admin.database.v1', - manifest={ - 'RestoreSourceType', - 'RestoreInfo', - 'Database', - 'ListDatabasesRequest', - 'ListDatabasesResponse', - 'CreateDatabaseRequest', - 'CreateDatabaseMetadata', - 'GetDatabaseRequest', - 'UpdateDatabaseRequest', - 'UpdateDatabaseMetadata', - 'UpdateDatabaseDdlRequest', - 'UpdateDatabaseDdlMetadata', - 'DropDatabaseRequest', - 'GetDatabaseDdlRequest', - 'GetDatabaseDdlResponse', - 'ListDatabaseOperationsRequest', - 'ListDatabaseOperationsResponse', - 'RestoreDatabaseRequest', - 'RestoreDatabaseEncryptionConfig', - 'RestoreDatabaseMetadata', - 'OptimizeRestoredDatabaseMetadata', - 'DatabaseRole', - 'ListDatabaseRolesRequest', - 'ListDatabaseRolesResponse', - }, -) - - -class RestoreSourceType(proto.Enum): - r"""Indicates the type of the restore source. - - Values: - TYPE_UNSPECIFIED (0): - No restore associated. - BACKUP (1): - A backup was used as the source of the - restore. - """ - TYPE_UNSPECIFIED = 0 - BACKUP = 1 - - -class RestoreInfo(proto.Message): - r"""Information about the database restore. - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - source_type (google.cloud.spanner_admin_database_v1.types.RestoreSourceType): - The type of the restore source. - backup_info (google.cloud.spanner_admin_database_v1.types.BackupInfo): - Information about the backup used to restore - the database. The backup may no longer exist. - - This field is a member of `oneof`_ ``source_info``. - """ - - source_type: 'RestoreSourceType' = proto.Field( - proto.ENUM, - number=1, - enum='RestoreSourceType', - ) - backup_info: gsad_backup.BackupInfo = proto.Field( - proto.MESSAGE, - number=2, - oneof='source_info', - message=gsad_backup.BackupInfo, - ) - - -class Database(proto.Message): - r"""A Cloud Spanner database. - - Attributes: - name (str): - Required. The name of the database. Values are of the form - ``projects//instances//databases/``, - where ```` is as specified in the - ``CREATE DATABASE`` statement. This name can be passed to - other API methods to identify the database. - state (google.cloud.spanner_admin_database_v1.types.Database.State): - Output only. The current database state. - create_time (google.protobuf.timestamp_pb2.Timestamp): - Output only. If exists, the time at which the - database creation started. - restore_info (google.cloud.spanner_admin_database_v1.types.RestoreInfo): - Output only. Applicable only for restored - databases. Contains information about the - restore source. - encryption_config (google.cloud.spanner_admin_database_v1.types.EncryptionConfig): - Output only. For databases that are using - customer managed encryption, this field contains - the encryption configuration for the database. - For databases that are using Google default or - other types of encryption, this field is empty. - encryption_info (MutableSequence[google.cloud.spanner_admin_database_v1.types.EncryptionInfo]): - Output only. For databases that are using - customer managed encryption, this field contains - the encryption information for the database, - such as encryption state and the Cloud KMS key - versions that are in use. - For databases that are using Google default or - other types of encryption, this field is empty. - - This field is propagated lazily from the - backend. There might be a delay from when a key - version is being used and when it appears in - this field. - version_retention_period (str): - Output only. The period in which Cloud Spanner retains all - versions of data for the database. This is the same as the - value of version_retention_period database option set using - [UpdateDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl]. - Defaults to 1 hour, if not set. - earliest_version_time (google.protobuf.timestamp_pb2.Timestamp): - Output only. Earliest timestamp at which - older versions of the data can be read. This - value is continuously updated by Cloud Spanner - and becomes stale the moment it is queried. If - you are using this value to recover data, make - sure to account for the time from the moment - when the value is queried to the moment when you - initiate the recovery. - default_leader (str): - Output only. The read-write region which contains the - database's leader replicas. - - This is the same as the value of default_leader database - option set using DatabaseAdmin.CreateDatabase or - DatabaseAdmin.UpdateDatabaseDdl. If not explicitly set, this - is empty. - database_dialect (google.cloud.spanner_admin_database_v1.types.DatabaseDialect): - Output only. The dialect of the Cloud Spanner - Database. - enable_drop_protection (bool): - Whether drop protection is enabled for this - database. Defaults to false, if not set. - reconciling (bool): - Output only. If true, the database is being - updated. If false, there are no ongoing update - operations for the database. - """ - class State(proto.Enum): - r"""Indicates the current state of the database. - - Values: - STATE_UNSPECIFIED (0): - Not specified. - CREATING (1): - The database is still being created. Operations on the - database may fail with ``FAILED_PRECONDITION`` in this - state. - READY (2): - The database is fully created and ready for - use. - READY_OPTIMIZING (3): - The database is fully created and ready for use, but is - still being optimized for performance and cannot handle full - load. - - In this state, the database still references the backup it - was restore from, preventing the backup from being deleted. - When optimizations are complete, the full performance of the - database will be restored, and the database will transition - to ``READY`` state. - """ - STATE_UNSPECIFIED = 0 - CREATING = 1 - READY = 2 - READY_OPTIMIZING = 3 - - name: str = proto.Field( - proto.STRING, - number=1, - ) - state: State = proto.Field( - proto.ENUM, - number=2, - enum=State, - ) - create_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - restore_info: 'RestoreInfo' = proto.Field( - proto.MESSAGE, - number=4, - message='RestoreInfo', - ) - encryption_config: common.EncryptionConfig = proto.Field( - proto.MESSAGE, - number=5, - message=common.EncryptionConfig, - ) - encryption_info: MutableSequence[common.EncryptionInfo] = proto.RepeatedField( - proto.MESSAGE, - number=8, - message=common.EncryptionInfo, - ) - version_retention_period: str = proto.Field( - proto.STRING, - number=6, - ) - earliest_version_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=7, - message=timestamp_pb2.Timestamp, - ) - default_leader: str = proto.Field( - proto.STRING, - number=9, - ) - database_dialect: common.DatabaseDialect = proto.Field( - proto.ENUM, - number=10, - enum=common.DatabaseDialect, - ) - enable_drop_protection: bool = proto.Field( - proto.BOOL, - number=11, - ) - reconciling: bool = proto.Field( - proto.BOOL, - number=12, - ) - - -class ListDatabasesRequest(proto.Message): - r"""The request for - [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. - - Attributes: - parent (str): - Required. The instance whose databases should be listed. - Values are of the form - ``projects//instances/``. - page_size (int): - Number of databases to be returned in the - response. If 0 or less, defaults to the server's - maximum allowed page size. - page_token (str): - If non-empty, ``page_token`` should contain a - [next_page_token][google.spanner.admin.database.v1.ListDatabasesResponse.next_page_token] - from a previous - [ListDatabasesResponse][google.spanner.admin.database.v1.ListDatabasesResponse]. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - page_size: int = proto.Field( - proto.INT32, - number=3, - ) - page_token: str = proto.Field( - proto.STRING, - number=4, - ) - - -class ListDatabasesResponse(proto.Message): - r"""The response for - [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases]. - - Attributes: - databases (MutableSequence[google.cloud.spanner_admin_database_v1.types.Database]): - Databases that matched the request. - next_page_token (str): - ``next_page_token`` can be sent in a subsequent - [ListDatabases][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases] - call to fetch more of the matching databases. - """ - - @property - def raw_page(self): - return self - - databases: MutableSequence['Database'] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Database', - ) - next_page_token: str = proto.Field( - proto.STRING, - number=2, - ) - - -class CreateDatabaseRequest(proto.Message): - r"""The request for - [CreateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase]. - - Attributes: - parent (str): - Required. The name of the instance that will serve the new - database. Values are of the form - ``projects//instances/``. - create_statement (str): - Required. A ``CREATE DATABASE`` statement, which specifies - the ID of the new database. The database ID must conform to - the regular expression ``[a-z][a-z0-9_\-]*[a-z0-9]`` and be - between 2 and 30 characters in length. If the database ID is - a reserved word or if it contains a hyphen, the database ID - must be enclosed in backticks (:literal:`\``). - extra_statements (MutableSequence[str]): - Optional. A list of DDL statements to run - inside the newly created database. Statements - can create tables, indexes, etc. These - statements execute atomically with the creation - of the database: if there is an error in any - statement, the database is not created. - encryption_config (google.cloud.spanner_admin_database_v1.types.EncryptionConfig): - Optional. The encryption configuration for - the database. If this field is not specified, - Cloud Spanner will encrypt/decrypt all data at - rest using Google default encryption. - database_dialect (google.cloud.spanner_admin_database_v1.types.DatabaseDialect): - Optional. The dialect of the Cloud Spanner - Database. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - create_statement: str = proto.Field( - proto.STRING, - number=2, - ) - extra_statements: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=3, - ) - encryption_config: common.EncryptionConfig = proto.Field( - proto.MESSAGE, - number=4, - message=common.EncryptionConfig, - ) - database_dialect: common.DatabaseDialect = proto.Field( - proto.ENUM, - number=5, - enum=common.DatabaseDialect, - ) - - -class CreateDatabaseMetadata(proto.Message): - r"""Metadata type for the operation returned by - [CreateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase]. - - Attributes: - database (str): - The database being created. - """ - - database: str = proto.Field( - proto.STRING, - number=1, - ) - - -class GetDatabaseRequest(proto.Message): - r"""The request for - [GetDatabase][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase]. - - Attributes: - name (str): - Required. The name of the requested database. Values are of - the form - ``projects//instances//databases/``. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - - -class UpdateDatabaseRequest(proto.Message): - r"""The request for - [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. - - Attributes: - database (google.cloud.spanner_admin_database_v1.types.Database): - Required. The database to update. The ``name`` field of the - database is of the form - ``projects//instances//databases/``. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. The list of fields to update. Currently, only - ``enable_drop_protection`` field can be updated. - """ - - database: 'Database' = proto.Field( - proto.MESSAGE, - number=1, - message='Database', - ) - update_mask: field_mask_pb2.FieldMask = proto.Field( - proto.MESSAGE, - number=2, - message=field_mask_pb2.FieldMask, - ) - - -class UpdateDatabaseMetadata(proto.Message): - r"""Metadata type for the operation returned by - [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. - - Attributes: - request (google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest): - The request for - [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase]. - progress (google.cloud.spanner_admin_database_v1.types.OperationProgress): - The progress of the - [UpdateDatabase][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase] - operation. - cancel_time (google.protobuf.timestamp_pb2.Timestamp): - The time at which this operation was - cancelled. If set, this operation is in the - process of undoing itself (which is - best-effort). - """ - - request: 'UpdateDatabaseRequest' = proto.Field( - proto.MESSAGE, - number=1, - message='UpdateDatabaseRequest', - ) - progress: common.OperationProgress = proto.Field( - proto.MESSAGE, - number=2, - message=common.OperationProgress, - ) - cancel_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - - -class UpdateDatabaseDdlRequest(proto.Message): - r"""Enqueues the given DDL statements to be applied, in order but not - necessarily all at once, to the database schema at some point (or - points) in the future. The server checks that the statements are - executable (syntactically valid, name tables that exist, etc.) - before enqueueing them, but they may still fail upon later execution - (e.g., if a statement from another batch of statements is applied - first and it conflicts in some way, or if there is some data-related - problem like a ``NULL`` value in a column to which ``NOT NULL`` - would be added). If a statement fails, all subsequent statements in - the batch are automatically cancelled. - - Each batch of statements is assigned a name which can be used with - the [Operations][google.longrunning.Operations] API to monitor - progress. See the - [operation_id][google.spanner.admin.database.v1.UpdateDatabaseDdlRequest.operation_id] - field for more details. - - Attributes: - database (str): - Required. The database to update. - statements (MutableSequence[str]): - Required. DDL statements to be applied to the - database. - operation_id (str): - If empty, the new update request is assigned an - automatically-generated operation ID. Otherwise, - ``operation_id`` is used to construct the name of the - resulting [Operation][google.longrunning.Operation]. - - Specifying an explicit operation ID simplifies determining - whether the statements were executed in the event that the - [UpdateDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl] - call is replayed, or the return value is otherwise lost: the - [database][google.spanner.admin.database.v1.UpdateDatabaseDdlRequest.database] - and ``operation_id`` fields can be combined to form the - [name][google.longrunning.Operation.name] of the resulting - [longrunning.Operation][google.longrunning.Operation]: - ``/operations/``. - - ``operation_id`` should be unique within the database, and - must be a valid identifier: ``[a-z][a-z0-9_]*``. Note that - automatically-generated operation IDs always begin with an - underscore. If the named operation already exists, - [UpdateDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl] - returns ``ALREADY_EXISTS``. - """ - - database: str = proto.Field( - proto.STRING, - number=1, - ) - statements: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=2, - ) - operation_id: str = proto.Field( - proto.STRING, - number=3, - ) - - -class UpdateDatabaseDdlMetadata(proto.Message): - r"""Metadata type for the operation returned by - [UpdateDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl]. - - Attributes: - database (str): - The database being modified. - statements (MutableSequence[str]): - For an update this list contains all the - statements. For an individual statement, this - list contains only that statement. - commit_timestamps (MutableSequence[google.protobuf.timestamp_pb2.Timestamp]): - Reports the commit timestamps of all statements that have - succeeded so far, where ``commit_timestamps[i]`` is the - commit timestamp for the statement ``statements[i]``. - throttled (bool): - Output only. When true, indicates that the - operation is throttled e.g due to resource - constraints. When resources become available the - operation will resume and this field will be - false again. - progress (MutableSequence[google.cloud.spanner_admin_database_v1.types.OperationProgress]): - The progress of the - [UpdateDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl] - operations. Currently, only index creation statements will - have a continuously updating progress. For non-index - creation statements, ``progress[i]`` will have start time - and end time populated with commit timestamp of operation, - as well as a progress of 100% once the operation has - completed. ``progress[i]`` is the operation progress for - ``statements[i]``. - """ - - database: str = proto.Field( - proto.STRING, - number=1, - ) - statements: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=2, - ) - commit_timestamps: MutableSequence[timestamp_pb2.Timestamp] = proto.RepeatedField( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - throttled: bool = proto.Field( - proto.BOOL, - number=4, - ) - progress: MutableSequence[common.OperationProgress] = proto.RepeatedField( - proto.MESSAGE, - number=5, - message=common.OperationProgress, - ) - - -class DropDatabaseRequest(proto.Message): - r"""The request for - [DropDatabase][google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase]. - - Attributes: - database (str): - Required. The database to be dropped. - """ - - database: str = proto.Field( - proto.STRING, - number=1, - ) - - -class GetDatabaseDdlRequest(proto.Message): - r"""The request for - [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. - - Attributes: - database (str): - Required. The database whose schema we wish to get. Values - are of the form - ``projects//instances//databases/`` - """ - - database: str = proto.Field( - proto.STRING, - number=1, - ) - - -class GetDatabaseDdlResponse(proto.Message): - r"""The response for - [GetDatabaseDdl][google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl]. - - Attributes: - statements (MutableSequence[str]): - A list of formatted DDL statements defining - the schema of the database specified in the - request. - """ - - statements: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=1, - ) - - -class ListDatabaseOperationsRequest(proto.Message): - r"""The request for - [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. - - Attributes: - parent (str): - Required. The instance of the database operations. Values - are of the form ``projects//instances/``. - filter (str): - An expression that filters the list of returned operations. - - A filter expression consists of a field name, a comparison - operator, and a value for filtering. The value must be a - string, a number, or a boolean. The comparison operator must - be one of: ``<``, ``>``, ``<=``, ``>=``, ``!=``, ``=``, or - ``:``. Colon ``:`` is the contains operator. Filter rules - are not case sensitive. - - The following fields in the - [Operation][google.longrunning.Operation] are eligible for - filtering: - - - ``name`` - The name of the long-running operation - - ``done`` - False if the operation is in progress, else - true. - - ``metadata.@type`` - the type of metadata. For example, - the type string for - [RestoreDatabaseMetadata][google.spanner.admin.database.v1.RestoreDatabaseMetadata] - is - ``type.googleapis.com/google.spanner.admin.database.v1.RestoreDatabaseMetadata``. - - ``metadata.`` - any field in metadata.value. - ``metadata.@type`` must be specified first, if filtering - on metadata fields. - - ``error`` - Error associated with the long-running - operation. - - ``response.@type`` - the type of response. - - ``response.`` - any field in response.value. - - You can combine multiple expressions by enclosing each - expression in parentheses. By default, expressions are - combined with AND logic. However, you can specify AND, OR, - and NOT logic explicitly. - - Here are a few examples: - - - ``done:true`` - The operation is complete. - - ``(metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.RestoreDatabaseMetadata) AND`` - ``(metadata.source_type:BACKUP) AND`` - ``(metadata.backup_info.backup:backup_howl) AND`` - ``(metadata.name:restored_howl) AND`` - ``(metadata.progress.start_time < \"2018-03-28T14:50:00Z\") AND`` - ``(error:*)`` - Return operations where: - - - The operation's metadata type is - [RestoreDatabaseMetadata][google.spanner.admin.database.v1.RestoreDatabaseMetadata]. - - The database is restored from a backup. - - The backup name contains "backup_howl". - - The restored database's name contains "restored_howl". - - The operation started before 2018-03-28T14:50:00Z. - - The operation resulted in an error. - page_size (int): - Number of operations to be returned in the - response. If 0 or less, defaults to the server's - maximum allowed page size. - page_token (str): - If non-empty, ``page_token`` should contain a - [next_page_token][google.spanner.admin.database.v1.ListDatabaseOperationsResponse.next_page_token] - from a previous - [ListDatabaseOperationsResponse][google.spanner.admin.database.v1.ListDatabaseOperationsResponse] - to the same ``parent`` and with the same ``filter``. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - filter: str = proto.Field( - proto.STRING, - number=2, - ) - page_size: int = proto.Field( - proto.INT32, - number=3, - ) - page_token: str = proto.Field( - proto.STRING, - number=4, - ) - - -class ListDatabaseOperationsResponse(proto.Message): - r"""The response for - [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations]. - - Attributes: - operations (MutableSequence[google.longrunning.operations_pb2.Operation]): - The list of matching database [long-running - operations][google.longrunning.Operation]. Each operation's - name will be prefixed by the database's name. The - operation's - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - next_page_token (str): - ``next_page_token`` can be sent in a subsequent - [ListDatabaseOperations][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations] - call to fetch more of the matching metadata. - """ - - @property - def raw_page(self): - return self - - operations: MutableSequence[operations_pb2.Operation] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message=operations_pb2.Operation, - ) - next_page_token: str = proto.Field( - proto.STRING, - number=2, - ) - - -class RestoreDatabaseRequest(proto.Message): - r"""The request for - [RestoreDatabase][google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase]. - - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - parent (str): - Required. The name of the instance in which to create the - restored database. This instance must be in the same project - and have the same instance configuration as the instance - containing the source backup. Values are of the form - ``projects//instances/``. - database_id (str): - Required. The id of the database to create and restore to. - This database must not already exist. The ``database_id`` - appended to ``parent`` forms the full database name of the - form - ``projects//instances//databases/``. - backup (str): - Name of the backup from which to restore. Values are of the - form - ``projects//instances//backups/``. - - This field is a member of `oneof`_ ``source``. - encryption_config (google.cloud.spanner_admin_database_v1.types.RestoreDatabaseEncryptionConfig): - Optional. An encryption configuration describing the - encryption type and key resources in Cloud KMS used to - encrypt/decrypt the database to restore to. If this field is - not specified, the restored database will use the same - encryption configuration as the backup by default, namely - [encryption_type][google.spanner.admin.database.v1.RestoreDatabaseEncryptionConfig.encryption_type] - = ``USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION``. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - database_id: str = proto.Field( - proto.STRING, - number=2, - ) - backup: str = proto.Field( - proto.STRING, - number=3, - oneof='source', - ) - encryption_config: 'RestoreDatabaseEncryptionConfig' = proto.Field( - proto.MESSAGE, - number=4, - message='RestoreDatabaseEncryptionConfig', - ) - - -class RestoreDatabaseEncryptionConfig(proto.Message): - r"""Encryption configuration for the restored database. - - Attributes: - encryption_type (google.cloud.spanner_admin_database_v1.types.RestoreDatabaseEncryptionConfig.EncryptionType): - Required. The encryption type of the restored - database. - kms_key_name (str): - Optional. The Cloud KMS key that will be used to - encrypt/decrypt the restored database. This field should be - set only when - [encryption_type][google.spanner.admin.database.v1.RestoreDatabaseEncryptionConfig.encryption_type] - is ``CUSTOMER_MANAGED_ENCRYPTION``. Values are of the form - ``projects//locations//keyRings//cryptoKeys/``. - """ - class EncryptionType(proto.Enum): - r"""Encryption types for the database to be restored. - - Values: - ENCRYPTION_TYPE_UNSPECIFIED (0): - Unspecified. Do not use. - USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION (1): - This is the default option when - [encryption_config][google.spanner.admin.database.v1.RestoreDatabaseEncryptionConfig] - is not specified. - GOOGLE_DEFAULT_ENCRYPTION (2): - Use Google default encryption. - CUSTOMER_MANAGED_ENCRYPTION (3): - Use customer managed encryption. If specified, - ``kms_key_name`` must must contain a valid Cloud KMS key. - """ - ENCRYPTION_TYPE_UNSPECIFIED = 0 - USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION = 1 - GOOGLE_DEFAULT_ENCRYPTION = 2 - CUSTOMER_MANAGED_ENCRYPTION = 3 - - encryption_type: EncryptionType = proto.Field( - proto.ENUM, - number=1, - enum=EncryptionType, - ) - kms_key_name: str = proto.Field( - proto.STRING, - number=2, - ) - - -class RestoreDatabaseMetadata(proto.Message): - r"""Metadata type for the long-running operation returned by - [RestoreDatabase][google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase]. - - - .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields - - Attributes: - name (str): - Name of the database being created and - restored to. - source_type (google.cloud.spanner_admin_database_v1.types.RestoreSourceType): - The type of the restore source. - backup_info (google.cloud.spanner_admin_database_v1.types.BackupInfo): - Information about the backup used to restore - the database. - - This field is a member of `oneof`_ ``source_info``. - progress (google.cloud.spanner_admin_database_v1.types.OperationProgress): - The progress of the - [RestoreDatabase][google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase] - operation. - cancel_time (google.protobuf.timestamp_pb2.Timestamp): - The time at which cancellation of this operation was - received. - [Operations.CancelOperation][google.longrunning.Operations.CancelOperation] - starts asynchronous cancellation on a long-running - operation. The server makes a best effort to cancel the - operation, but success is not guaranteed. Clients can use - [Operations.GetOperation][google.longrunning.Operations.GetOperation] - or other methods to check whether the cancellation succeeded - or whether the operation completed despite cancellation. On - successful cancellation, the operation is not deleted; - instead, it becomes an operation with an - [Operation.error][google.longrunning.Operation.error] value - with a [google.rpc.Status.code][google.rpc.Status.code] of - 1, corresponding to ``Code.CANCELLED``. - optimize_database_operation_name (str): - If exists, the name of the long-running operation that will - be used to track the post-restore optimization process to - optimize the performance of the restored database, and - remove the dependency on the restore source. The name is of - the form - ``projects//instances//databases//operations/`` - where the is the name of database being created and restored - to. The metadata type of the long-running operation is - [OptimizeRestoredDatabaseMetadata][google.spanner.admin.database.v1.OptimizeRestoredDatabaseMetadata]. - This long-running operation will be automatically created by - the system after the RestoreDatabase long-running operation - completes successfully. This operation will not be created - if the restore was not successful. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - source_type: 'RestoreSourceType' = proto.Field( - proto.ENUM, - number=2, - enum='RestoreSourceType', - ) - backup_info: gsad_backup.BackupInfo = proto.Field( - proto.MESSAGE, - number=3, - oneof='source_info', - message=gsad_backup.BackupInfo, - ) - progress: common.OperationProgress = proto.Field( - proto.MESSAGE, - number=4, - message=common.OperationProgress, - ) - cancel_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=5, - message=timestamp_pb2.Timestamp, - ) - optimize_database_operation_name: str = proto.Field( - proto.STRING, - number=6, - ) - - -class OptimizeRestoredDatabaseMetadata(proto.Message): - r"""Metadata type for the long-running operation used to track - the progress of optimizations performed on a newly restored - database. This long-running operation is automatically created - by the system after the successful completion of a database - restore, and cannot be cancelled. - - Attributes: - name (str): - Name of the restored database being - optimized. - progress (google.cloud.spanner_admin_database_v1.types.OperationProgress): - The progress of the post-restore - optimizations. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - progress: common.OperationProgress = proto.Field( - proto.MESSAGE, - number=2, - message=common.OperationProgress, - ) - - -class DatabaseRole(proto.Message): - r"""A Cloud Spanner database role. - - Attributes: - name (str): - Required. The name of the database role. Values are of the - form - ``projects//instances//databases//databaseRoles/ {role}``, - where ```` is as specified in the ``CREATE ROLE`` DDL - statement. This name can be passed to Get/Set IAMPolicy - methods to identify the database role. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - - -class ListDatabaseRolesRequest(proto.Message): - r"""The request for - [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. - - Attributes: - parent (str): - Required. The database whose roles should be listed. Values - are of the form - ``projects//instances//databases//databaseRoles``. - page_size (int): - Number of database roles to be returned in - the response. If 0 or less, defaults to the - server's maximum allowed page size. - page_token (str): - If non-empty, ``page_token`` should contain a - [next_page_token][google.spanner.admin.database.v1.ListDatabaseRolesResponse.next_page_token] - from a previous - [ListDatabaseRolesResponse][google.spanner.admin.database.v1.ListDatabaseRolesResponse]. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - page_size: int = proto.Field( - proto.INT32, - number=2, - ) - page_token: str = proto.Field( - proto.STRING, - number=3, - ) - - -class ListDatabaseRolesResponse(proto.Message): - r"""The response for - [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles]. - - Attributes: - database_roles (MutableSequence[google.cloud.spanner_admin_database_v1.types.DatabaseRole]): - Database roles that matched the request. - next_page_token (str): - ``next_page_token`` can be sent in a subsequent - [ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles] - call to fetch more of the matching roles. - """ - - @property - def raw_page(self): - return self - - database_roles: MutableSequence['DatabaseRole'] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='DatabaseRole', - ) - next_page_token: str = proto.Field( - proto.STRING, - number=2, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner_admin_database/v1/mypy.ini b/owl-bot-staging/spanner_admin_database/v1/mypy.ini deleted file mode 100644 index 574c5aed39..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/mypy.ini +++ /dev/null @@ -1,3 +0,0 @@ -[mypy] -python_version = 3.7 -namespace_packages = True diff --git a/owl-bot-staging/spanner_admin_database/v1/noxfile.py b/owl-bot-staging/spanner_admin_database/v1/noxfile.py deleted file mode 100644 index d00593d952..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/noxfile.py +++ /dev/null @@ -1,184 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -import pathlib -import shutil -import subprocess -import sys - - -import nox # type: ignore - -ALL_PYTHON = [ - "3.7", - "3.8", - "3.9", - "3.10", - "3.11", -] - -CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() - -LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" -PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8") - -BLACK_VERSION = "black==22.3.0" -BLACK_PATHS = ["docs", "google", "tests", "samples", "noxfile.py", "setup.py"] -DEFAULT_PYTHON_VERSION = "3.11" - -nox.sessions = [ - "unit", - "cover", - "mypy", - "check_lower_bounds" - # exclude update_lower_bounds from default - "docs", - "blacken", - "lint", - "lint_setup_py", -] - -@nox.session(python=ALL_PYTHON) -def unit(session): - """Run the unit test suite.""" - - session.install('coverage', 'pytest', 'pytest-cov', 'pytest-asyncio', 'asyncmock; python_version < "3.8"') - session.install('-e', '.') - - session.run( - 'py.test', - '--quiet', - '--cov=google/cloud/spanner_admin_database_v1/', - '--cov=tests/', - '--cov-config=.coveragerc', - '--cov-report=term', - '--cov-report=html', - os.path.join('tests', 'unit', ''.join(session.posargs)) - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def cover(session): - """Run the final coverage report. - This outputs the coverage report aggregating coverage from the unit - test runs (not system test runs), and then erases coverage data. - """ - session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=100") - - session.run("coverage", "erase") - - -@nox.session(python=ALL_PYTHON) -def mypy(session): - """Run the type checker.""" - session.install( - 'mypy', - 'types-requests', - 'types-protobuf' - ) - session.install('.') - session.run( - 'mypy', - '--explicit-package-bases', - 'google', - ) - - -@nox.session -def update_lower_bounds(session): - """Update lower bounds in constraints.txt to match setup.py""" - session.install('google-cloud-testutils') - session.install('.') - - session.run( - 'lower-bound-checker', - 'update', - '--package-name', - PACKAGE_NAME, - '--constraints-file', - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - - -@nox.session -def check_lower_bounds(session): - """Check lower bounds in setup.py are reflected in constraints file""" - session.install('google-cloud-testutils') - session.install('.') - - session.run( - 'lower-bound-checker', - 'check', - '--package-name', - PACKAGE_NAME, - '--constraints-file', - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def docs(session): - """Build the docs for this library.""" - - session.install("-e", ".") - session.install("sphinx==4.0.1", "alabaster", "recommonmark") - - shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) - session.run( - "sphinx-build", - "-W", # warnings as errors - "-T", # show full traceback on exception - "-N", # no colors - "-b", - "html", - "-d", - os.path.join("docs", "_build", "doctrees", ""), - os.path.join("docs", ""), - os.path.join("docs", "_build", "html", ""), - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def lint(session): - """Run linters. - - Returns a failure if the linters find linting errors or sufficiently - serious code quality issues. - """ - session.install("flake8", BLACK_VERSION) - session.run( - "black", - "--check", - *BLACK_PATHS, - ) - session.run("flake8", "google", "tests", "samples") - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def blacken(session): - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - session.run( - "black", - *BLACK_PATHS, - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def lint_setup_py(session): - """Verify that setup.py is valid (including RST check).""" - session.install("docutils", "pygments") - session.run("python", "setup.py", "check", "--restructuredtext", "--strict") diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.database.v1.json b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.database.v1.json deleted file mode 100644 index 11932ae5e8..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.database.v1.json +++ /dev/null @@ -1,3319 +0,0 @@ -{ - "clientLibrary": { - "apis": [ - { - "id": "google.spanner.admin.database.v1", - "version": "v1" - } - ], - "language": "PYTHON", - "name": "google-cloud-spanner-admin-database", - "version": "0.1.0" - }, - "snippets": [ - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.copy_backup", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "CopyBackup" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.CopyBackupRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "backup_id", - "type": "str" - }, - { - "name": "source_backup", - "type": "str" - }, - { - "name": "expire_time", - "type": "google.protobuf.timestamp_pb2.Timestamp" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "copy_backup" - }, - "description": "Sample for CopyBackup", - "file": "spanner_v1_generated_database_admin_copy_backup_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_CopyBackup_async", - "segments": [ - { - "end": 57, - "start": 27, - "type": "FULL" - }, - { - "end": 57, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 47, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 54, - "start": 48, - "type": "REQUEST_EXECUTION" - }, - { - "end": 58, - "start": 55, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_copy_backup_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.copy_backup", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CopyBackup", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "CopyBackup" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.CopyBackupRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "backup_id", - "type": "str" - }, - { - "name": "source_backup", - "type": "str" - }, - { - "name": "expire_time", - "type": "google.protobuf.timestamp_pb2.Timestamp" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation.Operation", - "shortName": "copy_backup" - }, - "description": "Sample for CopyBackup", - "file": "spanner_v1_generated_database_admin_copy_backup_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_CopyBackup_sync", - "segments": [ - { - "end": 57, - "start": 27, - "type": "FULL" - }, - { - "end": 57, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 47, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 54, - "start": 48, - "type": "REQUEST_EXECUTION" - }, - { - "end": 58, - "start": 55, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_copy_backup_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.create_backup", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "CreateBackup" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.CreateBackupRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "backup", - "type": "google.cloud.spanner_admin_database_v1.types.Backup" - }, - { - "name": "backup_id", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "create_backup" - }, - "description": "Sample for CreateBackup", - "file": "spanner_v1_generated_database_admin_create_backup_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_CreateBackup_async", - "segments": [ - { - "end": 56, - "start": 27, - "type": "FULL" - }, - { - "end": 56, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 53, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 57, - "start": 54, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_create_backup_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.create_backup", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CreateBackup", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "CreateBackup" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.CreateBackupRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "backup", - "type": "google.cloud.spanner_admin_database_v1.types.Backup" - }, - { - "name": "backup_id", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation.Operation", - "shortName": "create_backup" - }, - "description": "Sample for CreateBackup", - "file": "spanner_v1_generated_database_admin_create_backup_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_CreateBackup_sync", - "segments": [ - { - "end": 56, - "start": 27, - "type": "FULL" - }, - { - "end": 56, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 53, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 57, - "start": 54, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_create_backup_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.create_database", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "CreateDatabase" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.CreateDatabaseRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "create_statement", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "create_database" - }, - "description": "Sample for CreateDatabase", - "file": "spanner_v1_generated_database_admin_create_database_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_CreateDatabase_async", - "segments": [ - { - "end": 56, - "start": 27, - "type": "FULL" - }, - { - "end": 56, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 53, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 57, - "start": 54, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_create_database_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.create_database", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "CreateDatabase" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.CreateDatabaseRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "create_statement", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation.Operation", - "shortName": "create_database" - }, - "description": "Sample for CreateDatabase", - "file": "spanner_v1_generated_database_admin_create_database_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_CreateDatabase_sync", - "segments": [ - { - "end": 56, - "start": 27, - "type": "FULL" - }, - { - "end": 56, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 53, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 57, - "start": 54, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_create_database_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.delete_backup", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "DeleteBackup" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.DeleteBackupRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "shortName": "delete_backup" - }, - "description": "Sample for DeleteBackup", - "file": "spanner_v1_generated_database_admin_delete_backup_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_DeleteBackup_async", - "segments": [ - { - "end": 49, - "start": 27, - "type": "FULL" - }, - { - "end": 49, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_delete_backup_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.delete_backup", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.DeleteBackup", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "DeleteBackup" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.DeleteBackupRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "shortName": "delete_backup" - }, - "description": "Sample for DeleteBackup", - "file": "spanner_v1_generated_database_admin_delete_backup_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_DeleteBackup_sync", - "segments": [ - { - "end": 49, - "start": 27, - "type": "FULL" - }, - { - "end": 49, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_delete_backup_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.drop_database", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "DropDatabase" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.DropDatabaseRequest" - }, - { - "name": "database", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "shortName": "drop_database" - }, - "description": "Sample for DropDatabase", - "file": "spanner_v1_generated_database_admin_drop_database_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_DropDatabase_async", - "segments": [ - { - "end": 49, - "start": 27, - "type": "FULL" - }, - { - "end": 49, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_drop_database_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.drop_database", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "DropDatabase" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.DropDatabaseRequest" - }, - { - "name": "database", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "shortName": "drop_database" - }, - "description": "Sample for DropDatabase", - "file": "spanner_v1_generated_database_admin_drop_database_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_DropDatabase_sync", - "segments": [ - { - "end": 49, - "start": 27, - "type": "FULL" - }, - { - "end": 49, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_drop_database_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.get_backup", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetBackup", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "GetBackup" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.GetBackupRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.types.Backup", - "shortName": "get_backup" - }, - "description": "Sample for GetBackup", - "file": "spanner_v1_generated_database_admin_get_backup_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_GetBackup_async", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_get_backup_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.get_backup", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetBackup", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "GetBackup" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.GetBackupRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.types.Backup", - "shortName": "get_backup" - }, - "description": "Sample for GetBackup", - "file": "spanner_v1_generated_database_admin_get_backup_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_GetBackup_sync", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_get_backup_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.get_database_ddl", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "GetDatabaseDdl" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlRequest" - }, - { - "name": "database", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlResponse", - "shortName": "get_database_ddl" - }, - "description": "Sample for GetDatabaseDdl", - "file": "spanner_v1_generated_database_admin_get_database_ddl_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_async", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_get_database_ddl_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.get_database_ddl", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "GetDatabaseDdl" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlRequest" - }, - { - "name": "database", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlResponse", - "shortName": "get_database_ddl" - }, - "description": "Sample for GetDatabaseDdl", - "file": "spanner_v1_generated_database_admin_get_database_ddl_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_sync", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_get_database_ddl_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.get_database", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "GetDatabase" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.GetDatabaseRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.types.Database", - "shortName": "get_database" - }, - "description": "Sample for GetDatabase", - "file": "spanner_v1_generated_database_admin_get_database_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_GetDatabase_async", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_get_database_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.get_database", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "GetDatabase" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.GetDatabaseRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.types.Database", - "shortName": "get_database" - }, - "description": "Sample for GetDatabase", - "file": "spanner_v1_generated_database_admin_get_database_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_GetDatabase_sync", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_get_database_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.get_iam_policy", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetIamPolicy", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "GetIamPolicy" - }, - "parameters": [ - { - "name": "request", - "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" - }, - { - "name": "resource", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.iam.v1.policy_pb2.Policy", - "shortName": "get_iam_policy" - }, - "description": "Sample for GetIamPolicy", - "file": "spanner_v1_generated_database_admin_get_iam_policy_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_GetIamPolicy_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 41, - "start": 39, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 42, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_get_iam_policy_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.get_iam_policy", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.GetIamPolicy", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "GetIamPolicy" - }, - "parameters": [ - { - "name": "request", - "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" - }, - { - "name": "resource", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.iam.v1.policy_pb2.Policy", - "shortName": "get_iam_policy" - }, - "description": "Sample for GetIamPolicy", - "file": "spanner_v1_generated_database_admin_get_iam_policy_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_GetIamPolicy_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 41, - "start": 39, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 42, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_get_iam_policy_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.list_backup_operations", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "ListBackupOperations" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupOperationsAsyncPager", - "shortName": "list_backup_operations" - }, - "description": "Sample for ListBackupOperations", - "file": "spanner_v1_generated_database_admin_list_backup_operations_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_ListBackupOperations_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_list_backup_operations_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.list_backup_operations", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListBackupOperations", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "ListBackupOperations" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.ListBackupOperationsRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupOperationsPager", - "shortName": "list_backup_operations" - }, - "description": "Sample for ListBackupOperations", - "file": "spanner_v1_generated_database_admin_list_backup_operations_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_ListBackupOperations_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_list_backup_operations_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.list_backups", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListBackups", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "ListBackups" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.ListBackupsRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupsAsyncPager", - "shortName": "list_backups" - }, - "description": "Sample for ListBackups", - "file": "spanner_v1_generated_database_admin_list_backups_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_ListBackups_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_list_backups_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.list_backups", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListBackups", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "ListBackups" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.ListBackupsRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListBackupsPager", - "shortName": "list_backups" - }, - "description": "Sample for ListBackups", - "file": "spanner_v1_generated_database_admin_list_backups_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_ListBackups_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_list_backups_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.list_database_operations", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "ListDatabaseOperations" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseOperationsAsyncPager", - "shortName": "list_database_operations" - }, - "description": "Sample for ListDatabaseOperations", - "file": "spanner_v1_generated_database_admin_list_database_operations_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_list_database_operations_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.list_database_operations", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseOperations", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "ListDatabaseOperations" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.ListDatabaseOperationsRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseOperationsPager", - "shortName": "list_database_operations" - }, - "description": "Sample for ListDatabaseOperations", - "file": "spanner_v1_generated_database_admin_list_database_operations_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_list_database_operations_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.list_database_roles", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "ListDatabaseRoles" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseRolesAsyncPager", - "shortName": "list_database_roles" - }, - "description": "Sample for ListDatabaseRoles", - "file": "spanner_v1_generated_database_admin_list_database_roles_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabaseRoles_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_list_database_roles_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.list_database_roles", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "ListDatabaseRoles" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseRolesPager", - "shortName": "list_database_roles" - }, - "description": "Sample for ListDatabaseRoles", - "file": "spanner_v1_generated_database_admin_list_database_roles_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabaseRoles_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_list_database_roles_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.list_databases", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "ListDatabases" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabasesAsyncPager", - "shortName": "list_databases" - }, - "description": "Sample for ListDatabases", - "file": "spanner_v1_generated_database_admin_list_databases_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabases_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_list_databases_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.list_databases", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "ListDatabases" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.ListDatabasesRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabasesPager", - "shortName": "list_databases" - }, - "description": "Sample for ListDatabases", - "file": "spanner_v1_generated_database_admin_list_databases_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_ListDatabases_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_list_databases_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.restore_database", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "RestoreDatabase" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.RestoreDatabaseRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "database_id", - "type": "str" - }, - { - "name": "backup", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "restore_database" - }, - "description": "Sample for RestoreDatabase", - "file": "spanner_v1_generated_database_admin_restore_database_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_RestoreDatabase_async", - "segments": [ - { - "end": 57, - "start": 27, - "type": "FULL" - }, - { - "end": 57, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 47, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 54, - "start": 48, - "type": "REQUEST_EXECUTION" - }, - { - "end": 58, - "start": 55, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_restore_database_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.restore_database", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.RestoreDatabase", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "RestoreDatabase" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.RestoreDatabaseRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "database_id", - "type": "str" - }, - { - "name": "backup", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation.Operation", - "shortName": "restore_database" - }, - "description": "Sample for RestoreDatabase", - "file": "spanner_v1_generated_database_admin_restore_database_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_RestoreDatabase_sync", - "segments": [ - { - "end": 57, - "start": 27, - "type": "FULL" - }, - { - "end": 57, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 47, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 54, - "start": 48, - "type": "REQUEST_EXECUTION" - }, - { - "end": 58, - "start": 55, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_restore_database_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.set_iam_policy", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.SetIamPolicy", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "SetIamPolicy" - }, - "parameters": [ - { - "name": "request", - "type": "google.iam.v1.iam_policy_pb2.SetIamPolicyRequest" - }, - { - "name": "resource", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.iam.v1.policy_pb2.Policy", - "shortName": "set_iam_policy" - }, - "description": "Sample for SetIamPolicy", - "file": "spanner_v1_generated_database_admin_set_iam_policy_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_SetIamPolicy_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 41, - "start": 39, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 42, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_set_iam_policy_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.set_iam_policy", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.SetIamPolicy", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "SetIamPolicy" - }, - "parameters": [ - { - "name": "request", - "type": "google.iam.v1.iam_policy_pb2.SetIamPolicyRequest" - }, - { - "name": "resource", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.iam.v1.policy_pb2.Policy", - "shortName": "set_iam_policy" - }, - "description": "Sample for SetIamPolicy", - "file": "spanner_v1_generated_database_admin_set_iam_policy_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_SetIamPolicy_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 41, - "start": 39, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 42, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_set_iam_policy_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.test_iam_permissions", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.TestIamPermissions", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "TestIamPermissions" - }, - "parameters": [ - { - "name": "request", - "type": "google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest" - }, - { - "name": "resource", - "type": "str" - }, - { - "name": "permissions", - "type": "MutableSequence[str]" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", - "shortName": "test_iam_permissions" - }, - "description": "Sample for TestIamPermissions", - "file": "spanner_v1_generated_database_admin_test_iam_permissions_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_TestIamPermissions_async", - "segments": [ - { - "end": 53, - "start": 27, - "type": "FULL" - }, - { - "end": 53, - "start": 27, - "type": "SHORT" - }, - { - "end": 41, - "start": 39, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 47, - "start": 42, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 50, - "start": 48, - "type": "REQUEST_EXECUTION" - }, - { - "end": 54, - "start": 51, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_test_iam_permissions_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.test_iam_permissions", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.TestIamPermissions", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "TestIamPermissions" - }, - "parameters": [ - { - "name": "request", - "type": "google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest" - }, - { - "name": "resource", - "type": "str" - }, - { - "name": "permissions", - "type": "MutableSequence[str]" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", - "shortName": "test_iam_permissions" - }, - "description": "Sample for TestIamPermissions", - "file": "spanner_v1_generated_database_admin_test_iam_permissions_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_TestIamPermissions_sync", - "segments": [ - { - "end": 53, - "start": 27, - "type": "FULL" - }, - { - "end": 53, - "start": 27, - "type": "SHORT" - }, - { - "end": 41, - "start": 39, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 47, - "start": 42, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 50, - "start": 48, - "type": "REQUEST_EXECUTION" - }, - { - "end": 54, - "start": 51, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_test_iam_permissions_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.update_backup", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "UpdateBackup" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.UpdateBackupRequest" - }, - { - "name": "backup", - "type": "google.cloud.spanner_admin_database_v1.types.Backup" - }, - { - "name": "update_mask", - "type": "google.protobuf.field_mask_pb2.FieldMask" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.types.Backup", - "shortName": "update_backup" - }, - "description": "Sample for UpdateBackup", - "file": "spanner_v1_generated_database_admin_update_backup_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateBackup_async", - "segments": [ - { - "end": 50, - "start": 27, - "type": "FULL" - }, - { - "end": 50, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 44, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 47, - "start": 45, - "type": "REQUEST_EXECUTION" - }, - { - "end": 51, - "start": 48, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_update_backup_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.update_backup", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateBackup", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "UpdateBackup" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.UpdateBackupRequest" - }, - { - "name": "backup", - "type": "google.cloud.spanner_admin_database_v1.types.Backup" - }, - { - "name": "update_mask", - "type": "google.protobuf.field_mask_pb2.FieldMask" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_database_v1.types.Backup", - "shortName": "update_backup" - }, - "description": "Sample for UpdateBackup", - "file": "spanner_v1_generated_database_admin_update_backup_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateBackup_sync", - "segments": [ - { - "end": 50, - "start": 27, - "type": "FULL" - }, - { - "end": 50, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 44, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 47, - "start": 45, - "type": "REQUEST_EXECUTION" - }, - { - "end": 51, - "start": 48, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_update_backup_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.update_database_ddl", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "UpdateDatabaseDdl" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.UpdateDatabaseDdlRequest" - }, - { - "name": "database", - "type": "str" - }, - { - "name": "statements", - "type": "MutableSequence[str]" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "update_database_ddl" - }, - "description": "Sample for UpdateDatabaseDdl", - "file": "spanner_v1_generated_database_admin_update_database_ddl_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_async", - "segments": [ - { - "end": 56, - "start": 27, - "type": "FULL" - }, - { - "end": 56, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 53, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 57, - "start": 54, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_update_database_ddl_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.update_database_ddl", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabaseDdl", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "UpdateDatabaseDdl" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.UpdateDatabaseDdlRequest" - }, - { - "name": "database", - "type": "str" - }, - { - "name": "statements", - "type": "MutableSequence[str]" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation.Operation", - "shortName": "update_database_ddl" - }, - "description": "Sample for UpdateDatabaseDdl", - "file": "spanner_v1_generated_database_admin_update_database_ddl_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_sync", - "segments": [ - { - "end": 56, - "start": 27, - "type": "FULL" - }, - { - "end": 56, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 53, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 57, - "start": 54, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_update_database_ddl_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", - "shortName": "DatabaseAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.update_database", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "UpdateDatabase" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest" - }, - { - "name": "database", - "type": "google.cloud.spanner_admin_database_v1.types.Database" - }, - { - "name": "update_mask", - "type": "google.protobuf.field_mask_pb2.FieldMask" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "update_database" - }, - "description": "Sample for UpdateDatabase", - "file": "spanner_v1_generated_database_admin_update_database_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateDatabase_async", - "segments": [ - { - "end": 58, - "start": 27, - "type": "FULL" - }, - { - "end": 58, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 48, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 55, - "start": 49, - "type": "REQUEST_EXECUTION" - }, - { - "end": 59, - "start": 56, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_update_database_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", - "shortName": "DatabaseAdminClient" - }, - "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.update_database", - "method": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase", - "service": { - "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", - "shortName": "DatabaseAdmin" - }, - "shortName": "UpdateDatabase" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest" - }, - { - "name": "database", - "type": "google.cloud.spanner_admin_database_v1.types.Database" - }, - { - "name": "update_mask", - "type": "google.protobuf.field_mask_pb2.FieldMask" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation.Operation", - "shortName": "update_database" - }, - "description": "Sample for UpdateDatabase", - "file": "spanner_v1_generated_database_admin_update_database_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateDatabase_sync", - "segments": [ - { - "end": 58, - "start": 27, - "type": "FULL" - }, - { - "end": 58, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 48, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 55, - "start": 49, - "type": "REQUEST_EXECUTION" - }, - { - "end": 59, - "start": 56, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_database_admin_update_database_sync.py" - } - ] -} diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_async.py deleted file mode 100644 index 63dd1a1230..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_async.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for CopyBackup -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_CopyBackup_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_copy_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.CopyBackupRequest( - parent="parent_value", - backup_id="backup_id_value", - source_backup="source_backup_value", - ) - - # Make the request - operation = client.copy_backup(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_CopyBackup_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_sync.py deleted file mode 100644 index 30d1efc423..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_copy_backup_sync.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for CopyBackup -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_CopyBackup_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_copy_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.CopyBackupRequest( - parent="parent_value", - backup_id="backup_id_value", - source_backup="source_backup_value", - ) - - # Make the request - operation = client.copy_backup(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_CopyBackup_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_async.py deleted file mode 100644 index 530f39e816..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_async.py +++ /dev/null @@ -1,57 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for CreateBackup -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_CreateBackup_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_create_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.CreateBackupRequest( - parent="parent_value", - backup_id="backup_id_value", - ) - - # Make the request - operation = client.create_backup(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_CreateBackup_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_sync.py deleted file mode 100644 index 9af8c6943a..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_backup_sync.py +++ /dev/null @@ -1,57 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for CreateBackup -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_CreateBackup_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_create_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.CreateBackupRequest( - parent="parent_value", - backup_id="backup_id_value", - ) - - # Make the request - operation = client.create_backup(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_CreateBackup_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_async.py deleted file mode 100644 index e9525c02ec..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_async.py +++ /dev/null @@ -1,57 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for CreateDatabase -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_CreateDatabase_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_create_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.CreateDatabaseRequest( - parent="parent_value", - create_statement="create_statement_value", - ) - - # Make the request - operation = client.create_database(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_CreateDatabase_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_sync.py deleted file mode 100644 index 95d549e82f..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_create_database_sync.py +++ /dev/null @@ -1,57 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for CreateDatabase -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_CreateDatabase_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_create_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.CreateDatabaseRequest( - parent="parent_value", - create_statement="create_statement_value", - ) - - # Make the request - operation = client.create_database(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_CreateDatabase_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_async.py deleted file mode 100644 index 630c8b34dd..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_async.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for DeleteBackup -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_DeleteBackup_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_delete_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.DeleteBackupRequest( - name="name_value", - ) - - # Make the request - await client.delete_backup(request=request) - - -# [END spanner_v1_generated_DatabaseAdmin_DeleteBackup_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_sync.py deleted file mode 100644 index b1ea092308..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_delete_backup_sync.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for DeleteBackup -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_DeleteBackup_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_delete_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.DeleteBackupRequest( - name="name_value", - ) - - # Make the request - client.delete_backup(request=request) - - -# [END spanner_v1_generated_DatabaseAdmin_DeleteBackup_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_async.py deleted file mode 100644 index 4683f47e99..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_async.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for DropDatabase -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_DropDatabase_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_drop_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.DropDatabaseRequest( - database="database_value", - ) - - # Make the request - await client.drop_database(request=request) - - -# [END spanner_v1_generated_DatabaseAdmin_DropDatabase_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_sync.py deleted file mode 100644 index 62c322279a..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_drop_database_sync.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for DropDatabase -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_DropDatabase_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_drop_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.DropDatabaseRequest( - database="database_value", - ) - - # Make the request - client.drop_database(request=request) - - -# [END spanner_v1_generated_DatabaseAdmin_DropDatabase_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_async.py deleted file mode 100644 index e41b762328..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_async.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetBackup -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_GetBackup_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_get_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.GetBackupRequest( - name="name_value", - ) - - # Make the request - response = await client.get_backup(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_GetBackup_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_sync.py deleted file mode 100644 index 9d65904d9f..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_backup_sync.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetBackup -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_GetBackup_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_get_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.GetBackupRequest( - name="name_value", - ) - - # Make the request - response = client.get_backup(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_GetBackup_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_async.py deleted file mode 100644 index 6fb00eab77..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_async.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetDatabase -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_GetDatabase_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_get_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.GetDatabaseRequest( - name="name_value", - ) - - # Make the request - response = await client.get_database(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_GetDatabase_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_async.py deleted file mode 100644 index 1d386931a8..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_async.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetDatabaseDdl -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_get_database_ddl(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.GetDatabaseDdlRequest( - database="database_value", - ) - - # Make the request - response = await client.get_database_ddl(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_sync.py deleted file mode 100644 index 79b8d9516a..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_ddl_sync.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetDatabaseDdl -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_get_database_ddl(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.GetDatabaseDdlRequest( - database="database_value", - ) - - # Make the request - response = client.get_database_ddl(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_GetDatabaseDdl_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_sync.py deleted file mode 100644 index 5f5f80083e..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_database_sync.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetDatabase -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_GetDatabase_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_get_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.GetDatabaseRequest( - name="name_value", - ) - - # Make the request - response = client.get_database(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_GetDatabase_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_async.py deleted file mode 100644 index 3b4e55b75b..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetIamPolicy -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_GetIamPolicy_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 -from google.iam.v1 import iam_policy_pb2 # type: ignore - - -async def sample_get_iam_policy(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = iam_policy_pb2.GetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = await client.get_iam_policy(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_GetIamPolicy_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_sync.py deleted file mode 100644 index 84c49219c5..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_get_iam_policy_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetIamPolicy -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_GetIamPolicy_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 -from google.iam.v1 import iam_policy_pb2 # type: ignore - - -def sample_get_iam_policy(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = iam_policy_pb2.GetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = client.get_iam_policy(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_GetIamPolicy_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_async.py deleted file mode 100644 index 2c13cc98cd..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListBackupOperations -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_ListBackupOperations_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_list_backup_operations(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListBackupOperationsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_backup_operations(request=request) - - # Handle the response - async for response in page_result: - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_ListBackupOperations_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_sync.py deleted file mode 100644 index cebc0ff3c3..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backup_operations_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListBackupOperations -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_ListBackupOperations_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_list_backup_operations(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListBackupOperationsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_backup_operations(request=request) - - # Handle the response - for response in page_result: - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_ListBackupOperations_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_async.py deleted file mode 100644 index f23a15cc85..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListBackups -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_ListBackups_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_list_backups(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListBackupsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_backups(request=request) - - # Handle the response - async for response in page_result: - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_ListBackups_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_sync.py deleted file mode 100644 index 93105567fa..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_backups_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListBackups -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_ListBackups_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_list_backups(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListBackupsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_backups(request=request) - - # Handle the response - for response in page_result: - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_ListBackups_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_async.py deleted file mode 100644 index 8611d349ac..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListDatabaseOperations -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_list_database_operations(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListDatabaseOperationsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_database_operations(request=request) - - # Handle the response - async for response in page_result: - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_sync.py deleted file mode 100644 index 10b059bc4a..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_operations_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListDatabaseOperations -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_list_database_operations(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListDatabaseOperationsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_database_operations(request=request) - - # Handle the response - for response in page_result: - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_ListDatabaseOperations_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_async.py deleted file mode 100644 index b4848d4be0..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListDatabaseRoles -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_ListDatabaseRoles_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_list_database_roles(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListDatabaseRolesRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_database_roles(request=request) - - # Handle the response - async for response in page_result: - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_ListDatabaseRoles_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_sync.py deleted file mode 100644 index b46bc5c8f4..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_database_roles_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListDatabaseRoles -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_ListDatabaseRoles_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_list_database_roles(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListDatabaseRolesRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_database_roles(request=request) - - # Handle the response - for response in page_result: - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_ListDatabaseRoles_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_async.py deleted file mode 100644 index 13f1472d56..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListDatabases -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_ListDatabases_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_list_databases(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListDatabasesRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_databases(request=request) - - # Handle the response - async for response in page_result: - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_ListDatabases_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_sync.py deleted file mode 100644 index 97bd5a23a3..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_list_databases_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListDatabases -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_ListDatabases_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_list_databases(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.ListDatabasesRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_databases(request=request) - - # Handle the response - for response in page_result: - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_ListDatabases_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_async.py deleted file mode 100644 index bf5b073250..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_async.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for RestoreDatabase -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_RestoreDatabase_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_restore_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.RestoreDatabaseRequest( - backup="backup_value", - parent="parent_value", - database_id="database_id_value", - ) - - # Make the request - operation = client.restore_database(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_RestoreDatabase_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_sync.py deleted file mode 100644 index 92a98e4868..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_restore_database_sync.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for RestoreDatabase -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_RestoreDatabase_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_restore_database(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.RestoreDatabaseRequest( - backup="backup_value", - parent="parent_value", - database_id="database_id_value", - ) - - # Make the request - operation = client.restore_database(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_RestoreDatabase_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_async.py deleted file mode 100644 index 9c045ccdf3..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for SetIamPolicy -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_SetIamPolicy_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 -from google.iam.v1 import iam_policy_pb2 # type: ignore - - -async def sample_set_iam_policy(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = iam_policy_pb2.SetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = await client.set_iam_policy(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_SetIamPolicy_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_sync.py deleted file mode 100644 index e2ba9269ed..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_set_iam_policy_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for SetIamPolicy -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_SetIamPolicy_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 -from google.iam.v1 import iam_policy_pb2 # type: ignore - - -def sample_set_iam_policy(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = iam_policy_pb2.SetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = client.set_iam_policy(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_SetIamPolicy_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_async.py deleted file mode 100644 index b96cd5a67b..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_async.py +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for TestIamPermissions -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_TestIamPermissions_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 -from google.iam.v1 import iam_policy_pb2 # type: ignore - - -async def sample_test_iam_permissions(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = iam_policy_pb2.TestIamPermissionsRequest( - resource="resource_value", - permissions=['permissions_value1', 'permissions_value2'], - ) - - # Make the request - response = await client.test_iam_permissions(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_TestIamPermissions_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_sync.py deleted file mode 100644 index 40a31194ae..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_test_iam_permissions_sync.py +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for TestIamPermissions -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_TestIamPermissions_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 -from google.iam.v1 import iam_policy_pb2 # type: ignore - - -def sample_test_iam_permissions(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = iam_policy_pb2.TestIamPermissionsRequest( - resource="resource_value", - permissions=['permissions_value1', 'permissions_value2'], - ) - - # Make the request - response = client.test_iam_permissions(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_TestIamPermissions_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_async.py deleted file mode 100644 index c12a2a3721..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_async.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for UpdateBackup -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_UpdateBackup_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_update_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.UpdateBackupRequest( - ) - - # Make the request - response = await client.update_backup(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_UpdateBackup_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_sync.py deleted file mode 100644 index cf4ec006ba..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_backup_sync.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for UpdateBackup -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_UpdateBackup_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_update_backup(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.UpdateBackupRequest( - ) - - # Make the request - response = client.update_backup(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_UpdateBackup_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_async.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_async.py deleted file mode 100644 index 7b7d438b6e..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_async.py +++ /dev/null @@ -1,57 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for UpdateDatabaseDdl -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -async def sample_update_database_ddl(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.UpdateDatabaseDdlRequest( - database="database_value", - statements=['statements_value1', 'statements_value2'], - ) - - # Make the request - operation = client.update_database_ddl(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_async] diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_sync.py b/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_sync.py deleted file mode 100644 index e06df63277..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_ddl_sync.py +++ /dev/null @@ -1,57 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for UpdateDatabaseDdl -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-database - - -# [START spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_database_v1 - - -def sample_update_database_ddl(): - # Create a client - client = spanner_admin_database_v1.DatabaseAdminClient() - - # Initialize request argument(s) - request = spanner_admin_database_v1.UpdateDatabaseDdlRequest( - database="database_value", - statements=['statements_value1', 'statements_value2'], - ) - - # Make the request - operation = client.update_database_ddl(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_DatabaseAdmin_UpdateDatabaseDdl_sync] diff --git a/owl-bot-staging/spanner_admin_database/v1/scripts/fixup_spanner_admin_database_v1_keywords.py b/owl-bot-staging/spanner_admin_database/v1/scripts/fixup_spanner_admin_database_v1_keywords.py deleted file mode 100644 index b358554082..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/scripts/fixup_spanner_admin_database_v1_keywords.py +++ /dev/null @@ -1,195 +0,0 @@ -#! /usr/bin/env python3 -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import argparse -import os -import libcst as cst -import pathlib -import sys -from typing import (Any, Callable, Dict, List, Sequence, Tuple) - - -def partition( - predicate: Callable[[Any], bool], - iterator: Sequence[Any] -) -> Tuple[List[Any], List[Any]]: - """A stable, out-of-place partition.""" - results = ([], []) - - for i in iterator: - results[int(predicate(i))].append(i) - - # Returns trueList, falseList - return results[1], results[0] - - -class spanner_admin_databaseCallTransformer(cst.CSTTransformer): - CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') - METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'copy_backup': ('parent', 'backup_id', 'source_backup', 'expire_time', 'encryption_config', ), - 'create_backup': ('parent', 'backup_id', 'backup', 'encryption_config', ), - 'create_database': ('parent', 'create_statement', 'extra_statements', 'encryption_config', 'database_dialect', ), - 'delete_backup': ('name', ), - 'drop_database': ('database', ), - 'get_backup': ('name', ), - 'get_database': ('name', ), - 'get_database_ddl': ('database', ), - 'get_iam_policy': ('resource', 'options', ), - 'list_backup_operations': ('parent', 'filter', 'page_size', 'page_token', ), - 'list_backups': ('parent', 'filter', 'page_size', 'page_token', ), - 'list_database_operations': ('parent', 'filter', 'page_size', 'page_token', ), - 'list_database_roles': ('parent', 'page_size', 'page_token', ), - 'list_databases': ('parent', 'page_size', 'page_token', ), - 'restore_database': ('parent', 'database_id', 'backup', 'encryption_config', ), - 'set_iam_policy': ('resource', 'policy', 'update_mask', ), - 'test_iam_permissions': ('resource', 'permissions', ), - 'update_backup': ('backup', 'update_mask', ), - 'update_database': ('database', 'update_mask', ), - 'update_database_ddl': ('database', 'statements', 'operation_id', ), - } - - def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: - try: - key = original.func.attr.value - kword_params = self.METHOD_TO_PARAMS[key] - except (AttributeError, KeyError): - # Either not a method from the API or too convoluted to be sure. - return updated - - # If the existing code is valid, keyword args come after positional args. - # Therefore, all positional args must map to the first parameters. - args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) - if any(k.keyword.value == "request" for k in kwargs): - # We've already fixed this file, don't fix it again. - return updated - - kwargs, ctrl_kwargs = partition( - lambda a: a.keyword.value not in self.CTRL_PARAMS, - kwargs - ) - - args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] - ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) - for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) - - request_arg = cst.Arg( - value=cst.Dict([ - cst.DictElement( - cst.SimpleString("'{}'".format(name)), -cst.Element(value=arg.value) - ) - # Note: the args + kwargs looks silly, but keep in mind that - # the control parameters had to be stripped out, and that - # those could have been passed positionally or by keyword. - for name, arg in zip(kword_params, args + kwargs)]), - keyword=cst.Name("request") - ) - - return updated.with_changes( - args=[request_arg] + ctrl_kwargs - ) - - -def fix_files( - in_dir: pathlib.Path, - out_dir: pathlib.Path, - *, - transformer=spanner_admin_databaseCallTransformer(), -): - """Duplicate the input dir to the output dir, fixing file method calls. - - Preconditions: - * in_dir is a real directory - * out_dir is a real, empty directory - """ - pyfile_gen = ( - pathlib.Path(os.path.join(root, f)) - for root, _, files in os.walk(in_dir) - for f in files if os.path.splitext(f)[1] == ".py" - ) - - for fpath in pyfile_gen: - with open(fpath, 'r') as f: - src = f.read() - - # Parse the code and insert method call fixes. - tree = cst.parse_module(src) - updated = tree.visit(transformer) - - # Create the path and directory structure for the new file. - updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) - updated_path.parent.mkdir(parents=True, exist_ok=True) - - # Generate the updated source file at the corresponding path. - with open(updated_path, 'w') as f: - f.write(updated.code) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description="""Fix up source that uses the spanner_admin_database client library. - -The existing sources are NOT overwritten but are copied to output_dir with changes made. - -Note: This tool operates at a best-effort level at converting positional - parameters in client method calls to keyword based parameters. - Cases where it WILL FAIL include - A) * or ** expansion in a method call. - B) Calls via function or method alias (includes free function calls) - C) Indirect or dispatched calls (e.g. the method is looked up dynamically) - - These all constitute false negatives. The tool will also detect false - positives when an API method shares a name with another method. -""") - parser.add_argument( - '-d', - '--input-directory', - required=True, - dest='input_dir', - help='the input directory to walk for python files to fix up', - ) - parser.add_argument( - '-o', - '--output-directory', - required=True, - dest='output_dir', - help='the directory to output files fixed via un-flattening', - ) - args = parser.parse_args() - input_dir = pathlib.Path(args.input_dir) - output_dir = pathlib.Path(args.output_dir) - if not input_dir.is_dir(): - print( - f"input directory '{input_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if not output_dir.is_dir(): - print( - f"output directory '{output_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if os.listdir(output_dir): - print( - f"output directory '{output_dir}' is not empty", - file=sys.stderr, - ) - sys.exit(-1) - - fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/spanner_admin_database/v1/setup.py b/owl-bot-staging/spanner_admin_database/v1/setup.py deleted file mode 100644 index 3887fc3059..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/setup.py +++ /dev/null @@ -1,91 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import io -import os - -import setuptools # type: ignore - -package_root = os.path.abspath(os.path.dirname(__file__)) - -name = 'google-cloud-spanner-admin-database' - - -description = "Google Cloud Spanner Admin Database API client library" - -version = {} -with open(os.path.join(package_root, 'google/cloud/spanner_admin_database/gapic_version.py')) as fp: - exec(fp.read(), version) -version = version["__version__"] - -if version[0] == "0": - release_status = "Development Status :: 4 - Beta" -else: - release_status = "Development Status :: 5 - Production/Stable" - -dependencies = [ - "google-api-core[grpc] >= 1.34.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", - "proto-plus >= 1.22.0, <2.0.0dev", - "proto-plus >= 1.22.2, <2.0.0dev; python_version>='3.11'", - "protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", - "grpc-google-iam-v1 >= 0.12.4, <1.0.0dev", -] -url = "https://github.com/googleapis/python-spanner-admin-database" - -package_root = os.path.abspath(os.path.dirname(__file__)) - -readme_filename = os.path.join(package_root, "README.rst") -with io.open(readme_filename, encoding="utf-8") as readme_file: - readme = readme_file.read() - -packages = [ - package - for package in setuptools.PEP420PackageFinder.find() - if package.startswith("google") -] - -namespaces = ["google", "google.cloud"] - -setuptools.setup( - name=name, - version=version, - description=description, - long_description=readme, - author="Google LLC", - author_email="googleapis-packages@google.com", - license="Apache 2.0", - url=url, - classifiers=[ - release_status, - "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Operating System :: OS Independent", - "Topic :: Internet", - ], - platforms="Posix; MacOS X; Windows", - packages=packages, - python_requires=">=3.7", - namespace_packages=namespaces, - install_requires=dependencies, - include_package_data=True, - zip_safe=False, -) diff --git a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.10.txt b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.10.txt deleted file mode 100644 index ad3f0fa58e..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.10.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.11.txt b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.11.txt deleted file mode 100644 index ad3f0fa58e..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.11.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.12.txt b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.12.txt deleted file mode 100644 index ad3f0fa58e..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.12.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.7.txt b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.7.txt deleted file mode 100644 index 2beecf99e0..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.7.txt +++ /dev/null @@ -1,10 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.0 -proto-plus==1.22.0 -protobuf==3.19.5 -grpc-google-iam-v1==0.12.4 diff --git a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.8.txt b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.8.txt deleted file mode 100644 index ad3f0fa58e..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.8.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.9.txt b/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.9.txt deleted file mode 100644 index ad3f0fa58e..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/testing/constraints-3.9.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_database/v1/tests/__init__.py b/owl-bot-staging/spanner_admin_database/v1/tests/__init__.py deleted file mode 100644 index 231bc12501..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/tests/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner_admin_database/v1/tests/unit/__init__.py b/owl-bot-staging/spanner_admin_database/v1/tests/unit/__init__.py deleted file mode 100644 index 231bc12501..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/tests/unit/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/__init__.py b/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/__init__.py deleted file mode 100644 index 231bc12501..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/__init__.py b/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/__init__.py deleted file mode 100644 index 231bc12501..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py b/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py deleted file mode 100644 index 28087d188d..0000000000 --- a/owl-bot-staging/spanner_admin_database/v1/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py +++ /dev/null @@ -1,12988 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -# try/except added for compatibility with python < 3.8 -try: - from unittest import mock - from unittest.mock import AsyncMock # pragma: NO COVER -except ImportError: # pragma: NO COVER - import mock - -import grpc -from grpc.experimental import aio -from collections.abc import Iterable -from google.protobuf import json_format -import json -import math -import pytest -from proto.marshal.rules.dates import DurationRule, TimestampRule -from proto.marshal.rules import wrappers -from requests import Response -from requests import Request, PreparedRequest -from requests.sessions import Session -from google.protobuf import json_format - -from google.api_core import client_options -from google.api_core import exceptions as core_exceptions -from google.api_core import future -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import operation -from google.api_core import operation_async # type: ignore -from google.api_core import operations_v1 -from google.api_core import path_template -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.cloud.spanner_admin_database_v1.services.database_admin import DatabaseAdminAsyncClient -from google.cloud.spanner_admin_database_v1.services.database_admin import DatabaseAdminClient -from google.cloud.spanner_admin_database_v1.services.database_admin import pagers -from google.cloud.spanner_admin_database_v1.services.database_admin import transports -from google.cloud.spanner_admin_database_v1.types import backup -from google.cloud.spanner_admin_database_v1.types import backup as gsad_backup -from google.cloud.spanner_admin_database_v1.types import common -from google.cloud.spanner_admin_database_v1.types import spanner_database_admin -from google.iam.v1 import iam_policy_pb2 # type: ignore -from google.iam.v1 import options_pb2 # type: ignore -from google.iam.v1 import policy_pb2 # type: ignore -from google.longrunning import operations_pb2 -from google.longrunning import operations_pb2 # type: ignore -from google.oauth2 import service_account -from google.protobuf import any_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.rpc import status_pb2 # type: ignore -from google.type import expr_pb2 # type: ignore -import google.auth - - -def client_cert_source_callback(): - return b"cert bytes", b"key bytes" - - -# If default endpoint is localhost, then default mtls endpoint will be the same. -# This method modifies the default endpoint so the client can produce a different -# mtls endpoint for endpoint testing purposes. -def modify_default_endpoint(client): - return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT - - -def test__get_default_mtls_endpoint(): - api_endpoint = "example.googleapis.com" - api_mtls_endpoint = "example.mtls.googleapis.com" - sandbox_endpoint = "example.sandbox.googleapis.com" - sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" - non_googleapi = "api.example.com" - - assert DatabaseAdminClient._get_default_mtls_endpoint(None) is None - assert DatabaseAdminClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert DatabaseAdminClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert DatabaseAdminClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert DatabaseAdminClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert DatabaseAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - - -@pytest.mark.parametrize("client_class,transport_name", [ - (DatabaseAdminClient, "grpc"), - (DatabaseAdminAsyncClient, "grpc_asyncio"), - (DatabaseAdminClient, "rest"), -]) -def test_database_admin_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: - factory.return_value = creds - info = {"valid": True} - client = client_class.from_service_account_info(info, transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == ( - 'spanner.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else - 'https://spanner.googleapis.com' - ) - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.DatabaseAdminGrpcTransport, "grpc"), - (transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio"), - (transports.DatabaseAdminRestTransport, "rest"), -]) -def test_database_admin_client_service_account_always_use_jwt(transport_class, transport_name): - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - transport = transport_class(credentials=creds, always_use_jwt_access=True) - use_jwt.assert_called_once_with(True) - - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - transport = transport_class(credentials=creds, always_use_jwt_access=False) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("client_class,transport_name", [ - (DatabaseAdminClient, "grpc"), - (DatabaseAdminAsyncClient, "grpc_asyncio"), - (DatabaseAdminClient, "rest"), -]) -def test_database_admin_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: - factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == ( - 'spanner.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else - 'https://spanner.googleapis.com' - ) - - -def test_database_admin_client_get_transport_class(): - transport = DatabaseAdminClient.get_transport_class() - available_transports = [ - transports.DatabaseAdminGrpcTransport, - transports.DatabaseAdminRestTransport, - ] - assert transport in available_transports - - transport = DatabaseAdminClient.get_transport_class("grpc") - assert transport == transports.DatabaseAdminGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (DatabaseAdminClient, transports.DatabaseAdminGrpcTransport, "grpc"), - (DatabaseAdminAsyncClient, transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio"), - (DatabaseAdminClient, transports.DatabaseAdminRestTransport, "rest"), -]) -@mock.patch.object(DatabaseAdminClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatabaseAdminClient)) -@mock.patch.object(DatabaseAdminAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatabaseAdminAsyncClient)) -def test_database_admin_client_client_options(client_class, transport_class, transport_name): - # Check that if channel is provided we won't create a new one. - with mock.patch.object(DatabaseAdminClient, 'get_transport_class') as gtc: - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ) - client = client_class(transport=transport) - gtc.assert_not_called() - - # Check that if channel is provided via str we will create a new one. - with mock.patch.object(DatabaseAdminClient, 'get_transport_class') as gtc: - client = client_class(transport=transport_name) - gtc.assert_called() - - # Check the case api_endpoint is provided. - options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name, client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_MTLS_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has - # unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): - with pytest.raises(MutualTLSChannelError): - client = client_class(transport=transport_name) - - # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): - with pytest.raises(ValueError): - client = client_class(transport=transport_name) - - # Check the case quota_project_id is provided - options = client_options.ClientOptions(quota_project_id="octopus") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id="octopus", - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - # Check the case api_endpoint is provided - options = client_options.ClientOptions(api_audience="https://language.googleapis.com") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience="https://language.googleapis.com" - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (DatabaseAdminClient, transports.DatabaseAdminGrpcTransport, "grpc", "true"), - (DatabaseAdminAsyncClient, transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (DatabaseAdminClient, transports.DatabaseAdminGrpcTransport, "grpc", "false"), - (DatabaseAdminAsyncClient, transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio", "false"), - (DatabaseAdminClient, transports.DatabaseAdminRestTransport, "rest", "true"), - (DatabaseAdminClient, transports.DatabaseAdminRestTransport, "rest", "false"), -]) -@mock.patch.object(DatabaseAdminClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatabaseAdminClient)) -@mock.patch.object(DatabaseAdminAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatabaseAdminAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_database_admin_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): - # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default - # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. - - # Check the case client_cert_source is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - - if use_client_cert_env == "false": - expected_client_cert_source = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_client_cert_source = client_cert_source_callback - expected_host = client.DEFAULT_MTLS_ENDPOINT - - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case ADC client cert is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): - if use_client_cert_env == "false": - expected_host = client.DEFAULT_ENDPOINT - expected_client_cert_source = None - else: - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_client_cert_source = client_cert_source_callback - - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - -@pytest.mark.parametrize("client_class", [ - DatabaseAdminClient, DatabaseAdminAsyncClient -]) -@mock.patch.object(DatabaseAdminClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatabaseAdminClient)) -@mock.patch.object(DatabaseAdminAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatabaseAdminAsyncClient)) -def test_database_admin_client_get_mtls_endpoint_and_cert_source(client_class): - mock_client_cert_source = mock.Mock() - - # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - mock_api_endpoint = "foo" - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) - assert api_endpoint == mock_api_endpoint - assert cert_source == mock_client_cert_source - - # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): - mock_client_cert_source = mock.Mock() - mock_api_endpoint = "foo" - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) - assert api_endpoint == mock_api_endpoint - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_client_cert_source): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT - assert cert_source == mock_client_cert_source - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (DatabaseAdminClient, transports.DatabaseAdminGrpcTransport, "grpc"), - (DatabaseAdminAsyncClient, transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio"), - (DatabaseAdminClient, transports.DatabaseAdminRestTransport, "rest"), -]) -def test_database_admin_client_client_options_scopes(client_class, transport_class, transport_name): - # Check the case scopes are provided. - options = client_options.ClientOptions( - scopes=["1", "2"], - ) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=["1", "2"], - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ - (DatabaseAdminClient, transports.DatabaseAdminGrpcTransport, "grpc", grpc_helpers), - (DatabaseAdminAsyncClient, transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), - (DatabaseAdminClient, transports.DatabaseAdminRestTransport, "rest", None), -]) -def test_database_admin_client_client_options_credentials_file(client_class, transport_class, transport_name, grpc_helpers): - # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) - - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file="credentials.json", - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - -def test_database_admin_client_client_options_from_dict(): - with mock.patch('google.cloud.spanner_admin_database_v1.services.database_admin.transports.DatabaseAdminGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = DatabaseAdminClient( - client_options={'api_endpoint': 'squid.clam.whelk'} - ) - grpc_transport.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ - (DatabaseAdminClient, transports.DatabaseAdminGrpcTransport, "grpc", grpc_helpers), - (DatabaseAdminAsyncClient, transports.DatabaseAdminGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), -]) -def test_database_admin_client_create_channel_credentials_file(client_class, transport_class, transport_name, grpc_helpers): - # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) - - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file="credentials.json", - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel" - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() - load_creds.return_value = (file_creds, None) - adc.return_value = (creds, None) - client = client_class(client_options=options, transport=transport_name) - create_channel.assert_called_with( - "spanner.googleapis.com:443", - credentials=file_creds, - credentials_file=None, - quota_project_id=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.admin', -), - scopes=None, - default_host="spanner.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.ListDatabasesRequest, - dict, -]) -def test_list_databases(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_databases), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.ListDatabasesResponse( - next_page_token='next_page_token_value', - ) - response = client.list_databases(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.ListDatabasesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListDatabasesPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_databases_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_databases), - '__call__') as call: - client.list_databases() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.ListDatabasesRequest() - -@pytest.mark.asyncio -async def test_list_databases_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.ListDatabasesRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_databases), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabasesResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_databases(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.ListDatabasesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListDatabasesAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_databases_async_from_dict(): - await test_list_databases_async(request_type=dict) - - -def test_list_databases_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.ListDatabasesRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_databases), - '__call__') as call: - call.return_value = spanner_database_admin.ListDatabasesResponse() - client.list_databases(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_list_databases_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.ListDatabasesRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_databases), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabasesResponse()) - await client.list_databases(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_list_databases_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_databases), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.ListDatabasesResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_databases( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - - -def test_list_databases_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_databases( - spanner_database_admin.ListDatabasesRequest(), - parent='parent_value', - ) - -@pytest.mark.asyncio -async def test_list_databases_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_databases), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.ListDatabasesResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabasesResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_databases( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_list_databases_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.list_databases( - spanner_database_admin.ListDatabasesRequest(), - parent='parent_value', - ) - - -def test_list_databases_pager(transport_name: str = "grpc"): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_databases), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - spanner_database_admin.Database(), - spanner_database_admin.Database(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - spanner_database_admin.Database(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_databases(request={}) - - assert pager._metadata == metadata - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, spanner_database_admin.Database) - for i in results) -def test_list_databases_pages(transport_name: str = "grpc"): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_databases), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - spanner_database_admin.Database(), - spanner_database_admin.Database(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - spanner_database_admin.Database(), - ], - ), - RuntimeError, - ) - pages = list(client.list_databases(request={}).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.asyncio -async def test_list_databases_async_pager(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_databases), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - spanner_database_admin.Database(), - spanner_database_admin.Database(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - spanner_database_admin.Database(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_databases(request={},) - assert async_pager.next_page_token == 'abc' - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, spanner_database_admin.Database) - for i in responses) - - -@pytest.mark.asyncio -async def test_list_databases_async_pages(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_databases), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - spanner_database_admin.Database(), - spanner_database_admin.Database(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - spanner_database_admin.Database(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_databases(request={})).pages: # pragma: no branch - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.CreateDatabaseRequest, - dict, -]) -def test_create_database(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.create_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.CreateDatabaseRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_create_database_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_database), - '__call__') as call: - client.create_database() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.CreateDatabaseRequest() - -@pytest.mark.asyncio -async def test_create_database_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.CreateDatabaseRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.create_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.CreateDatabaseRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_create_database_async_from_dict(): - await test_create_database_async(request_type=dict) - - -def test_create_database_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.CreateDatabaseRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_database), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.create_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_create_database_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.CreateDatabaseRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_database), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.create_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_create_database_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_database( - parent='parent_value', - create_statement='create_statement_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - arg = args[0].create_statement - mock_val = 'create_statement_value' - assert arg == mock_val - - -def test_create_database_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_database( - spanner_database_admin.CreateDatabaseRequest(), - parent='parent_value', - create_statement='create_statement_value', - ) - -@pytest.mark.asyncio -async def test_create_database_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_database( - parent='parent_value', - create_statement='create_statement_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - arg = args[0].create_statement - mock_val = 'create_statement_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_create_database_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.create_database( - spanner_database_admin.CreateDatabaseRequest(), - parent='parent_value', - create_statement='create_statement_value', - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.GetDatabaseRequest, - dict, -]) -def test_get_database(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.Database( - name='name_value', - state=spanner_database_admin.Database.State.CREATING, - version_retention_period='version_retention_period_value', - default_leader='default_leader_value', - database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, - enable_drop_protection=True, - reconciling=True, - ) - response = client.get_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.GetDatabaseRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner_database_admin.Database) - assert response.name == 'name_value' - assert response.state == spanner_database_admin.Database.State.CREATING - assert response.version_retention_period == 'version_retention_period_value' - assert response.default_leader == 'default_leader_value' - assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL - assert response.enable_drop_protection is True - assert response.reconciling is True - - -def test_get_database_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_database), - '__call__') as call: - client.get_database() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.GetDatabaseRequest() - -@pytest.mark.asyncio -async def test_get_database_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.GetDatabaseRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.Database( - name='name_value', - state=spanner_database_admin.Database.State.CREATING, - version_retention_period='version_retention_period_value', - default_leader='default_leader_value', - database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, - enable_drop_protection=True, - reconciling=True, - )) - response = await client.get_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.GetDatabaseRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner_database_admin.Database) - assert response.name == 'name_value' - assert response.state == spanner_database_admin.Database.State.CREATING - assert response.version_retention_period == 'version_retention_period_value' - assert response.default_leader == 'default_leader_value' - assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL - assert response.enable_drop_protection is True - assert response.reconciling is True - - -@pytest.mark.asyncio -async def test_get_database_async_from_dict(): - await test_get_database_async(request_type=dict) - - -def test_get_database_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.GetDatabaseRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_database), - '__call__') as call: - call.return_value = spanner_database_admin.Database() - client.get_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_get_database_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.GetDatabaseRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_database), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.Database()) - await client.get_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -def test_get_database_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.Database() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_database( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - - -def test_get_database_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_database( - spanner_database_admin.GetDatabaseRequest(), - name='name_value', - ) - -@pytest.mark.asyncio -async def test_get_database_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.Database() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.Database()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_database( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_get_database_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.get_database( - spanner_database_admin.GetDatabaseRequest(), - name='name_value', - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.UpdateDatabaseRequest, - dict, -]) -def test_update_database(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.update_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.UpdateDatabaseRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_update_database_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_database), - '__call__') as call: - client.update_database() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.UpdateDatabaseRequest() - -@pytest.mark.asyncio -async def test_update_database_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.UpdateDatabaseRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.update_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.UpdateDatabaseRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_update_database_async_from_dict(): - await test_update_database_async(request_type=dict) - - -def test_update_database_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.UpdateDatabaseRequest() - - request.database.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_database), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.update_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'database.name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_update_database_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.UpdateDatabaseRequest() - - request.database.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_database), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.update_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'database.name=name_value', - ) in kw['metadata'] - - -def test_update_database_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.update_database( - database=spanner_database_admin.Database(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].database - mock_val = spanner_database_admin.Database(name='name_value') - assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) - assert arg == mock_val - - -def test_update_database_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_database( - spanner_database_admin.UpdateDatabaseRequest(), - database=spanner_database_admin.Database(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - -@pytest.mark.asyncio -async def test_update_database_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.update_database( - database=spanner_database_admin.Database(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].database - mock_val = spanner_database_admin.Database(name='name_value') - assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) - assert arg == mock_val - -@pytest.mark.asyncio -async def test_update_database_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.update_database( - spanner_database_admin.UpdateDatabaseRequest(), - database=spanner_database_admin.Database(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.UpdateDatabaseDdlRequest, - dict, -]) -def test_update_database_ddl(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_database_ddl), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.update_database_ddl(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.UpdateDatabaseDdlRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_update_database_ddl_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_database_ddl), - '__call__') as call: - client.update_database_ddl() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.UpdateDatabaseDdlRequest() - -@pytest.mark.asyncio -async def test_update_database_ddl_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.UpdateDatabaseDdlRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_database_ddl), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.update_database_ddl(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.UpdateDatabaseDdlRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_update_database_ddl_async_from_dict(): - await test_update_database_ddl_async(request_type=dict) - - -def test_update_database_ddl_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.UpdateDatabaseDdlRequest() - - request.database = 'database_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_database_ddl), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.update_database_ddl(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'database=database_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_update_database_ddl_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.UpdateDatabaseDdlRequest() - - request.database = 'database_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_database_ddl), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.update_database_ddl(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'database=database_value', - ) in kw['metadata'] - - -def test_update_database_ddl_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_database_ddl), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.update_database_ddl( - database='database_value', - statements=['statements_value'], - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].database - mock_val = 'database_value' - assert arg == mock_val - arg = args[0].statements - mock_val = ['statements_value'] - assert arg == mock_val - - -def test_update_database_ddl_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_database_ddl( - spanner_database_admin.UpdateDatabaseDdlRequest(), - database='database_value', - statements=['statements_value'], - ) - -@pytest.mark.asyncio -async def test_update_database_ddl_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_database_ddl), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.update_database_ddl( - database='database_value', - statements=['statements_value'], - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].database - mock_val = 'database_value' - assert arg == mock_val - arg = args[0].statements - mock_val = ['statements_value'] - assert arg == mock_val - -@pytest.mark.asyncio -async def test_update_database_ddl_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.update_database_ddl( - spanner_database_admin.UpdateDatabaseDdlRequest(), - database='database_value', - statements=['statements_value'], - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.DropDatabaseRequest, - dict, -]) -def test_drop_database(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.drop_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.drop_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.DropDatabaseRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_drop_database_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.drop_database), - '__call__') as call: - client.drop_database() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.DropDatabaseRequest() - -@pytest.mark.asyncio -async def test_drop_database_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.DropDatabaseRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.drop_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.drop_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.DropDatabaseRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_drop_database_async_from_dict(): - await test_drop_database_async(request_type=dict) - - -def test_drop_database_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.DropDatabaseRequest() - - request.database = 'database_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.drop_database), - '__call__') as call: - call.return_value = None - client.drop_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'database=database_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_drop_database_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.DropDatabaseRequest() - - request.database = 'database_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.drop_database), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.drop_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'database=database_value', - ) in kw['metadata'] - - -def test_drop_database_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.drop_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.drop_database( - database='database_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].database - mock_val = 'database_value' - assert arg == mock_val - - -def test_drop_database_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.drop_database( - spanner_database_admin.DropDatabaseRequest(), - database='database_value', - ) - -@pytest.mark.asyncio -async def test_drop_database_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.drop_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.drop_database( - database='database_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].database - mock_val = 'database_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_drop_database_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.drop_database( - spanner_database_admin.DropDatabaseRequest(), - database='database_value', - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.GetDatabaseDdlRequest, - dict, -]) -def test_get_database_ddl(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_database_ddl), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.GetDatabaseDdlResponse( - statements=['statements_value'], - ) - response = client.get_database_ddl(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.GetDatabaseDdlRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner_database_admin.GetDatabaseDdlResponse) - assert response.statements == ['statements_value'] - - -def test_get_database_ddl_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_database_ddl), - '__call__') as call: - client.get_database_ddl() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.GetDatabaseDdlRequest() - -@pytest.mark.asyncio -async def test_get_database_ddl_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.GetDatabaseDdlRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_database_ddl), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.GetDatabaseDdlResponse( - statements=['statements_value'], - )) - response = await client.get_database_ddl(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.GetDatabaseDdlRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner_database_admin.GetDatabaseDdlResponse) - assert response.statements == ['statements_value'] - - -@pytest.mark.asyncio -async def test_get_database_ddl_async_from_dict(): - await test_get_database_ddl_async(request_type=dict) - - -def test_get_database_ddl_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.GetDatabaseDdlRequest() - - request.database = 'database_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_database_ddl), - '__call__') as call: - call.return_value = spanner_database_admin.GetDatabaseDdlResponse() - client.get_database_ddl(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'database=database_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_get_database_ddl_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.GetDatabaseDdlRequest() - - request.database = 'database_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_database_ddl), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.GetDatabaseDdlResponse()) - await client.get_database_ddl(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'database=database_value', - ) in kw['metadata'] - - -def test_get_database_ddl_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_database_ddl), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.GetDatabaseDdlResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_database_ddl( - database='database_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].database - mock_val = 'database_value' - assert arg == mock_val - - -def test_get_database_ddl_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_database_ddl( - spanner_database_admin.GetDatabaseDdlRequest(), - database='database_value', - ) - -@pytest.mark.asyncio -async def test_get_database_ddl_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_database_ddl), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.GetDatabaseDdlResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.GetDatabaseDdlResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_database_ddl( - database='database_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].database - mock_val = 'database_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_get_database_ddl_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.get_database_ddl( - spanner_database_admin.GetDatabaseDdlRequest(), - database='database_value', - ) - - -@pytest.mark.parametrize("request_type", [ - iam_policy_pb2.SetIamPolicyRequest, - dict, -]) -def test_set_iam_policy(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy( - version=774, - etag=b'etag_blob', - ) - response = client.set_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.SetIamPolicyRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, policy_pb2.Policy) - assert response.version == 774 - assert response.etag == b'etag_blob' - - -def test_set_iam_policy_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - client.set_iam_policy() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.SetIamPolicyRequest() - -@pytest.mark.asyncio -async def test_set_iam_policy_async(transport: str = 'grpc_asyncio', request_type=iam_policy_pb2.SetIamPolicyRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy( - version=774, - etag=b'etag_blob', - )) - response = await client.set_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.SetIamPolicyRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, policy_pb2.Policy) - assert response.version == 774 - assert response.etag == b'etag_blob' - - -@pytest.mark.asyncio -async def test_set_iam_policy_async_from_dict(): - await test_set_iam_policy_async(request_type=dict) - - -def test_set_iam_policy_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = iam_policy_pb2.SetIamPolicyRequest() - - request.resource = 'resource_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - call.return_value = policy_pb2.Policy() - client.set_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'resource=resource_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_set_iam_policy_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = iam_policy_pb2.SetIamPolicyRequest() - - request.resource = 'resource_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - await client.set_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'resource=resource_value', - ) in kw['metadata'] - -def test_set_iam_policy_from_dict_foreign(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() - response = client.set_iam_policy(request={ - 'resource': 'resource_value', - 'policy': policy_pb2.Policy(version=774), - 'update_mask': field_mask_pb2.FieldMask(paths=['paths_value']), - } - ) - call.assert_called() - - -def test_set_iam_policy_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.set_iam_policy( - resource='resource_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].resource - mock_val = 'resource_value' - assert arg == mock_val - - -def test_set_iam_policy_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.set_iam_policy( - iam_policy_pb2.SetIamPolicyRequest(), - resource='resource_value', - ) - -@pytest.mark.asyncio -async def test_set_iam_policy_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.set_iam_policy( - resource='resource_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].resource - mock_val = 'resource_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_set_iam_policy_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.set_iam_policy( - iam_policy_pb2.SetIamPolicyRequest(), - resource='resource_value', - ) - - -@pytest.mark.parametrize("request_type", [ - iam_policy_pb2.GetIamPolicyRequest, - dict, -]) -def test_get_iam_policy(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy( - version=774, - etag=b'etag_blob', - ) - response = client.get_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.GetIamPolicyRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, policy_pb2.Policy) - assert response.version == 774 - assert response.etag == b'etag_blob' - - -def test_get_iam_policy_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - client.get_iam_policy() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.GetIamPolicyRequest() - -@pytest.mark.asyncio -async def test_get_iam_policy_async(transport: str = 'grpc_asyncio', request_type=iam_policy_pb2.GetIamPolicyRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy( - version=774, - etag=b'etag_blob', - )) - response = await client.get_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.GetIamPolicyRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, policy_pb2.Policy) - assert response.version == 774 - assert response.etag == b'etag_blob' - - -@pytest.mark.asyncio -async def test_get_iam_policy_async_from_dict(): - await test_get_iam_policy_async(request_type=dict) - - -def test_get_iam_policy_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = iam_policy_pb2.GetIamPolicyRequest() - - request.resource = 'resource_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - call.return_value = policy_pb2.Policy() - client.get_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'resource=resource_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_get_iam_policy_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = iam_policy_pb2.GetIamPolicyRequest() - - request.resource = 'resource_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - await client.get_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'resource=resource_value', - ) in kw['metadata'] - -def test_get_iam_policy_from_dict_foreign(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() - response = client.get_iam_policy(request={ - 'resource': 'resource_value', - 'options': options_pb2.GetPolicyOptions(requested_policy_version=2598), - } - ) - call.assert_called() - - -def test_get_iam_policy_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_iam_policy( - resource='resource_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].resource - mock_val = 'resource_value' - assert arg == mock_val - - -def test_get_iam_policy_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_iam_policy( - iam_policy_pb2.GetIamPolicyRequest(), - resource='resource_value', - ) - -@pytest.mark.asyncio -async def test_get_iam_policy_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_iam_policy( - resource='resource_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].resource - mock_val = 'resource_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_get_iam_policy_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.get_iam_policy( - iam_policy_pb2.GetIamPolicyRequest(), - resource='resource_value', - ) - - -@pytest.mark.parametrize("request_type", [ - iam_policy_pb2.TestIamPermissionsRequest, - dict, -]) -def test_test_iam_permissions(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = iam_policy_pb2.TestIamPermissionsResponse( - permissions=['permissions_value'], - ) - response = client.test_iam_permissions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) - assert response.permissions == ['permissions_value'] - - -def test_test_iam_permissions_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - client.test_iam_permissions() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() - -@pytest.mark.asyncio -async def test_test_iam_permissions_async(transport: str = 'grpc_asyncio', request_type=iam_policy_pb2.TestIamPermissionsRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(iam_policy_pb2.TestIamPermissionsResponse( - permissions=['permissions_value'], - )) - response = await client.test_iam_permissions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) - assert response.permissions == ['permissions_value'] - - -@pytest.mark.asyncio -async def test_test_iam_permissions_async_from_dict(): - await test_test_iam_permissions_async(request_type=dict) - - -def test_test_iam_permissions_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = iam_policy_pb2.TestIamPermissionsRequest() - - request.resource = 'resource_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - call.return_value = iam_policy_pb2.TestIamPermissionsResponse() - client.test_iam_permissions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'resource=resource_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_test_iam_permissions_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = iam_policy_pb2.TestIamPermissionsRequest() - - request.resource = 'resource_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(iam_policy_pb2.TestIamPermissionsResponse()) - await client.test_iam_permissions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'resource=resource_value', - ) in kw['metadata'] - -def test_test_iam_permissions_from_dict_foreign(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = iam_policy_pb2.TestIamPermissionsResponse() - response = client.test_iam_permissions(request={ - 'resource': 'resource_value', - 'permissions': ['permissions_value'], - } - ) - call.assert_called() - - -def test_test_iam_permissions_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = iam_policy_pb2.TestIamPermissionsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.test_iam_permissions( - resource='resource_value', - permissions=['permissions_value'], - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].resource - mock_val = 'resource_value' - assert arg == mock_val - arg = args[0].permissions - mock_val = ['permissions_value'] - assert arg == mock_val - - -def test_test_iam_permissions_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.test_iam_permissions( - iam_policy_pb2.TestIamPermissionsRequest(), - resource='resource_value', - permissions=['permissions_value'], - ) - -@pytest.mark.asyncio -async def test_test_iam_permissions_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = iam_policy_pb2.TestIamPermissionsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(iam_policy_pb2.TestIamPermissionsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.test_iam_permissions( - resource='resource_value', - permissions=['permissions_value'], - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].resource - mock_val = 'resource_value' - assert arg == mock_val - arg = args[0].permissions - mock_val = ['permissions_value'] - assert arg == mock_val - -@pytest.mark.asyncio -async def test_test_iam_permissions_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.test_iam_permissions( - iam_policy_pb2.TestIamPermissionsRequest(), - resource='resource_value', - permissions=['permissions_value'], - ) - - -@pytest.mark.parametrize("request_type", [ - gsad_backup.CreateBackupRequest, - dict, -]) -def test_create_backup(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.create_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == gsad_backup.CreateBackupRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_create_backup_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_backup), - '__call__') as call: - client.create_backup() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == gsad_backup.CreateBackupRequest() - -@pytest.mark.asyncio -async def test_create_backup_async(transport: str = 'grpc_asyncio', request_type=gsad_backup.CreateBackupRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.create_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == gsad_backup.CreateBackupRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_create_backup_async_from_dict(): - await test_create_backup_async(request_type=dict) - - -def test_create_backup_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = gsad_backup.CreateBackupRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_backup), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.create_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_create_backup_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = gsad_backup.CreateBackupRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_backup), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.create_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_create_backup_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_backup( - parent='parent_value', - backup=gsad_backup.Backup(database='database_value'), - backup_id='backup_id_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - arg = args[0].backup - mock_val = gsad_backup.Backup(database='database_value') - assert arg == mock_val - arg = args[0].backup_id - mock_val = 'backup_id_value' - assert arg == mock_val - - -def test_create_backup_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_backup( - gsad_backup.CreateBackupRequest(), - parent='parent_value', - backup=gsad_backup.Backup(database='database_value'), - backup_id='backup_id_value', - ) - -@pytest.mark.asyncio -async def test_create_backup_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_backup( - parent='parent_value', - backup=gsad_backup.Backup(database='database_value'), - backup_id='backup_id_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - arg = args[0].backup - mock_val = gsad_backup.Backup(database='database_value') - assert arg == mock_val - arg = args[0].backup_id - mock_val = 'backup_id_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_create_backup_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.create_backup( - gsad_backup.CreateBackupRequest(), - parent='parent_value', - backup=gsad_backup.Backup(database='database_value'), - backup_id='backup_id_value', - ) - - -@pytest.mark.parametrize("request_type", [ - backup.CopyBackupRequest, - dict, -]) -def test_copy_backup(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.copy_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.copy_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == backup.CopyBackupRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_copy_backup_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.copy_backup), - '__call__') as call: - client.copy_backup() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == backup.CopyBackupRequest() - -@pytest.mark.asyncio -async def test_copy_backup_async(transport: str = 'grpc_asyncio', request_type=backup.CopyBackupRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.copy_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.copy_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == backup.CopyBackupRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_copy_backup_async_from_dict(): - await test_copy_backup_async(request_type=dict) - - -def test_copy_backup_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = backup.CopyBackupRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.copy_backup), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.copy_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_copy_backup_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = backup.CopyBackupRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.copy_backup), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.copy_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_copy_backup_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.copy_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.copy_backup( - parent='parent_value', - backup_id='backup_id_value', - source_backup='source_backup_value', - expire_time=timestamp_pb2.Timestamp(seconds=751), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - arg = args[0].backup_id - mock_val = 'backup_id_value' - assert arg == mock_val - arg = args[0].source_backup - mock_val = 'source_backup_value' - assert arg == mock_val - assert TimestampRule().to_proto(args[0].expire_time) == timestamp_pb2.Timestamp(seconds=751) - - -def test_copy_backup_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.copy_backup( - backup.CopyBackupRequest(), - parent='parent_value', - backup_id='backup_id_value', - source_backup='source_backup_value', - expire_time=timestamp_pb2.Timestamp(seconds=751), - ) - -@pytest.mark.asyncio -async def test_copy_backup_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.copy_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.copy_backup( - parent='parent_value', - backup_id='backup_id_value', - source_backup='source_backup_value', - expire_time=timestamp_pb2.Timestamp(seconds=751), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - arg = args[0].backup_id - mock_val = 'backup_id_value' - assert arg == mock_val - arg = args[0].source_backup - mock_val = 'source_backup_value' - assert arg == mock_val - assert TimestampRule().to_proto(args[0].expire_time) == timestamp_pb2.Timestamp(seconds=751) - -@pytest.mark.asyncio -async def test_copy_backup_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.copy_backup( - backup.CopyBackupRequest(), - parent='parent_value', - backup_id='backup_id_value', - source_backup='source_backup_value', - expire_time=timestamp_pb2.Timestamp(seconds=751), - ) - - -@pytest.mark.parametrize("request_type", [ - backup.GetBackupRequest, - dict, -]) -def test_get_backup(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = backup.Backup( - database='database_value', - name='name_value', - size_bytes=1089, - state=backup.Backup.State.CREATING, - referencing_databases=['referencing_databases_value'], - database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, - referencing_backups=['referencing_backups_value'], - ) - response = client.get_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == backup.GetBackupRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, backup.Backup) - assert response.database == 'database_value' - assert response.name == 'name_value' - assert response.size_bytes == 1089 - assert response.state == backup.Backup.State.CREATING - assert response.referencing_databases == ['referencing_databases_value'] - assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL - assert response.referencing_backups == ['referencing_backups_value'] - - -def test_get_backup_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_backup), - '__call__') as call: - client.get_backup() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == backup.GetBackupRequest() - -@pytest.mark.asyncio -async def test_get_backup_async(transport: str = 'grpc_asyncio', request_type=backup.GetBackupRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(backup.Backup( - database='database_value', - name='name_value', - size_bytes=1089, - state=backup.Backup.State.CREATING, - referencing_databases=['referencing_databases_value'], - database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, - referencing_backups=['referencing_backups_value'], - )) - response = await client.get_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == backup.GetBackupRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, backup.Backup) - assert response.database == 'database_value' - assert response.name == 'name_value' - assert response.size_bytes == 1089 - assert response.state == backup.Backup.State.CREATING - assert response.referencing_databases == ['referencing_databases_value'] - assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL - assert response.referencing_backups == ['referencing_backups_value'] - - -@pytest.mark.asyncio -async def test_get_backup_async_from_dict(): - await test_get_backup_async(request_type=dict) - - -def test_get_backup_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = backup.GetBackupRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_backup), - '__call__') as call: - call.return_value = backup.Backup() - client.get_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_get_backup_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = backup.GetBackupRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_backup), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(backup.Backup()) - await client.get_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -def test_get_backup_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = backup.Backup() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_backup( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - - -def test_get_backup_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_backup( - backup.GetBackupRequest(), - name='name_value', - ) - -@pytest.mark.asyncio -async def test_get_backup_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = backup.Backup() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(backup.Backup()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_backup( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_get_backup_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.get_backup( - backup.GetBackupRequest(), - name='name_value', - ) - - -@pytest.mark.parametrize("request_type", [ - gsad_backup.UpdateBackupRequest, - dict, -]) -def test_update_backup(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = gsad_backup.Backup( - database='database_value', - name='name_value', - size_bytes=1089, - state=gsad_backup.Backup.State.CREATING, - referencing_databases=['referencing_databases_value'], - database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, - referencing_backups=['referencing_backups_value'], - ) - response = client.update_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == gsad_backup.UpdateBackupRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, gsad_backup.Backup) - assert response.database == 'database_value' - assert response.name == 'name_value' - assert response.size_bytes == 1089 - assert response.state == gsad_backup.Backup.State.CREATING - assert response.referencing_databases == ['referencing_databases_value'] - assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL - assert response.referencing_backups == ['referencing_backups_value'] - - -def test_update_backup_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_backup), - '__call__') as call: - client.update_backup() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == gsad_backup.UpdateBackupRequest() - -@pytest.mark.asyncio -async def test_update_backup_async(transport: str = 'grpc_asyncio', request_type=gsad_backup.UpdateBackupRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(gsad_backup.Backup( - database='database_value', - name='name_value', - size_bytes=1089, - state=gsad_backup.Backup.State.CREATING, - referencing_databases=['referencing_databases_value'], - database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, - referencing_backups=['referencing_backups_value'], - )) - response = await client.update_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == gsad_backup.UpdateBackupRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, gsad_backup.Backup) - assert response.database == 'database_value' - assert response.name == 'name_value' - assert response.size_bytes == 1089 - assert response.state == gsad_backup.Backup.State.CREATING - assert response.referencing_databases == ['referencing_databases_value'] - assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL - assert response.referencing_backups == ['referencing_backups_value'] - - -@pytest.mark.asyncio -async def test_update_backup_async_from_dict(): - await test_update_backup_async(request_type=dict) - - -def test_update_backup_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = gsad_backup.UpdateBackupRequest() - - request.backup.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_backup), - '__call__') as call: - call.return_value = gsad_backup.Backup() - client.update_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'backup.name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_update_backup_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = gsad_backup.UpdateBackupRequest() - - request.backup.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_backup), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gsad_backup.Backup()) - await client.update_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'backup.name=name_value', - ) in kw['metadata'] - - -def test_update_backup_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = gsad_backup.Backup() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.update_backup( - backup=gsad_backup.Backup(database='database_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].backup - mock_val = gsad_backup.Backup(database='database_value') - assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) - assert arg == mock_val - - -def test_update_backup_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_backup( - gsad_backup.UpdateBackupRequest(), - backup=gsad_backup.Backup(database='database_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - -@pytest.mark.asyncio -async def test_update_backup_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = gsad_backup.Backup() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gsad_backup.Backup()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.update_backup( - backup=gsad_backup.Backup(database='database_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].backup - mock_val = gsad_backup.Backup(database='database_value') - assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) - assert arg == mock_val - -@pytest.mark.asyncio -async def test_update_backup_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.update_backup( - gsad_backup.UpdateBackupRequest(), - backup=gsad_backup.Backup(database='database_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -@pytest.mark.parametrize("request_type", [ - backup.DeleteBackupRequest, - dict, -]) -def test_delete_backup(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == backup.DeleteBackupRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_backup_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_backup), - '__call__') as call: - client.delete_backup() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == backup.DeleteBackupRequest() - -@pytest.mark.asyncio -async def test_delete_backup_async(transport: str = 'grpc_asyncio', request_type=backup.DeleteBackupRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == backup.DeleteBackupRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_backup_async_from_dict(): - await test_delete_backup_async(request_type=dict) - - -def test_delete_backup_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = backup.DeleteBackupRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_backup), - '__call__') as call: - call.return_value = None - client.delete_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_delete_backup_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = backup.DeleteBackupRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_backup), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_backup(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -def test_delete_backup_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_backup( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - - -def test_delete_backup_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_backup( - backup.DeleteBackupRequest(), - name='name_value', - ) - -@pytest.mark.asyncio -async def test_delete_backup_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_backup), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_backup( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_delete_backup_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.delete_backup( - backup.DeleteBackupRequest(), - name='name_value', - ) - - -@pytest.mark.parametrize("request_type", [ - backup.ListBackupsRequest, - dict, -]) -def test_list_backups(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backups), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = backup.ListBackupsResponse( - next_page_token='next_page_token_value', - ) - response = client.list_backups(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == backup.ListBackupsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListBackupsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_backups_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backups), - '__call__') as call: - client.list_backups() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == backup.ListBackupsRequest() - -@pytest.mark.asyncio -async def test_list_backups_async(transport: str = 'grpc_asyncio', request_type=backup.ListBackupsRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backups), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(backup.ListBackupsResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_backups(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == backup.ListBackupsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListBackupsAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_backups_async_from_dict(): - await test_list_backups_async(request_type=dict) - - -def test_list_backups_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = backup.ListBackupsRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backups), - '__call__') as call: - call.return_value = backup.ListBackupsResponse() - client.list_backups(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_list_backups_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = backup.ListBackupsRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backups), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(backup.ListBackupsResponse()) - await client.list_backups(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_list_backups_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backups), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = backup.ListBackupsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_backups( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - - -def test_list_backups_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_backups( - backup.ListBackupsRequest(), - parent='parent_value', - ) - -@pytest.mark.asyncio -async def test_list_backups_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backups), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = backup.ListBackupsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(backup.ListBackupsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_backups( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_list_backups_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.list_backups( - backup.ListBackupsRequest(), - parent='parent_value', - ) - - -def test_list_backups_pager(transport_name: str = "grpc"): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backups), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - backup.Backup(), - backup.Backup(), - ], - next_page_token='abc', - ), - backup.ListBackupsResponse( - backups=[], - next_page_token='def', - ), - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - ], - next_page_token='ghi', - ), - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - backup.Backup(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_backups(request={}) - - assert pager._metadata == metadata - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, backup.Backup) - for i in results) -def test_list_backups_pages(transport_name: str = "grpc"): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backups), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - backup.Backup(), - backup.Backup(), - ], - next_page_token='abc', - ), - backup.ListBackupsResponse( - backups=[], - next_page_token='def', - ), - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - ], - next_page_token='ghi', - ), - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - backup.Backup(), - ], - ), - RuntimeError, - ) - pages = list(client.list_backups(request={}).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.asyncio -async def test_list_backups_async_pager(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backups), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - backup.Backup(), - backup.Backup(), - ], - next_page_token='abc', - ), - backup.ListBackupsResponse( - backups=[], - next_page_token='def', - ), - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - ], - next_page_token='ghi', - ), - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - backup.Backup(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_backups(request={},) - assert async_pager.next_page_token == 'abc' - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, backup.Backup) - for i in responses) - - -@pytest.mark.asyncio -async def test_list_backups_async_pages(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backups), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - backup.Backup(), - backup.Backup(), - ], - next_page_token='abc', - ), - backup.ListBackupsResponse( - backups=[], - next_page_token='def', - ), - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - ], - next_page_token='ghi', - ), - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - backup.Backup(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_backups(request={})).pages: # pragma: no branch - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.RestoreDatabaseRequest, - dict, -]) -def test_restore_database(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.restore_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.restore_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.RestoreDatabaseRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_restore_database_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.restore_database), - '__call__') as call: - client.restore_database() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.RestoreDatabaseRequest() - -@pytest.mark.asyncio -async def test_restore_database_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.RestoreDatabaseRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.restore_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.restore_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.RestoreDatabaseRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_restore_database_async_from_dict(): - await test_restore_database_async(request_type=dict) - - -def test_restore_database_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.RestoreDatabaseRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.restore_database), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.restore_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_restore_database_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.RestoreDatabaseRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.restore_database), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.restore_database(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_restore_database_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.restore_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.restore_database( - parent='parent_value', - database_id='database_id_value', - backup='backup_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - arg = args[0].database_id - mock_val = 'database_id_value' - assert arg == mock_val - assert args[0].backup == 'backup_value' - - -def test_restore_database_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.restore_database( - spanner_database_admin.RestoreDatabaseRequest(), - parent='parent_value', - database_id='database_id_value', - backup='backup_value', - ) - -@pytest.mark.asyncio -async def test_restore_database_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.restore_database), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.restore_database( - parent='parent_value', - database_id='database_id_value', - backup='backup_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - arg = args[0].database_id - mock_val = 'database_id_value' - assert arg == mock_val - assert args[0].backup == 'backup_value' - -@pytest.mark.asyncio -async def test_restore_database_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.restore_database( - spanner_database_admin.RestoreDatabaseRequest(), - parent='parent_value', - database_id='database_id_value', - backup='backup_value', - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.ListDatabaseOperationsRequest, - dict, -]) -def test_list_database_operations(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_operations), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.ListDatabaseOperationsResponse( - next_page_token='next_page_token_value', - ) - response = client.list_database_operations(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.ListDatabaseOperationsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListDatabaseOperationsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_database_operations_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_operations), - '__call__') as call: - client.list_database_operations() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.ListDatabaseOperationsRequest() - -@pytest.mark.asyncio -async def test_list_database_operations_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.ListDatabaseOperationsRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_operations), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabaseOperationsResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_database_operations(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.ListDatabaseOperationsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListDatabaseOperationsAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_database_operations_async_from_dict(): - await test_list_database_operations_async(request_type=dict) - - -def test_list_database_operations_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.ListDatabaseOperationsRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_operations), - '__call__') as call: - call.return_value = spanner_database_admin.ListDatabaseOperationsResponse() - client.list_database_operations(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_list_database_operations_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.ListDatabaseOperationsRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_operations), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabaseOperationsResponse()) - await client.list_database_operations(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_list_database_operations_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_operations), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.ListDatabaseOperationsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_database_operations( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - - -def test_list_database_operations_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_database_operations( - spanner_database_admin.ListDatabaseOperationsRequest(), - parent='parent_value', - ) - -@pytest.mark.asyncio -async def test_list_database_operations_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_operations), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.ListDatabaseOperationsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabaseOperationsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_database_operations( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_list_database_operations_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.list_database_operations( - spanner_database_admin.ListDatabaseOperationsRequest(), - parent='parent_value', - ) - - -def test_list_database_operations_pager(transport_name: str = "grpc"): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_operations), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_database_operations(request={}) - - assert pager._metadata == metadata - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, operations_pb2.Operation) - for i in results) -def test_list_database_operations_pages(transport_name: str = "grpc"): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_operations), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - RuntimeError, - ) - pages = list(client.list_database_operations(request={}).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.asyncio -async def test_list_database_operations_async_pager(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_operations), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_database_operations(request={},) - assert async_pager.next_page_token == 'abc' - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, operations_pb2.Operation) - for i in responses) - - -@pytest.mark.asyncio -async def test_list_database_operations_async_pages(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_operations), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_database_operations(request={})).pages: # pragma: no branch - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.parametrize("request_type", [ - backup.ListBackupOperationsRequest, - dict, -]) -def test_list_backup_operations(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backup_operations), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = backup.ListBackupOperationsResponse( - next_page_token='next_page_token_value', - ) - response = client.list_backup_operations(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == backup.ListBackupOperationsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListBackupOperationsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_backup_operations_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backup_operations), - '__call__') as call: - client.list_backup_operations() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == backup.ListBackupOperationsRequest() - -@pytest.mark.asyncio -async def test_list_backup_operations_async(transport: str = 'grpc_asyncio', request_type=backup.ListBackupOperationsRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backup_operations), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(backup.ListBackupOperationsResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_backup_operations(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == backup.ListBackupOperationsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListBackupOperationsAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_backup_operations_async_from_dict(): - await test_list_backup_operations_async(request_type=dict) - - -def test_list_backup_operations_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = backup.ListBackupOperationsRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backup_operations), - '__call__') as call: - call.return_value = backup.ListBackupOperationsResponse() - client.list_backup_operations(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_list_backup_operations_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = backup.ListBackupOperationsRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backup_operations), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(backup.ListBackupOperationsResponse()) - await client.list_backup_operations(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_list_backup_operations_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backup_operations), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = backup.ListBackupOperationsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_backup_operations( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - - -def test_list_backup_operations_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_backup_operations( - backup.ListBackupOperationsRequest(), - parent='parent_value', - ) - -@pytest.mark.asyncio -async def test_list_backup_operations_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backup_operations), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = backup.ListBackupOperationsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(backup.ListBackupOperationsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_backup_operations( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_list_backup_operations_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.list_backup_operations( - backup.ListBackupOperationsRequest(), - parent='parent_value', - ) - - -def test_list_backup_operations_pager(transport_name: str = "grpc"): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backup_operations), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - backup.ListBackupOperationsResponse( - operations=[], - next_page_token='def', - ), - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_backup_operations(request={}) - - assert pager._metadata == metadata - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, operations_pb2.Operation) - for i in results) -def test_list_backup_operations_pages(transport_name: str = "grpc"): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backup_operations), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - backup.ListBackupOperationsResponse( - operations=[], - next_page_token='def', - ), - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - RuntimeError, - ) - pages = list(client.list_backup_operations(request={}).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.asyncio -async def test_list_backup_operations_async_pager(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backup_operations), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - backup.ListBackupOperationsResponse( - operations=[], - next_page_token='def', - ), - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_backup_operations(request={},) - assert async_pager.next_page_token == 'abc' - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, operations_pb2.Operation) - for i in responses) - - -@pytest.mark.asyncio -async def test_list_backup_operations_async_pages(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_backup_operations), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - backup.ListBackupOperationsResponse( - operations=[], - next_page_token='def', - ), - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_backup_operations(request={})).pages: # pragma: no branch - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.ListDatabaseRolesRequest, - dict, -]) -def test_list_database_roles(request_type, transport: str = 'grpc'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_roles), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.ListDatabaseRolesResponse( - next_page_token='next_page_token_value', - ) - response = client.list_database_roles(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.ListDatabaseRolesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListDatabaseRolesPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_database_roles_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_roles), - '__call__') as call: - client.list_database_roles() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.ListDatabaseRolesRequest() - -@pytest.mark.asyncio -async def test_list_database_roles_async(transport: str = 'grpc_asyncio', request_type=spanner_database_admin.ListDatabaseRolesRequest): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_roles), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabaseRolesResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_database_roles(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_database_admin.ListDatabaseRolesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListDatabaseRolesAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_database_roles_async_from_dict(): - await test_list_database_roles_async(request_type=dict) - - -def test_list_database_roles_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.ListDatabaseRolesRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_roles), - '__call__') as call: - call.return_value = spanner_database_admin.ListDatabaseRolesResponse() - client.list_database_roles(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_list_database_roles_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_database_admin.ListDatabaseRolesRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_roles), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabaseRolesResponse()) - await client.list_database_roles(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_list_database_roles_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_roles), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.ListDatabaseRolesResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_database_roles( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - - -def test_list_database_roles_flattened_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_database_roles( - spanner_database_admin.ListDatabaseRolesRequest(), - parent='parent_value', - ) - -@pytest.mark.asyncio -async def test_list_database_roles_flattened_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_roles), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_database_admin.ListDatabaseRolesResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_database_admin.ListDatabaseRolesResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_database_roles( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_list_database_roles_flattened_error_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.list_database_roles( - spanner_database_admin.ListDatabaseRolesRequest(), - parent='parent_value', - ) - - -def test_list_database_roles_pager(transport_name: str = "grpc"): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_roles), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_database_roles(request={}) - - assert pager._metadata == metadata - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, spanner_database_admin.DatabaseRole) - for i in results) -def test_list_database_roles_pages(transport_name: str = "grpc"): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_roles), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - ], - ), - RuntimeError, - ) - pages = list(client.list_database_roles(request={}).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.asyncio -async def test_list_database_roles_async_pager(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_roles), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_database_roles(request={},) - assert async_pager.next_page_token == 'abc' - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, spanner_database_admin.DatabaseRole) - for i in responses) - - -@pytest.mark.asyncio -async def test_list_database_roles_async_pages(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_database_roles), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_database_roles(request={})).pages: # pragma: no branch - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.ListDatabasesRequest, - dict, -]) -def test_list_databases_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.ListDatabasesResponse( - next_page_token='next_page_token_value', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_database_admin.ListDatabasesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.list_databases(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListDatabasesPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_databases_rest_required_fields(request_type=spanner_database_admin.ListDatabasesRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["parent"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_databases._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["parent"] = 'parent_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_databases._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("page_size", "page_token", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.ListDatabasesResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner_database_admin.ListDatabasesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.list_databases(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_list_databases_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.list_databases._get_unset_required_fields({}) - assert set(unset_fields) == (set(("pageSize", "pageToken", )) & set(("parent", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_databases_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_list_databases") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_list_databases") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_database_admin.ListDatabasesRequest.pb(spanner_database_admin.ListDatabasesRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner_database_admin.ListDatabasesResponse.to_json(spanner_database_admin.ListDatabasesResponse()) - - request = spanner_database_admin.ListDatabasesRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner_database_admin.ListDatabasesResponse() - - client.list_databases(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_list_databases_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.ListDatabasesRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.list_databases(request) - - -def test_list_databases_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.ListDatabasesResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'projects/sample1/instances/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_database_admin.ListDatabasesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.list_databases(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/databases" % client.transport._host, args[1]) - - -def test_list_databases_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_databases( - spanner_database_admin.ListDatabasesRequest(), - parent='parent_value', - ) - - -def test_list_databases_rest_pager(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - #with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - spanner_database_admin.Database(), - spanner_database_admin.Database(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabasesResponse( - databases=[ - spanner_database_admin.Database(), - spanner_database_admin.Database(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(spanner_database_admin.ListDatabasesResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode('UTF-8') - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {'parent': 'projects/sample1/instances/sample2'} - - pager = client.list_databases(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, spanner_database_admin.Database) - for i in results) - - pages = list(client.list_databases(request=sample_request).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.CreateDatabaseRequest, - dict, -]) -def test_create_database_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.create_database(request) - - # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" - - -def test_create_database_rest_required_fields(request_type=spanner_database_admin.CreateDatabaseRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["parent"] = "" - request_init["create_statement"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_database._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["parent"] = 'parent_value' - jsonified_request["createStatement"] = 'create_statement_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_database._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - assert "createStatement" in jsonified_request - assert jsonified_request["createStatement"] == 'create_statement_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.create_database(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_create_database_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.create_database._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("parent", "createStatement", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_database_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(operation.Operation, "_set_result_from_operation"), \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_create_database") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_create_database") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_database_admin.CreateDatabaseRequest.pb(spanner_database_admin.CreateDatabaseRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) - - request = spanner_database_admin.CreateDatabaseRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - - client.create_database(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_create_database_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.CreateDatabaseRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.create_database(request) - - -def test_create_database_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'projects/sample1/instances/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - create_statement='create_statement_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.create_database(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/databases" % client.transport._host, args[1]) - - -def test_create_database_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_database( - spanner_database_admin.CreateDatabaseRequest(), - parent='parent_value', - create_statement='create_statement_value', - ) - - -def test_create_database_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.GetDatabaseRequest, - dict, -]) -def test_get_database_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.Database( - name='name_value', - state=spanner_database_admin.Database.State.CREATING, - version_retention_period='version_retention_period_value', - default_leader='default_leader_value', - database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, - enable_drop_protection=True, - reconciling=True, - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_database_admin.Database.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.get_database(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner_database_admin.Database) - assert response.name == 'name_value' - assert response.state == spanner_database_admin.Database.State.CREATING - assert response.version_retention_period == 'version_retention_period_value' - assert response.default_leader == 'default_leader_value' - assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL - assert response.enable_drop_protection is True - assert response.reconciling is True - - -def test_get_database_rest_required_fields(request_type=spanner_database_admin.GetDatabaseRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["name"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_database._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["name"] = 'name_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_database._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == 'name_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.Database() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner_database_admin.Database.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.get_database(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_get_database_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.get_database._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_database_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_get_database") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_get_database") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_database_admin.GetDatabaseRequest.pb(spanner_database_admin.GetDatabaseRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner_database_admin.Database.to_json(spanner_database_admin.Database()) - - request = spanner_database_admin.GetDatabaseRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner_database_admin.Database() - - client.get_database(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_get_database_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.GetDatabaseRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.get_database(request) - - -def test_get_database_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.Database() - - # get arguments that satisfy an http rule for this method - sample_request = {'name': 'projects/sample1/instances/sample2/databases/sample3'} - - # get truthy value for each flattened field - mock_args = dict( - name='name_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_database_admin.Database.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.get_database(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{name=projects/*/instances/*/databases/*}" % client.transport._host, args[1]) - - -def test_get_database_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_database( - spanner_database_admin.GetDatabaseRequest(), - name='name_value', - ) - - -def test_get_database_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.UpdateDatabaseRequest, - dict, -]) -def test_update_database_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'database': {'name': 'projects/sample1/instances/sample2/databases/sample3'}} - request_init["database"] = {'name': 'projects/sample1/instances/sample2/databases/sample3', 'state': 1, 'create_time': {'seconds': 751, 'nanos': 543}, 'restore_info': {'source_type': 1, 'backup_info': {'backup': 'backup_value', 'version_time': {}, 'create_time': {}, 'source_database': 'source_database_value'}}, 'encryption_config': {'kms_key_name': 'kms_key_name_value'}, 'encryption_info': [{'encryption_type': 1, 'encryption_status': {'code': 411, 'message': 'message_value', 'details': [{'type_url': 'type.googleapis.com/google.protobuf.Duration', 'value': b'\x08\x0c\x10\xdb\x07'}]}, 'kms_key_version': 'kms_key_version_value'}], 'version_retention_period': 'version_retention_period_value', 'earliest_version_time': {}, 'default_leader': 'default_leader_value', 'database_dialect': 1, 'enable_drop_protection': True, 'reconciling': True} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.update_database(request) - - # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" - - -def test_update_database_rest_required_fields(request_type=spanner_database_admin.UpdateDatabaseRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_database._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_database._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("update_mask", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "patch", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.update_database(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_update_database_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.update_database._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask", )) & set(("database", "updateMask", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_database_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(operation.Operation, "_set_result_from_operation"), \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_update_database") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_update_database") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_database_admin.UpdateDatabaseRequest.pb(spanner_database_admin.UpdateDatabaseRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) - - request = spanner_database_admin.UpdateDatabaseRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - - client.update_database(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_update_database_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.UpdateDatabaseRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'database': {'name': 'projects/sample1/instances/sample2/databases/sample3'}} - request_init["database"] = {'name': 'projects/sample1/instances/sample2/databases/sample3', 'state': 1, 'create_time': {'seconds': 751, 'nanos': 543}, 'restore_info': {'source_type': 1, 'backup_info': {'backup': 'backup_value', 'version_time': {}, 'create_time': {}, 'source_database': 'source_database_value'}}, 'encryption_config': {'kms_key_name': 'kms_key_name_value'}, 'encryption_info': [{'encryption_type': 1, 'encryption_status': {'code': 411, 'message': 'message_value', 'details': [{'type_url': 'type.googleapis.com/google.protobuf.Duration', 'value': b'\x08\x0c\x10\xdb\x07'}]}, 'kms_key_version': 'kms_key_version_value'}], 'version_retention_period': 'version_retention_period_value', 'earliest_version_time': {}, 'default_leader': 'default_leader_value', 'database_dialect': 1, 'enable_drop_protection': True, 'reconciling': True} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.update_database(request) - - -def test_update_database_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # get arguments that satisfy an http rule for this method - sample_request = {'database': {'name': 'projects/sample1/instances/sample2/databases/sample3'}} - - # get truthy value for each flattened field - mock_args = dict( - database=spanner_database_admin.Database(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.update_database(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{database.name=projects/*/instances/*/databases/*}" % client.transport._host, args[1]) - - -def test_update_database_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_database( - spanner_database_admin.UpdateDatabaseRequest(), - database=spanner_database_admin.Database(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -def test_update_database_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.UpdateDatabaseDdlRequest, - dict, -]) -def test_update_database_ddl_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.update_database_ddl(request) - - # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" - - -def test_update_database_ddl_rest_required_fields(request_type=spanner_database_admin.UpdateDatabaseDdlRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["database"] = "" - request_init["statements"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_database_ddl._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["database"] = 'database_value' - jsonified_request["statements"] = 'statements_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_database_ddl._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "database" in jsonified_request - assert jsonified_request["database"] == 'database_value' - assert "statements" in jsonified_request - assert jsonified_request["statements"] == 'statements_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "patch", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.update_database_ddl(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_update_database_ddl_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.update_database_ddl._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("database", "statements", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_database_ddl_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(operation.Operation, "_set_result_from_operation"), \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_update_database_ddl") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_update_database_ddl") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_database_admin.UpdateDatabaseDdlRequest.pb(spanner_database_admin.UpdateDatabaseDdlRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) - - request = spanner_database_admin.UpdateDatabaseDdlRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - - client.update_database_ddl(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_update_database_ddl_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.UpdateDatabaseDdlRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.update_database_ddl(request) - - -def test_update_database_ddl_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # get arguments that satisfy an http rule for this method - sample_request = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - - # get truthy value for each flattened field - mock_args = dict( - database='database_value', - statements=['statements_value'], - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.update_database_ddl(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{database=projects/*/instances/*/databases/*}/ddl" % client.transport._host, args[1]) - - -def test_update_database_ddl_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_database_ddl( - spanner_database_admin.UpdateDatabaseDdlRequest(), - database='database_value', - statements=['statements_value'], - ) - - -def test_update_database_ddl_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.DropDatabaseRequest, - dict, -]) -def test_drop_database_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.drop_database(request) - - # Establish that the response is the type that we expect. - assert response is None - - -def test_drop_database_rest_required_fields(request_type=spanner_database_admin.DropDatabaseRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["database"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).drop_database._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["database"] = 'database_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).drop_database._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "database" in jsonified_request - assert jsonified_request["database"] == 'database_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = None - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "delete", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.drop_database(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_drop_database_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.drop_database._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("database", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_drop_database_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_drop_database") as pre: - pre.assert_not_called() - pb_message = spanner_database_admin.DropDatabaseRequest.pb(spanner_database_admin.DropDatabaseRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - - request = spanner_database_admin.DropDatabaseRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - - client.drop_database(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - - -def test_drop_database_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.DropDatabaseRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.drop_database(request) - - -def test_drop_database_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # get arguments that satisfy an http rule for this method - sample_request = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - - # get truthy value for each flattened field - mock_args = dict( - database='database_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.drop_database(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{database=projects/*/instances/*/databases/*}" % client.transport._host, args[1]) - - -def test_drop_database_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.drop_database( - spanner_database_admin.DropDatabaseRequest(), - database='database_value', - ) - - -def test_drop_database_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.GetDatabaseDdlRequest, - dict, -]) -def test_get_database_ddl_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.GetDatabaseDdlResponse( - statements=['statements_value'], - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_database_admin.GetDatabaseDdlResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.get_database_ddl(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner_database_admin.GetDatabaseDdlResponse) - assert response.statements == ['statements_value'] - - -def test_get_database_ddl_rest_required_fields(request_type=spanner_database_admin.GetDatabaseDdlRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["database"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_database_ddl._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["database"] = 'database_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_database_ddl._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "database" in jsonified_request - assert jsonified_request["database"] == 'database_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.GetDatabaseDdlResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner_database_admin.GetDatabaseDdlResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.get_database_ddl(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_get_database_ddl_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.get_database_ddl._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("database", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_database_ddl_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_get_database_ddl") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_get_database_ddl") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_database_admin.GetDatabaseDdlRequest.pb(spanner_database_admin.GetDatabaseDdlRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner_database_admin.GetDatabaseDdlResponse.to_json(spanner_database_admin.GetDatabaseDdlResponse()) - - request = spanner_database_admin.GetDatabaseDdlRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner_database_admin.GetDatabaseDdlResponse() - - client.get_database_ddl(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_get_database_ddl_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.GetDatabaseDdlRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.get_database_ddl(request) - - -def test_get_database_ddl_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.GetDatabaseDdlResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'database': 'projects/sample1/instances/sample2/databases/sample3'} - - # get truthy value for each flattened field - mock_args = dict( - database='database_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_database_admin.GetDatabaseDdlResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.get_database_ddl(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{database=projects/*/instances/*/databases/*}/ddl" % client.transport._host, args[1]) - - -def test_get_database_ddl_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_database_ddl( - spanner_database_admin.GetDatabaseDdlRequest(), - database='database_value', - ) - - -def test_get_database_ddl_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - iam_policy_pb2.SetIamPolicyRequest, - dict, -]) -def test_set_iam_policy_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy( - version=774, - etag=b'etag_blob', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.set_iam_policy(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, policy_pb2.Policy) - assert response.version == 774 - assert response.etag == b'etag_blob' - - -def test_set_iam_policy_rest_required_fields(request_type=iam_policy_pb2.SetIamPolicyRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["resource"] = "" - request = request_type(**request_init) - pb_request = request - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).set_iam_policy._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["resource"] = 'resource_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).set_iam_policy._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "resource" in jsonified_request - assert jsonified_request["resource"] == 'resource_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.set_iam_policy(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_set_iam_policy_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.set_iam_policy._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("resource", "policy", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_set_iam_policy_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_set_iam_policy") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_set_iam_policy") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = iam_policy_pb2.SetIamPolicyRequest() - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(policy_pb2.Policy()) - - request = iam_policy_pb2.SetIamPolicyRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = policy_pb2.Policy() - - client.set_iam_policy(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_set_iam_policy_rest_bad_request(transport: str = 'rest', request_type=iam_policy_pb2.SetIamPolicyRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.set_iam_policy(request) - - -def test_set_iam_policy_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy() - - # get arguments that satisfy an http rule for this method - sample_request = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} - - # get truthy value for each flattened field - mock_args = dict( - resource='resource_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.set_iam_policy(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{resource=projects/*/instances/*/databases/*}:setIamPolicy" % client.transport._host, args[1]) - - -def test_set_iam_policy_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.set_iam_policy( - iam_policy_pb2.SetIamPolicyRequest(), - resource='resource_value', - ) - - -def test_set_iam_policy_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - iam_policy_pb2.GetIamPolicyRequest, - dict, -]) -def test_get_iam_policy_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy( - version=774, - etag=b'etag_blob', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.get_iam_policy(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, policy_pb2.Policy) - assert response.version == 774 - assert response.etag == b'etag_blob' - - -def test_get_iam_policy_rest_required_fields(request_type=iam_policy_pb2.GetIamPolicyRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["resource"] = "" - request = request_type(**request_init) - pb_request = request - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_iam_policy._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["resource"] = 'resource_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_iam_policy._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "resource" in jsonified_request - assert jsonified_request["resource"] == 'resource_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.get_iam_policy(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_get_iam_policy_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.get_iam_policy._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("resource", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_iam_policy_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_get_iam_policy") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_get_iam_policy") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = iam_policy_pb2.GetIamPolicyRequest() - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(policy_pb2.Policy()) - - request = iam_policy_pb2.GetIamPolicyRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = policy_pb2.Policy() - - client.get_iam_policy(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_get_iam_policy_rest_bad_request(transport: str = 'rest', request_type=iam_policy_pb2.GetIamPolicyRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.get_iam_policy(request) - - -def test_get_iam_policy_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy() - - # get arguments that satisfy an http rule for this method - sample_request = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} - - # get truthy value for each flattened field - mock_args = dict( - resource='resource_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.get_iam_policy(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{resource=projects/*/instances/*/databases/*}:getIamPolicy" % client.transport._host, args[1]) - - -def test_get_iam_policy_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_iam_policy( - iam_policy_pb2.GetIamPolicyRequest(), - resource='resource_value', - ) - - -def test_get_iam_policy_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - iam_policy_pb2.TestIamPermissionsRequest, - dict, -]) -def test_test_iam_permissions_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = iam_policy_pb2.TestIamPermissionsResponse( - permissions=['permissions_value'], - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.test_iam_permissions(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) - assert response.permissions == ['permissions_value'] - - -def test_test_iam_permissions_rest_required_fields(request_type=iam_policy_pb2.TestIamPermissionsRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["resource"] = "" - request_init["permissions"] = "" - request = request_type(**request_init) - pb_request = request - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).test_iam_permissions._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["resource"] = 'resource_value' - jsonified_request["permissions"] = 'permissions_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).test_iam_permissions._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "resource" in jsonified_request - assert jsonified_request["resource"] == 'resource_value' - assert "permissions" in jsonified_request - assert jsonified_request["permissions"] == 'permissions_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = iam_policy_pb2.TestIamPermissionsResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.test_iam_permissions(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_test_iam_permissions_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.test_iam_permissions._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("resource", "permissions", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_test_iam_permissions_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_test_iam_permissions") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_test_iam_permissions") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = iam_policy_pb2.TestIamPermissionsRequest() - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(iam_policy_pb2.TestIamPermissionsResponse()) - - request = iam_policy_pb2.TestIamPermissionsRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = iam_policy_pb2.TestIamPermissionsResponse() - - client.test_iam_permissions(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_test_iam_permissions_rest_bad_request(transport: str = 'rest', request_type=iam_policy_pb2.TestIamPermissionsRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.test_iam_permissions(request) - - -def test_test_iam_permissions_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = iam_policy_pb2.TestIamPermissionsResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'resource': 'projects/sample1/instances/sample2/databases/sample3'} - - # get truthy value for each flattened field - mock_args = dict( - resource='resource_value', - permissions=['permissions_value'], - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.test_iam_permissions(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{resource=projects/*/instances/*/databases/*}:testIamPermissions" % client.transport._host, args[1]) - - -def test_test_iam_permissions_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.test_iam_permissions( - iam_policy_pb2.TestIamPermissionsRequest(), - resource='resource_value', - permissions=['permissions_value'], - ) - - -def test_test_iam_permissions_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - gsad_backup.CreateBackupRequest, - dict, -]) -def test_create_backup_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request_init["backup"] = {'database': 'database_value', 'version_time': {'seconds': 751, 'nanos': 543}, 'expire_time': {}, 'name': 'name_value', 'create_time': {}, 'size_bytes': 1089, 'state': 1, 'referencing_databases': ['referencing_databases_value1', 'referencing_databases_value2'], 'encryption_info': {'encryption_type': 1, 'encryption_status': {'code': 411, 'message': 'message_value', 'details': [{'type_url': 'type.googleapis.com/google.protobuf.Duration', 'value': b'\x08\x0c\x10\xdb\x07'}]}, 'kms_key_version': 'kms_key_version_value'}, 'database_dialect': 1, 'referencing_backups': ['referencing_backups_value1', 'referencing_backups_value2'], 'max_expire_time': {}} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.create_backup(request) - - # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" - - -def test_create_backup_rest_required_fields(request_type=gsad_backup.CreateBackupRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["parent"] = "" - request_init["backup_id"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - assert "backupId" not in jsonified_request - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_backup._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - assert "backupId" in jsonified_request - assert jsonified_request["backupId"] == request_init["backup_id"] - - jsonified_request["parent"] = 'parent_value' - jsonified_request["backupId"] = 'backup_id_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_backup._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("backup_id", "encryption_config", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - assert "backupId" in jsonified_request - assert jsonified_request["backupId"] == 'backup_id_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.create_backup(request) - - expected_params = [ - ( - "backupId", - "", - ), - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_create_backup_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.create_backup._get_unset_required_fields({}) - assert set(unset_fields) == (set(("backupId", "encryptionConfig", )) & set(("parent", "backupId", "backup", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_backup_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(operation.Operation, "_set_result_from_operation"), \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_create_backup") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_create_backup") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = gsad_backup.CreateBackupRequest.pb(gsad_backup.CreateBackupRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) - - request = gsad_backup.CreateBackupRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - - client.create_backup(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_create_backup_rest_bad_request(transport: str = 'rest', request_type=gsad_backup.CreateBackupRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request_init["backup"] = {'database': 'database_value', 'version_time': {'seconds': 751, 'nanos': 543}, 'expire_time': {}, 'name': 'name_value', 'create_time': {}, 'size_bytes': 1089, 'state': 1, 'referencing_databases': ['referencing_databases_value1', 'referencing_databases_value2'], 'encryption_info': {'encryption_type': 1, 'encryption_status': {'code': 411, 'message': 'message_value', 'details': [{'type_url': 'type.googleapis.com/google.protobuf.Duration', 'value': b'\x08\x0c\x10\xdb\x07'}]}, 'kms_key_version': 'kms_key_version_value'}, 'database_dialect': 1, 'referencing_backups': ['referencing_backups_value1', 'referencing_backups_value2'], 'max_expire_time': {}} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.create_backup(request) - - -def test_create_backup_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'projects/sample1/instances/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - backup=gsad_backup.Backup(database='database_value'), - backup_id='backup_id_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.create_backup(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/backups" % client.transport._host, args[1]) - - -def test_create_backup_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_backup( - gsad_backup.CreateBackupRequest(), - parent='parent_value', - backup=gsad_backup.Backup(database='database_value'), - backup_id='backup_id_value', - ) - - -def test_create_backup_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - backup.CopyBackupRequest, - dict, -]) -def test_copy_backup_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.copy_backup(request) - - # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" - - -def test_copy_backup_rest_required_fields(request_type=backup.CopyBackupRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["parent"] = "" - request_init["backup_id"] = "" - request_init["source_backup"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).copy_backup._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["parent"] = 'parent_value' - jsonified_request["backupId"] = 'backup_id_value' - jsonified_request["sourceBackup"] = 'source_backup_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).copy_backup._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - assert "backupId" in jsonified_request - assert jsonified_request["backupId"] == 'backup_id_value' - assert "sourceBackup" in jsonified_request - assert jsonified_request["sourceBackup"] == 'source_backup_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.copy_backup(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_copy_backup_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.copy_backup._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("parent", "backupId", "sourceBackup", "expireTime", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_copy_backup_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(operation.Operation, "_set_result_from_operation"), \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_copy_backup") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_copy_backup") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = backup.CopyBackupRequest.pb(backup.CopyBackupRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) - - request = backup.CopyBackupRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - - client.copy_backup(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_copy_backup_rest_bad_request(transport: str = 'rest', request_type=backup.CopyBackupRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.copy_backup(request) - - -def test_copy_backup_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'projects/sample1/instances/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - backup_id='backup_id_value', - source_backup='source_backup_value', - expire_time=timestamp_pb2.Timestamp(seconds=751), - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.copy_backup(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/backups:copy" % client.transport._host, args[1]) - - -def test_copy_backup_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.copy_backup( - backup.CopyBackupRequest(), - parent='parent_value', - backup_id='backup_id_value', - source_backup='source_backup_value', - expire_time=timestamp_pb2.Timestamp(seconds=751), - ) - - -def test_copy_backup_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - backup.GetBackupRequest, - dict, -]) -def test_get_backup_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instances/sample2/backups/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = backup.Backup( - database='database_value', - name='name_value', - size_bytes=1089, - state=backup.Backup.State.CREATING, - referencing_databases=['referencing_databases_value'], - database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, - referencing_backups=['referencing_backups_value'], - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = backup.Backup.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.get_backup(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, backup.Backup) - assert response.database == 'database_value' - assert response.name == 'name_value' - assert response.size_bytes == 1089 - assert response.state == backup.Backup.State.CREATING - assert response.referencing_databases == ['referencing_databases_value'] - assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL - assert response.referencing_backups == ['referencing_backups_value'] - - -def test_get_backup_rest_required_fields(request_type=backup.GetBackupRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["name"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_backup._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["name"] = 'name_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_backup._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == 'name_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = backup.Backup() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = backup.Backup.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.get_backup(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_get_backup_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.get_backup._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_backup_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_get_backup") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_get_backup") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = backup.GetBackupRequest.pb(backup.GetBackupRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = backup.Backup.to_json(backup.Backup()) - - request = backup.GetBackupRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = backup.Backup() - - client.get_backup(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_get_backup_rest_bad_request(transport: str = 'rest', request_type=backup.GetBackupRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instances/sample2/backups/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.get_backup(request) - - -def test_get_backup_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = backup.Backup() - - # get arguments that satisfy an http rule for this method - sample_request = {'name': 'projects/sample1/instances/sample2/backups/sample3'} - - # get truthy value for each flattened field - mock_args = dict( - name='name_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = backup.Backup.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.get_backup(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{name=projects/*/instances/*/backups/*}" % client.transport._host, args[1]) - - -def test_get_backup_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_backup( - backup.GetBackupRequest(), - name='name_value', - ) - - -def test_get_backup_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - gsad_backup.UpdateBackupRequest, - dict, -]) -def test_update_backup_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'backup': {'name': 'projects/sample1/instances/sample2/backups/sample3'}} - request_init["backup"] = {'database': 'database_value', 'version_time': {'seconds': 751, 'nanos': 543}, 'expire_time': {}, 'name': 'projects/sample1/instances/sample2/backups/sample3', 'create_time': {}, 'size_bytes': 1089, 'state': 1, 'referencing_databases': ['referencing_databases_value1', 'referencing_databases_value2'], 'encryption_info': {'encryption_type': 1, 'encryption_status': {'code': 411, 'message': 'message_value', 'details': [{'type_url': 'type.googleapis.com/google.protobuf.Duration', 'value': b'\x08\x0c\x10\xdb\x07'}]}, 'kms_key_version': 'kms_key_version_value'}, 'database_dialect': 1, 'referencing_backups': ['referencing_backups_value1', 'referencing_backups_value2'], 'max_expire_time': {}} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = gsad_backup.Backup( - database='database_value', - name='name_value', - size_bytes=1089, - state=gsad_backup.Backup.State.CREATING, - referencing_databases=['referencing_databases_value'], - database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, - referencing_backups=['referencing_backups_value'], - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = gsad_backup.Backup.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.update_backup(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, gsad_backup.Backup) - assert response.database == 'database_value' - assert response.name == 'name_value' - assert response.size_bytes == 1089 - assert response.state == gsad_backup.Backup.State.CREATING - assert response.referencing_databases == ['referencing_databases_value'] - assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL - assert response.referencing_backups == ['referencing_backups_value'] - - -def test_update_backup_rest_required_fields(request_type=gsad_backup.UpdateBackupRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_backup._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_backup._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("update_mask", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = gsad_backup.Backup() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "patch", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = gsad_backup.Backup.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.update_backup(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_update_backup_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.update_backup._get_unset_required_fields({}) - assert set(unset_fields) == (set(("updateMask", )) & set(("backup", "updateMask", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_backup_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_update_backup") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_update_backup") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = gsad_backup.UpdateBackupRequest.pb(gsad_backup.UpdateBackupRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = gsad_backup.Backup.to_json(gsad_backup.Backup()) - - request = gsad_backup.UpdateBackupRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = gsad_backup.Backup() - - client.update_backup(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_update_backup_rest_bad_request(transport: str = 'rest', request_type=gsad_backup.UpdateBackupRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'backup': {'name': 'projects/sample1/instances/sample2/backups/sample3'}} - request_init["backup"] = {'database': 'database_value', 'version_time': {'seconds': 751, 'nanos': 543}, 'expire_time': {}, 'name': 'projects/sample1/instances/sample2/backups/sample3', 'create_time': {}, 'size_bytes': 1089, 'state': 1, 'referencing_databases': ['referencing_databases_value1', 'referencing_databases_value2'], 'encryption_info': {'encryption_type': 1, 'encryption_status': {'code': 411, 'message': 'message_value', 'details': [{'type_url': 'type.googleapis.com/google.protobuf.Duration', 'value': b'\x08\x0c\x10\xdb\x07'}]}, 'kms_key_version': 'kms_key_version_value'}, 'database_dialect': 1, 'referencing_backups': ['referencing_backups_value1', 'referencing_backups_value2'], 'max_expire_time': {}} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.update_backup(request) - - -def test_update_backup_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = gsad_backup.Backup() - - # get arguments that satisfy an http rule for this method - sample_request = {'backup': {'name': 'projects/sample1/instances/sample2/backups/sample3'}} - - # get truthy value for each flattened field - mock_args = dict( - backup=gsad_backup.Backup(database='database_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = gsad_backup.Backup.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.update_backup(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{backup.name=projects/*/instances/*/backups/*}" % client.transport._host, args[1]) - - -def test_update_backup_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_backup( - gsad_backup.UpdateBackupRequest(), - backup=gsad_backup.Backup(database='database_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -def test_update_backup_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - backup.DeleteBackupRequest, - dict, -]) -def test_delete_backup_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instances/sample2/backups/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.delete_backup(request) - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_backup_rest_required_fields(request_type=backup.DeleteBackupRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["name"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_backup._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["name"] = 'name_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_backup._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == 'name_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = None - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "delete", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.delete_backup(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_delete_backup_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.delete_backup._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_backup_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_delete_backup") as pre: - pre.assert_not_called() - pb_message = backup.DeleteBackupRequest.pb(backup.DeleteBackupRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - - request = backup.DeleteBackupRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - - client.delete_backup(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - - -def test_delete_backup_rest_bad_request(transport: str = 'rest', request_type=backup.DeleteBackupRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instances/sample2/backups/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.delete_backup(request) - - -def test_delete_backup_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # get arguments that satisfy an http rule for this method - sample_request = {'name': 'projects/sample1/instances/sample2/backups/sample3'} - - # get truthy value for each flattened field - mock_args = dict( - name='name_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.delete_backup(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{name=projects/*/instances/*/backups/*}" % client.transport._host, args[1]) - - -def test_delete_backup_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_backup( - backup.DeleteBackupRequest(), - name='name_value', - ) - - -def test_delete_backup_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - backup.ListBackupsRequest, - dict, -]) -def test_list_backups_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = backup.ListBackupsResponse( - next_page_token='next_page_token_value', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = backup.ListBackupsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.list_backups(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListBackupsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_backups_rest_required_fields(request_type=backup.ListBackupsRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["parent"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_backups._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["parent"] = 'parent_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_backups._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("filter", "page_size", "page_token", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = backup.ListBackupsResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = backup.ListBackupsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.list_backups(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_list_backups_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.list_backups._get_unset_required_fields({}) - assert set(unset_fields) == (set(("filter", "pageSize", "pageToken", )) & set(("parent", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_backups_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_list_backups") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_list_backups") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = backup.ListBackupsRequest.pb(backup.ListBackupsRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = backup.ListBackupsResponse.to_json(backup.ListBackupsResponse()) - - request = backup.ListBackupsRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = backup.ListBackupsResponse() - - client.list_backups(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_list_backups_rest_bad_request(transport: str = 'rest', request_type=backup.ListBackupsRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.list_backups(request) - - -def test_list_backups_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = backup.ListBackupsResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'projects/sample1/instances/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = backup.ListBackupsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.list_backups(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/backups" % client.transport._host, args[1]) - - -def test_list_backups_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_backups( - backup.ListBackupsRequest(), - parent='parent_value', - ) - - -def test_list_backups_rest_pager(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - #with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - backup.Backup(), - backup.Backup(), - ], - next_page_token='abc', - ), - backup.ListBackupsResponse( - backups=[], - next_page_token='def', - ), - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - ], - next_page_token='ghi', - ), - backup.ListBackupsResponse( - backups=[ - backup.Backup(), - backup.Backup(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(backup.ListBackupsResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode('UTF-8') - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {'parent': 'projects/sample1/instances/sample2'} - - pager = client.list_backups(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, backup.Backup) - for i in results) - - pages = list(client.list_backups(request=sample_request).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.RestoreDatabaseRequest, - dict, -]) -def test_restore_database_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.restore_database(request) - - # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" - - -def test_restore_database_rest_required_fields(request_type=spanner_database_admin.RestoreDatabaseRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["parent"] = "" - request_init["database_id"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).restore_database._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["parent"] = 'parent_value' - jsonified_request["databaseId"] = 'database_id_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).restore_database._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - assert "databaseId" in jsonified_request - assert jsonified_request["databaseId"] == 'database_id_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.restore_database(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_restore_database_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.restore_database._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("parent", "databaseId", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_restore_database_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(operation.Operation, "_set_result_from_operation"), \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_restore_database") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_restore_database") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_database_admin.RestoreDatabaseRequest.pb(spanner_database_admin.RestoreDatabaseRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) - - request = spanner_database_admin.RestoreDatabaseRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - - client.restore_database(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_restore_database_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.RestoreDatabaseRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.restore_database(request) - - -def test_restore_database_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'projects/sample1/instances/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - database_id='database_id_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.restore_database(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/databases:restore" % client.transport._host, args[1]) - - -def test_restore_database_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.restore_database( - spanner_database_admin.RestoreDatabaseRequest(), - parent='parent_value', - database_id='database_id_value', - backup='backup_value', - ) - - -def test_restore_database_rest_error(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.ListDatabaseOperationsRequest, - dict, -]) -def test_list_database_operations_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.ListDatabaseOperationsResponse( - next_page_token='next_page_token_value', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_database_admin.ListDatabaseOperationsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.list_database_operations(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListDatabaseOperationsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_database_operations_rest_required_fields(request_type=spanner_database_admin.ListDatabaseOperationsRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["parent"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_database_operations._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["parent"] = 'parent_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_database_operations._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("filter", "page_size", "page_token", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.ListDatabaseOperationsResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner_database_admin.ListDatabaseOperationsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.list_database_operations(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_list_database_operations_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.list_database_operations._get_unset_required_fields({}) - assert set(unset_fields) == (set(("filter", "pageSize", "pageToken", )) & set(("parent", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_database_operations_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_list_database_operations") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_list_database_operations") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_database_admin.ListDatabaseOperationsRequest.pb(spanner_database_admin.ListDatabaseOperationsRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner_database_admin.ListDatabaseOperationsResponse.to_json(spanner_database_admin.ListDatabaseOperationsResponse()) - - request = spanner_database_admin.ListDatabaseOperationsRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner_database_admin.ListDatabaseOperationsResponse() - - client.list_database_operations(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_list_database_operations_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.ListDatabaseOperationsRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.list_database_operations(request) - - -def test_list_database_operations_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.ListDatabaseOperationsResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'projects/sample1/instances/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_database_admin.ListDatabaseOperationsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.list_database_operations(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/databaseOperations" % client.transport._host, args[1]) - - -def test_list_database_operations_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_database_operations( - spanner_database_admin.ListDatabaseOperationsRequest(), - parent='parent_value', - ) - - -def test_list_database_operations_rest_pager(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - #with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabaseOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(spanner_database_admin.ListDatabaseOperationsResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode('UTF-8') - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {'parent': 'projects/sample1/instances/sample2'} - - pager = client.list_database_operations(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, operations_pb2.Operation) - for i in results) - - pages = list(client.list_database_operations(request=sample_request).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.parametrize("request_type", [ - backup.ListBackupOperationsRequest, - dict, -]) -def test_list_backup_operations_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = backup.ListBackupOperationsResponse( - next_page_token='next_page_token_value', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = backup.ListBackupOperationsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.list_backup_operations(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListBackupOperationsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_backup_operations_rest_required_fields(request_type=backup.ListBackupOperationsRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["parent"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_backup_operations._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["parent"] = 'parent_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_backup_operations._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("filter", "page_size", "page_token", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = backup.ListBackupOperationsResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = backup.ListBackupOperationsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.list_backup_operations(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_list_backup_operations_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.list_backup_operations._get_unset_required_fields({}) - assert set(unset_fields) == (set(("filter", "pageSize", "pageToken", )) & set(("parent", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_backup_operations_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_list_backup_operations") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_list_backup_operations") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = backup.ListBackupOperationsRequest.pb(backup.ListBackupOperationsRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = backup.ListBackupOperationsResponse.to_json(backup.ListBackupOperationsResponse()) - - request = backup.ListBackupOperationsRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = backup.ListBackupOperationsResponse() - - client.list_backup_operations(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_list_backup_operations_rest_bad_request(transport: str = 'rest', request_type=backup.ListBackupOperationsRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.list_backup_operations(request) - - -def test_list_backup_operations_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = backup.ListBackupOperationsResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'projects/sample1/instances/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = backup.ListBackupOperationsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.list_backup_operations(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{parent=projects/*/instances/*}/backupOperations" % client.transport._host, args[1]) - - -def test_list_backup_operations_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_backup_operations( - backup.ListBackupOperationsRequest(), - parent='parent_value', - ) - - -def test_list_backup_operations_rest_pager(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - #with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - backup.ListBackupOperationsResponse( - operations=[], - next_page_token='def', - ), - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - backup.ListBackupOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(backup.ListBackupOperationsResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode('UTF-8') - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {'parent': 'projects/sample1/instances/sample2'} - - pager = client.list_backup_operations(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, operations_pb2.Operation) - for i in results) - - pages = list(client.list_backup_operations(request=sample_request).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.parametrize("request_type", [ - spanner_database_admin.ListDatabaseRolesRequest, - dict, -]) -def test_list_database_roles_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.ListDatabaseRolesResponse( - next_page_token='next_page_token_value', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_database_admin.ListDatabaseRolesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.list_database_roles(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListDatabaseRolesPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_database_roles_rest_required_fields(request_type=spanner_database_admin.ListDatabaseRolesRequest): - transport_class = transports.DatabaseAdminRestTransport - - request_init = {} - request_init["parent"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_database_roles._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["parent"] = 'parent_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_database_roles._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("page_size", "page_token", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.ListDatabaseRolesResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner_database_admin.ListDatabaseRolesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.list_database_roles(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_list_database_roles_rest_unset_required_fields(): - transport = transports.DatabaseAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.list_database_roles._get_unset_required_fields({}) - assert set(unset_fields) == (set(("pageSize", "pageToken", )) & set(("parent", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_database_roles_rest_interceptors(null_interceptor): - transport = transports.DatabaseAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.DatabaseAdminRestInterceptor(), - ) - client = DatabaseAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "post_list_database_roles") as post, \ - mock.patch.object(transports.DatabaseAdminRestInterceptor, "pre_list_database_roles") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_database_admin.ListDatabaseRolesRequest.pb(spanner_database_admin.ListDatabaseRolesRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner_database_admin.ListDatabaseRolesResponse.to_json(spanner_database_admin.ListDatabaseRolesResponse()) - - request = spanner_database_admin.ListDatabaseRolesRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner_database_admin.ListDatabaseRolesResponse() - - client.list_database_roles(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_list_database_roles_rest_bad_request(transport: str = 'rest', request_type=spanner_database_admin.ListDatabaseRolesRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1/instances/sample2/databases/sample3'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.list_database_roles(request) - - -def test_list_database_roles_rest_flattened(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_database_admin.ListDatabaseRolesResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'projects/sample1/instances/sample2/databases/sample3'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_database_admin.ListDatabaseRolesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.list_database_roles(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{parent=projects/*/instances/*/databases/*}/databaseRoles" % client.transport._host, args[1]) - - -def test_list_database_roles_rest_flattened_error(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_database_roles( - spanner_database_admin.ListDatabaseRolesRequest(), - parent='parent_value', - ) - - -def test_list_database_roles_rest_pager(transport: str = 'rest'): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - #with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - ], - next_page_token='abc', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[], - next_page_token='def', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - ], - next_page_token='ghi', - ), - spanner_database_admin.ListDatabaseRolesResponse( - database_roles=[ - spanner_database_admin.DatabaseRole(), - spanner_database_admin.DatabaseRole(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(spanner_database_admin.ListDatabaseRolesResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode('UTF-8') - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {'parent': 'projects/sample1/instances/sample2/databases/sample3'} - - pager = client.list_database_roles(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, spanner_database_admin.DatabaseRole) - for i in results) - - pages = list(client.list_database_roles(request=sample_request).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.DatabaseAdminGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.DatabaseAdminGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = DatabaseAdminClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide an api_key and a transport instance. - transport = transports.DatabaseAdminGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - options = client_options.ClientOptions() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = DatabaseAdminClient( - client_options=options, - transport=transport, - ) - - # It is an error to provide an api_key and a credential. - options = mock.Mock() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = DatabaseAdminClient( - client_options=options, - credentials=ga_credentials.AnonymousCredentials() - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.DatabaseAdminGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = DatabaseAdminClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.DatabaseAdminGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = DatabaseAdminClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.DatabaseAdminGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.DatabaseAdminGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.DatabaseAdminGrpcTransport, - transports.DatabaseAdminGrpcAsyncIOTransport, - transports.DatabaseAdminRestTransport, -]) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() - -@pytest.mark.parametrize("transport_name", [ - "grpc", - "rest", -]) -def test_transport_kind(transport_name): - transport = DatabaseAdminClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert transport.kind == transport_name - -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.DatabaseAdminGrpcTransport, - ) - -def test_database_admin_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.DatabaseAdminTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_database_admin_base_transport(): - # Instantiate the base transport. - with mock.patch('google.cloud.spanner_admin_database_v1.services.database_admin.transports.DatabaseAdminTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.DatabaseAdminTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'list_databases', - 'create_database', - 'get_database', - 'update_database', - 'update_database_ddl', - 'drop_database', - 'get_database_ddl', - 'set_iam_policy', - 'get_iam_policy', - 'test_iam_permissions', - 'create_backup', - 'copy_backup', - 'get_backup', - 'update_backup', - 'delete_backup', - 'list_backups', - 'restore_database', - 'list_database_operations', - 'list_backup_operations', - 'list_database_roles', - 'get_operation', - 'cancel_operation', - 'delete_operation', - 'list_operations', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - with pytest.raises(NotImplementedError): - transport.close() - - # Additionally, the LRO client (a property) should - # also raise NotImplementedError - with pytest.raises(NotImplementedError): - transport.operations_client - - # Catch all for all remaining methods and properties - remainder = [ - 'kind', - ] - for r in remainder: - with pytest.raises(NotImplementedError): - getattr(transport, r)() - - -def test_database_admin_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file - with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.spanner_admin_database_v1.services.database_admin.transports.DatabaseAdminTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DatabaseAdminTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.admin', -), - quota_project_id="octopus", - ) - - -def test_database_admin_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.cloud.spanner_admin_database_v1.services.database_admin.transports.DatabaseAdminTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DatabaseAdminTransport() - adc.assert_called_once() - - -def test_database_admin_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - DatabaseAdminClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.admin', -), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.DatabaseAdminGrpcTransport, - transports.DatabaseAdminGrpcAsyncIOTransport, - ], -) -def test_database_admin_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/spanner.admin',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.DatabaseAdminGrpcTransport, - transports.DatabaseAdminGrpcAsyncIOTransport, - transports.DatabaseAdminRestTransport, - ], -) -def test_database_admin_transport_auth_gdch_credentials(transport_class): - host = 'https://language.com' - api_audience_tests = [None, 'https://language2.com'] - api_audience_expect = [host, 'https://language2.com'] - for t, e in zip(api_audience_tests, api_audience_expect): - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - gdch_mock = mock.MagicMock() - type(gdch_mock).with_gdch_audience = mock.PropertyMock(return_value=gdch_mock) - adc.return_value = (gdch_mock, None) - transport_class(host=host, api_audience=t) - gdch_mock.with_gdch_audience.assert_called_once_with( - e - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.DatabaseAdminGrpcTransport, grpc_helpers), - (transports.DatabaseAdminGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_database_admin_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class( - quota_project_id="octopus", - scopes=["1", "2"] - ) - - create_channel.assert_called_with( - "spanner.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.admin', -), - scopes=["1", "2"], - default_host="spanner.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.DatabaseAdminGrpcTransport, transports.DatabaseAdminGrpcAsyncIOTransport]) -def test_database_admin_grpc_transport_client_cert_source_for_mtls( - transport_class -): - cred = ga_credentials.AnonymousCredentials() - - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds - ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback - ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, - private_key=expected_key - ) - -def test_database_admin_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() - with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel") as mock_configure_mtls_channel: - transports.DatabaseAdminRestTransport ( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback - ) - mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) - - -def test_database_admin_rest_lro_client(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - transport = client.transport - - # Ensure that we have a api-core operations client. - assert isinstance( - transport.operations_client, - operations_v1.AbstractOperationsClient, - ) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client - - -@pytest.mark.parametrize("transport_name", [ - "grpc", - "grpc_asyncio", - "rest", -]) -def test_database_admin_host_no_port(transport_name): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='spanner.googleapis.com'), - transport=transport_name, - ) - assert client.transport._host == ( - 'spanner.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else 'https://spanner.googleapis.com' - ) - -@pytest.mark.parametrize("transport_name", [ - "grpc", - "grpc_asyncio", - "rest", -]) -def test_database_admin_host_with_port(transport_name): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='spanner.googleapis.com:8000'), - transport=transport_name, - ) - assert client.transport._host == ( - 'spanner.googleapis.com:8000' - if transport_name in ['grpc', 'grpc_asyncio'] - else 'https://spanner.googleapis.com:8000' - ) - -@pytest.mark.parametrize("transport_name", [ - "rest", -]) -def test_database_admin_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() - client1 = DatabaseAdminClient( - credentials=creds1, - transport=transport_name, - ) - client2 = DatabaseAdminClient( - credentials=creds2, - transport=transport_name, - ) - session1 = client1.transport.list_databases._session - session2 = client2.transport.list_databases._session - assert session1 != session2 - session1 = client1.transport.create_database._session - session2 = client2.transport.create_database._session - assert session1 != session2 - session1 = client1.transport.get_database._session - session2 = client2.transport.get_database._session - assert session1 != session2 - session1 = client1.transport.update_database._session - session2 = client2.transport.update_database._session - assert session1 != session2 - session1 = client1.transport.update_database_ddl._session - session2 = client2.transport.update_database_ddl._session - assert session1 != session2 - session1 = client1.transport.drop_database._session - session2 = client2.transport.drop_database._session - assert session1 != session2 - session1 = client1.transport.get_database_ddl._session - session2 = client2.transport.get_database_ddl._session - assert session1 != session2 - session1 = client1.transport.set_iam_policy._session - session2 = client2.transport.set_iam_policy._session - assert session1 != session2 - session1 = client1.transport.get_iam_policy._session - session2 = client2.transport.get_iam_policy._session - assert session1 != session2 - session1 = client1.transport.test_iam_permissions._session - session2 = client2.transport.test_iam_permissions._session - assert session1 != session2 - session1 = client1.transport.create_backup._session - session2 = client2.transport.create_backup._session - assert session1 != session2 - session1 = client1.transport.copy_backup._session - session2 = client2.transport.copy_backup._session - assert session1 != session2 - session1 = client1.transport.get_backup._session - session2 = client2.transport.get_backup._session - assert session1 != session2 - session1 = client1.transport.update_backup._session - session2 = client2.transport.update_backup._session - assert session1 != session2 - session1 = client1.transport.delete_backup._session - session2 = client2.transport.delete_backup._session - assert session1 != session2 - session1 = client1.transport.list_backups._session - session2 = client2.transport.list_backups._session - assert session1 != session2 - session1 = client1.transport.restore_database._session - session2 = client2.transport.restore_database._session - assert session1 != session2 - session1 = client1.transport.list_database_operations._session - session2 = client2.transport.list_database_operations._session - assert session1 != session2 - session1 = client1.transport.list_backup_operations._session - session2 = client2.transport.list_backup_operations._session - assert session1 != session2 - session1 = client1.transport.list_database_roles._session - session2 = client2.transport.list_database_roles._session - assert session1 != session2 -def test_database_admin_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.DatabaseAdminGrpcTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -def test_database_admin_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.DatabaseAdminGrpcAsyncIOTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.DatabaseAdminGrpcTransport, transports.DatabaseAdminGrpcAsyncIOTransport]) -def test_database_admin_transport_channel_mtls_with_client_cert_source( - transport_class -): - with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() - - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.DatabaseAdminGrpcTransport, transports.DatabaseAdminGrpcAsyncIOTransport]) -def test_database_admin_transport_channel_mtls_with_adc( - transport_class -): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() - - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) - - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - - -def test_database_admin_grpc_lro_client(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - transport = client.transport - - # Ensure that we have a api-core operations client. - assert isinstance( - transport.operations_client, - operations_v1.OperationsClient, - ) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client - - -def test_database_admin_grpc_lro_async_client(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc_asyncio', - ) - transport = client.transport - - # Ensure that we have a api-core operations client. - assert isinstance( - transport.operations_client, - operations_v1.OperationsAsyncClient, - ) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client - - -def test_backup_path(): - project = "squid" - instance = "clam" - backup = "whelk" - expected = "projects/{project}/instances/{instance}/backups/{backup}".format(project=project, instance=instance, backup=backup, ) - actual = DatabaseAdminClient.backup_path(project, instance, backup) - assert expected == actual - - -def test_parse_backup_path(): - expected = { - "project": "octopus", - "instance": "oyster", - "backup": "nudibranch", - } - path = DatabaseAdminClient.backup_path(**expected) - - # Check that the path construction is reversible. - actual = DatabaseAdminClient.parse_backup_path(path) - assert expected == actual - -def test_crypto_key_path(): - project = "cuttlefish" - location = "mussel" - key_ring = "winkle" - crypto_key = "nautilus" - expected = "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}".format(project=project, location=location, key_ring=key_ring, crypto_key=crypto_key, ) - actual = DatabaseAdminClient.crypto_key_path(project, location, key_ring, crypto_key) - assert expected == actual - - -def test_parse_crypto_key_path(): - expected = { - "project": "scallop", - "location": "abalone", - "key_ring": "squid", - "crypto_key": "clam", - } - path = DatabaseAdminClient.crypto_key_path(**expected) - - # Check that the path construction is reversible. - actual = DatabaseAdminClient.parse_crypto_key_path(path) - assert expected == actual - -def test_crypto_key_version_path(): - project = "whelk" - location = "octopus" - key_ring = "oyster" - crypto_key = "nudibranch" - crypto_key_version = "cuttlefish" - expected = "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version}".format(project=project, location=location, key_ring=key_ring, crypto_key=crypto_key, crypto_key_version=crypto_key_version, ) - actual = DatabaseAdminClient.crypto_key_version_path(project, location, key_ring, crypto_key, crypto_key_version) - assert expected == actual - - -def test_parse_crypto_key_version_path(): - expected = { - "project": "mussel", - "location": "winkle", - "key_ring": "nautilus", - "crypto_key": "scallop", - "crypto_key_version": "abalone", - } - path = DatabaseAdminClient.crypto_key_version_path(**expected) - - # Check that the path construction is reversible. - actual = DatabaseAdminClient.parse_crypto_key_version_path(path) - assert expected == actual - -def test_database_path(): - project = "squid" - instance = "clam" - database = "whelk" - expected = "projects/{project}/instances/{instance}/databases/{database}".format(project=project, instance=instance, database=database, ) - actual = DatabaseAdminClient.database_path(project, instance, database) - assert expected == actual - - -def test_parse_database_path(): - expected = { - "project": "octopus", - "instance": "oyster", - "database": "nudibranch", - } - path = DatabaseAdminClient.database_path(**expected) - - # Check that the path construction is reversible. - actual = DatabaseAdminClient.parse_database_path(path) - assert expected == actual - -def test_database_role_path(): - project = "cuttlefish" - instance = "mussel" - database = "winkle" - role = "nautilus" - expected = "projects/{project}/instances/{instance}/databases/{database}/databaseRoles/{role}".format(project=project, instance=instance, database=database, role=role, ) - actual = DatabaseAdminClient.database_role_path(project, instance, database, role) - assert expected == actual - - -def test_parse_database_role_path(): - expected = { - "project": "scallop", - "instance": "abalone", - "database": "squid", - "role": "clam", - } - path = DatabaseAdminClient.database_role_path(**expected) - - # Check that the path construction is reversible. - actual = DatabaseAdminClient.parse_database_role_path(path) - assert expected == actual - -def test_instance_path(): - project = "whelk" - instance = "octopus" - expected = "projects/{project}/instances/{instance}".format(project=project, instance=instance, ) - actual = DatabaseAdminClient.instance_path(project, instance) - assert expected == actual - - -def test_parse_instance_path(): - expected = { - "project": "oyster", - "instance": "nudibranch", - } - path = DatabaseAdminClient.instance_path(**expected) - - # Check that the path construction is reversible. - actual = DatabaseAdminClient.parse_instance_path(path) - assert expected == actual - -def test_common_billing_account_path(): - billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = DatabaseAdminClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "mussel", - } - path = DatabaseAdminClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = DatabaseAdminClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "winkle" - expected = "folders/{folder}".format(folder=folder, ) - actual = DatabaseAdminClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "nautilus", - } - path = DatabaseAdminClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = DatabaseAdminClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "scallop" - expected = "organizations/{organization}".format(organization=organization, ) - actual = DatabaseAdminClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "abalone", - } - path = DatabaseAdminClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = DatabaseAdminClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "squid" - expected = "projects/{project}".format(project=project, ) - actual = DatabaseAdminClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "clam", - } - path = DatabaseAdminClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = DatabaseAdminClient.parse_common_project_path(path) - assert expected == actual - -def test_common_location_path(): - project = "whelk" - location = "octopus" - expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) - actual = DatabaseAdminClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "oyster", - "location": "nudibranch", - } - path = DatabaseAdminClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = DatabaseAdminClient.parse_common_location_path(path) - assert expected == actual - - -def test_client_with_default_client_info(): - client_info = gapic_v1.client_info.ClientInfo() - - with mock.patch.object(transports.DatabaseAdminTransport, '_prep_wrapped_messages') as prep: - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.DatabaseAdminTransport, '_prep_wrapped_messages') as prep: - transport_class = DatabaseAdminClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - -@pytest.mark.asyncio -async def test_transport_close_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc_asyncio", - ) - with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: - async with client: - close.assert_not_called() - close.assert_called_once() - - -def test_cancel_operation_rest_bad_request(transport: str = 'rest', request_type=operations_pb2.CancelOperationRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - request = request_type() - request = json_format.ParseDict({'name': 'projects/sample1/instances/sample2/databases/sample3/operations/sample4'}, request) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.cancel_operation(request) - -@pytest.mark.parametrize("request_type", [ - operations_pb2.CancelOperationRequest, - dict, -]) -def test_cancel_operation_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/operations/sample4'} - request = request_type(**request_init) - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '{}' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.cancel_operation(request) - - # Establish that the response is the type that we expect. - assert response is None - -def test_delete_operation_rest_bad_request(transport: str = 'rest', request_type=operations_pb2.DeleteOperationRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - request = request_type() - request = json_format.ParseDict({'name': 'projects/sample1/instances/sample2/databases/sample3/operations/sample4'}, request) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.delete_operation(request) - -@pytest.mark.parametrize("request_type", [ - operations_pb2.DeleteOperationRequest, - dict, -]) -def test_delete_operation_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/operations/sample4'} - request = request_type(**request_init) - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '{}' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.delete_operation(request) - - # Establish that the response is the type that we expect. - assert response is None - -def test_get_operation_rest_bad_request(transport: str = 'rest', request_type=operations_pb2.GetOperationRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - request = request_type() - request = json_format.ParseDict({'name': 'projects/sample1/instances/sample2/databases/sample3/operations/sample4'}, request) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.get_operation(request) - -@pytest.mark.parametrize("request_type", [ - operations_pb2.GetOperationRequest, - dict, -]) -def test_get_operation_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/operations/sample4'} - request = request_type(**request_init) - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation() - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.get_operation(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, operations_pb2.Operation) - -def test_list_operations_rest_bad_request(transport: str = 'rest', request_type=operations_pb2.ListOperationsRequest): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - request = request_type() - request = json_format.ParseDict({'name': 'projects/sample1/instances/sample2/databases/sample3/operations'}, request) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.list_operations(request) - -@pytest.mark.parametrize("request_type", [ - operations_pb2.ListOperationsRequest, - dict, -]) -def test_list_operations_rest(request_type): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - request_init = {'name': 'projects/sample1/instances/sample2/databases/sample3/operations'} - request = request_type(**request_init) - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.ListOperationsResponse() - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.list_operations(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, operations_pb2.ListOperationsResponse) - - -def test_delete_operation(transport: str = "grpc"): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = operations_pb2.DeleteOperationRequest() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_operation(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the response is the type that we expect. - assert response is None -@pytest.mark.asyncio -async def test_delete_operation_async(transport: str = "grpc"): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = operations_pb2.DeleteOperationRequest() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - None - ) - response = await client.delete_operation(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the response is the type that we expect. - assert response is None - -def test_delete_operation_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = operations_pb2.DeleteOperationRequest() - request.name = "locations" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: - call.return_value = None - - client.delete_operation(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=locations",) in kw["metadata"] -@pytest.mark.asyncio -async def test_delete_operation_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = operations_pb2.DeleteOperationRequest() - request.name = "locations" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - None - ) - await client.delete_operation(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=locations",) in kw["metadata"] - -def test_delete_operation_from_dict(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = None - - response = client.delete_operation( - request={ - "name": "locations", - } - ) - call.assert_called() -@pytest.mark.asyncio -async def test_delete_operation_from_dict_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - None - ) - response = await client.delete_operation( - request={ - "name": "locations", - } - ) - call.assert_called() - - -def test_cancel_operation(transport: str = "grpc"): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = operations_pb2.CancelOperationRequest() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.cancel_operation(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the response is the type that we expect. - assert response is None -@pytest.mark.asyncio -async def test_cancel_operation_async(transport: str = "grpc"): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = operations_pb2.CancelOperationRequest() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - None - ) - response = await client.cancel_operation(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the response is the type that we expect. - assert response is None - -def test_cancel_operation_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = operations_pb2.CancelOperationRequest() - request.name = "locations" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: - call.return_value = None - - client.cancel_operation(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=locations",) in kw["metadata"] -@pytest.mark.asyncio -async def test_cancel_operation_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = operations_pb2.CancelOperationRequest() - request.name = "locations" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - None - ) - await client.cancel_operation(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=locations",) in kw["metadata"] - -def test_cancel_operation_from_dict(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = None - - response = client.cancel_operation( - request={ - "name": "locations", - } - ) - call.assert_called() -@pytest.mark.asyncio -async def test_cancel_operation_from_dict_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - None - ) - response = await client.cancel_operation( - request={ - "name": "locations", - } - ) - call.assert_called() - - -def test_get_operation(transport: str = "grpc"): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = operations_pb2.GetOperationRequest() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_operation), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation() - response = client.get_operation(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, operations_pb2.Operation) -@pytest.mark.asyncio -async def test_get_operation_async(transport: str = "grpc"): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = operations_pb2.GetOperationRequest() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_operation), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation() - ) - response = await client.get_operation(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, operations_pb2.Operation) - -def test_get_operation_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = operations_pb2.GetOperationRequest() - request.name = "locations" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_operation), "__call__") as call: - call.return_value = operations_pb2.Operation() - - client.get_operation(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=locations",) in kw["metadata"] -@pytest.mark.asyncio -async def test_get_operation_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = operations_pb2.GetOperationRequest() - request.name = "locations" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_operation), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation() - ) - await client.get_operation(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=locations",) in kw["metadata"] - -def test_get_operation_from_dict(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_operation), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation() - - response = client.get_operation( - request={ - "name": "locations", - } - ) - call.assert_called() -@pytest.mark.asyncio -async def test_get_operation_from_dict_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_operation), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation() - ) - response = await client.get_operation( - request={ - "name": "locations", - } - ) - call.assert_called() - - -def test_list_operations(transport: str = "grpc"): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = operations_pb2.ListOperationsRequest() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_operations), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.ListOperationsResponse() - response = client.list_operations(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, operations_pb2.ListOperationsResponse) -@pytest.mark.asyncio -async def test_list_operations_async(transport: str = "grpc"): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = operations_pb2.ListOperationsRequest() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_operations), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.ListOperationsResponse() - ) - response = await client.list_operations(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the response is the type that we expect. - assert isinstance(response, operations_pb2.ListOperationsResponse) - -def test_list_operations_field_headers(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = operations_pb2.ListOperationsRequest() - request.name = "locations" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_operations), "__call__") as call: - call.return_value = operations_pb2.ListOperationsResponse() - - client.list_operations(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=locations",) in kw["metadata"] -@pytest.mark.asyncio -async def test_list_operations_field_headers_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = operations_pb2.ListOperationsRequest() - request.name = "locations" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_operations), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.ListOperationsResponse() - ) - await client.list_operations(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=locations",) in kw["metadata"] - -def test_list_operations_from_dict(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_operations), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.ListOperationsResponse() - - response = client.list_operations( - request={ - "name": "locations", - } - ) - call.assert_called() -@pytest.mark.asyncio -async def test_list_operations_from_dict_async(): - client = DatabaseAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_operations), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.ListOperationsResponse() - ) - response = await client.list_operations( - request={ - "name": "locations", - } - ) - call.assert_called() - - -def test_transport_close(): - transports = { - "rest": "_session", - "grpc": "_grpc_channel", - } - - for transport, close_name in transports.items(): - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - -def test_client_ctx(): - transports = [ - 'rest', - 'grpc', - ] - for transport in transports: - client = DatabaseAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - # Test client calls underlying transport. - with mock.patch.object(type(client.transport), "close") as close: - close.assert_not_called() - with client: - pass - close.assert_called() - -@pytest.mark.parametrize("client_class,transport_class", [ - (DatabaseAdminClient, transports.DatabaseAdminGrpcTransport), - (DatabaseAdminAsyncClient, transports.DatabaseAdminGrpcAsyncIOTransport), -]) -def test_api_key_credentials(client_class, transport_class): - with mock.patch.object( - google.auth._default, "get_api_key_credentials", create=True - ) as get_api_key_credentials: - mock_cred = mock.Mock() - get_api_key_credentials.return_value = mock_cred - options = client_options.ClientOptions() - options.api_key = "api_key" - with mock.patch.object(transport_class, "__init__") as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=mock_cred, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) diff --git a/owl-bot-staging/spanner_admin_instance/v1/.coveragerc b/owl-bot-staging/spanner_admin_instance/v1/.coveragerc deleted file mode 100644 index 040d100fc8..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/.coveragerc +++ /dev/null @@ -1,13 +0,0 @@ -[run] -branch = True - -[report] -show_missing = True -omit = - google/cloud/spanner_admin_instance/__init__.py - google/cloud/spanner_admin_instance/gapic_version.py -exclude_lines = - # Re-enable the standard pragma - pragma: NO COVER - # Ignore debug-only repr - def __repr__ diff --git a/owl-bot-staging/spanner_admin_instance/v1/.flake8 b/owl-bot-staging/spanner_admin_instance/v1/.flake8 deleted file mode 100644 index 29227d4cf4..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/.flake8 +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Generated by synthtool. DO NOT EDIT! -[flake8] -ignore = E203, E266, E501, W503 -exclude = - # Exclude generated code. - **/proto/** - **/gapic/** - **/services/** - **/types/** - *_pb2.py - - # Standard linting exemptions. - **/.nox/** - __pycache__, - .git, - *.pyc, - conf.py diff --git a/owl-bot-staging/spanner_admin_instance/v1/MANIFEST.in b/owl-bot-staging/spanner_admin_instance/v1/MANIFEST.in deleted file mode 100644 index 5af7430e8d..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -recursive-include google/cloud/spanner_admin_instance *.py -recursive-include google/cloud/spanner_admin_instance_v1 *.py diff --git a/owl-bot-staging/spanner_admin_instance/v1/README.rst b/owl-bot-staging/spanner_admin_instance/v1/README.rst deleted file mode 100644 index 94972f5b29..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/README.rst +++ /dev/null @@ -1,49 +0,0 @@ -Python Client for Google Cloud Spanner Admin Instance API -================================================= - -Quick Start ------------ - -In order to use this library, you first need to go through the following steps: - -1. `Select or create a Cloud Platform project.`_ -2. `Enable billing for your project.`_ -3. Enable the Google Cloud Spanner Admin Instance API. -4. `Setup Authentication.`_ - -.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project -.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project -.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html - -Installation -~~~~~~~~~~~~ - -Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to -create isolated Python environments. The basic problem it addresses is one of -dependencies and versions, and indirectly permissions. - -With `virtualenv`_, it's possible to install this library without needing system -install permissions, and without clashing with the installed system -dependencies. - -.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ - - -Mac/Linux -^^^^^^^^^ - -.. code-block:: console - - python3 -m venv - source /bin/activate - /bin/pip install /path/to/library - - -Windows -^^^^^^^ - -.. code-block:: console - - python3 -m venv - \Scripts\activate - \Scripts\pip.exe install \path\to\library diff --git a/owl-bot-staging/spanner_admin_instance/v1/docs/conf.py b/owl-bot-staging/spanner_admin_instance/v1/docs/conf.py deleted file mode 100644 index 74199e86f7..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/docs/conf.py +++ /dev/null @@ -1,376 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# -# google-cloud-spanner-admin-instance documentation build configuration file -# -# This file is execfile()d with the current directory set to its -# containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -import sys -import os -import shlex - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath("..")) - -__version__ = "0.1.0" - -# -- General configuration ------------------------------------------------ - -# If your documentation needs a minimal Sphinx version, state it here. -needs_sphinx = "4.0.1" - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.autosummary", - "sphinx.ext.intersphinx", - "sphinx.ext.coverage", - "sphinx.ext.napoleon", - "sphinx.ext.todo", - "sphinx.ext.viewcode", -] - -# autodoc/autosummary flags -autoclass_content = "both" -autodoc_default_flags = ["members"] -autosummary_generate = True - - -# Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] - -# Allow markdown includes (so releases.md can include CHANGLEOG.md) -# http://www.sphinx-doc.org/en/master/markdown.html -source_parsers = {".md": "recommonmark.parser.CommonMarkParser"} - -# The suffix(es) of source filenames. -# You can specify multiple suffix as a list of string: -source_suffix = [".rst", ".md"] - -# The encoding of source files. -# source_encoding = 'utf-8-sig' - -# The root toctree document. -root_doc = "index" - -# General information about the project. -project = u"google-cloud-spanner-admin-instance" -copyright = u"2022, Google, LLC" -author = u"Google APIs" # TODO: autogenerate this bit - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The full version, including alpha/beta/rc tags. -release = __version__ -# The short X.Y version. -version = ".".join(release.split(".")[0:2]) - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. -language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -# today = '' -# Else, today_fmt is used as the format for a strftime call. -# today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = ["_build"] - -# The reST default role (used for this markup: `text`) to use for all -# documents. -# default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -# add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -# add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -# show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = "sphinx" - -# A list of ignored prefixes for module index sorting. -# modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built documents. -# keep_warnings = False - -# If true, `todo` and `todoList` produce output, else they produce nothing. -todo_include_todos = True - - -# -- Options for HTML output ---------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = "alabaster" - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -html_theme_options = { - "description": "Google Cloud Client Libraries for Python", - "github_user": "googleapis", - "github_repo": "google-cloud-python", - "github_banner": True, - "font_family": "'Roboto', Georgia, sans", - "head_font_family": "'Roboto', Georgia, serif", - "code_font_family": "'Roboto Mono', 'Consolas', monospace", -} - -# Add any paths that contain custom themes here, relative to this directory. -# html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -# html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -# html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -# html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -# html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] - -# Add any extra paths that contain custom files (such as robots.txt or -# .htaccess) here, relative to this directory. These files are copied -# directly to the root of the documentation. -# html_extra_path = [] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -# html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -# html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -# html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -# html_additional_pages = {} - -# If false, no module index is generated. -# html_domain_indices = True - -# If false, no index is generated. -# html_use_index = True - -# If true, the index is split into individual pages for each letter. -# html_split_index = False - -# If true, links to the reST sources are added to the pages. -# html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -# html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -# html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -# html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -# html_file_suffix = None - -# Language to be used for generating the HTML full-text search index. -# Sphinx supports the following languages: -# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' -# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' -# html_search_language = 'en' - -# A dictionary with options for the search language support, empty by default. -# Now only 'ja' uses this config value -# html_search_options = {'type': 'default'} - -# The name of a javascript file (relative to the configuration directory) that -# implements a search results scorer. If empty, the default will be used. -# html_search_scorer = 'scorer.js' - -# Output file base name for HTML help builder. -htmlhelp_basename = "google-cloud-spanner-admin-instance-doc" - -# -- Options for warnings ------------------------------------------------------ - - -suppress_warnings = [ - # Temporarily suppress this to avoid "more than one target found for - # cross-reference" warning, which are intractable for us to avoid while in - # a mono-repo. - # See https://github.com/sphinx-doc/sphinx/blob - # /2a65ffeef5c107c19084fabdd706cdff3f52d93c/sphinx/domains/python.py#L843 - "ref.python" -] - -# -- Options for LaTeX output --------------------------------------------- - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). - # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. - # 'preamble': '', - # Latex figure (float) alignment - # 'figure_align': 'htbp', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - ( - root_doc, - "google-cloud-spanner-admin-instance.tex", - u"google-cloud-spanner-admin-instance Documentation", - author, - "manual", - ) -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -# latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -# latex_use_parts = False - -# If true, show page references after internal links. -# latex_show_pagerefs = False - -# If true, show URL addresses after external links. -# latex_show_urls = False - -# Documents to append as an appendix to all manuals. -# latex_appendices = [] - -# If false, no module index is generated. -# latex_domain_indices = True - - -# -- Options for manual page output --------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - ( - root_doc, - "google-cloud-spanner-admin-instance", - u"Google Cloud Spanner Admin Instance Documentation", - [author], - 1, - ) -] - -# If true, show URL addresses after external links. -# man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - ( - root_doc, - "google-cloud-spanner-admin-instance", - u"google-cloud-spanner-admin-instance Documentation", - author, - "google-cloud-spanner-admin-instance", - "GAPIC library for Google Cloud Spanner Admin Instance API", - "APIs", - ) -] - -# Documents to append as an appendix to all manuals. -# texinfo_appendices = [] - -# If false, no module index is generated. -# texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -# texinfo_show_urls = 'footnote' - -# If true, do not generate a @detailmenu in the "Top" node's menu. -# texinfo_no_detailmenu = False - - -# Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = { - "python": ("http://python.readthedocs.org/en/latest/", None), - "gax": ("https://gax-python.readthedocs.org/en/latest/", None), - "google-auth": ("https://google-auth.readthedocs.io/en/stable", None), - "google-gax": ("https://gax-python.readthedocs.io/en/latest/", None), - "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None), - "grpc": ("https://grpc.io/grpc/python/", None), - "requests": ("http://requests.kennethreitz.org/en/stable/", None), - "proto": ("https://proto-plus-python.readthedocs.io/en/stable", None), - "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), -} - - -# Napoleon settings -napoleon_google_docstring = True -napoleon_numpy_docstring = True -napoleon_include_private_with_doc = False -napoleon_include_special_with_doc = True -napoleon_use_admonition_for_examples = False -napoleon_use_admonition_for_notes = False -napoleon_use_admonition_for_references = False -napoleon_use_ivar = False -napoleon_use_param = True -napoleon_use_rtype = True diff --git a/owl-bot-staging/spanner_admin_instance/v1/docs/index.rst b/owl-bot-staging/spanner_admin_instance/v1/docs/index.rst deleted file mode 100644 index bc65940f95..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/docs/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -API Reference -------------- -.. toctree:: - :maxdepth: 2 - - spanner_admin_instance_v1/services - spanner_admin_instance_v1/types diff --git a/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/instance_admin.rst b/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/instance_admin.rst deleted file mode 100644 index fe820b3fad..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/instance_admin.rst +++ /dev/null @@ -1,10 +0,0 @@ -InstanceAdmin -------------------------------- - -.. automodule:: google.cloud.spanner_admin_instance_v1.services.instance_admin - :members: - :inherited-members: - -.. automodule:: google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers - :members: - :inherited-members: diff --git a/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/services.rst b/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/services.rst deleted file mode 100644 index 407d44cc34..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/services.rst +++ /dev/null @@ -1,6 +0,0 @@ -Services for Google Cloud Spanner Admin Instance v1 API -======================================================= -.. toctree:: - :maxdepth: 2 - - instance_admin diff --git a/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/types.rst b/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/types.rst deleted file mode 100644 index 250cf6bf9b..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/docs/spanner_admin_instance_v1/types.rst +++ /dev/null @@ -1,6 +0,0 @@ -Types for Google Cloud Spanner Admin Instance v1 API -==================================================== - -.. automodule:: google.cloud.spanner_admin_instance_v1.types - :members: - :show-inheritance: diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/__init__.py deleted file mode 100644 index 402b48d265..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/__init__.py +++ /dev/null @@ -1,71 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from google.cloud.spanner_admin_instance import gapic_version as package_version - -__version__ = package_version.__version__ - - -from google.cloud.spanner_admin_instance_v1.services.instance_admin.client import InstanceAdminClient -from google.cloud.spanner_admin_instance_v1.services.instance_admin.async_client import InstanceAdminAsyncClient - -from google.cloud.spanner_admin_instance_v1.types.common import OperationProgress -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import CreateInstanceConfigMetadata -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import CreateInstanceConfigRequest -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import CreateInstanceMetadata -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import CreateInstanceRequest -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import DeleteInstanceConfigRequest -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import DeleteInstanceRequest -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import GetInstanceConfigRequest -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import GetInstanceRequest -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import Instance -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import InstanceConfig -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import ListInstanceConfigOperationsRequest -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import ListInstanceConfigOperationsResponse -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import ListInstanceConfigsRequest -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import ListInstanceConfigsResponse -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import ListInstancesRequest -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import ListInstancesResponse -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import ReplicaInfo -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import UpdateInstanceConfigMetadata -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import UpdateInstanceConfigRequest -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import UpdateInstanceMetadata -from google.cloud.spanner_admin_instance_v1.types.spanner_instance_admin import UpdateInstanceRequest - -__all__ = ('InstanceAdminClient', - 'InstanceAdminAsyncClient', - 'OperationProgress', - 'CreateInstanceConfigMetadata', - 'CreateInstanceConfigRequest', - 'CreateInstanceMetadata', - 'CreateInstanceRequest', - 'DeleteInstanceConfigRequest', - 'DeleteInstanceRequest', - 'GetInstanceConfigRequest', - 'GetInstanceRequest', - 'Instance', - 'InstanceConfig', - 'ListInstanceConfigOperationsRequest', - 'ListInstanceConfigOperationsResponse', - 'ListInstanceConfigsRequest', - 'ListInstanceConfigsResponse', - 'ListInstancesRequest', - 'ListInstancesResponse', - 'ReplicaInfo', - 'UpdateInstanceConfigMetadata', - 'UpdateInstanceConfigRequest', - 'UpdateInstanceMetadata', - 'UpdateInstanceRequest', -) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/gapic_version.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/gapic_version.py deleted file mode 100644 index 405b1cebcf..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/gapic_version.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -__version__ = "0.1.0" # {x-release-please-version} diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/py.typed b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/py.typed deleted file mode 100644 index 915a8e55e3..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-spanner-admin-instance package uses inline types. diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/__init__.py deleted file mode 100644 index b4e39ea47e..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/__init__.py +++ /dev/null @@ -1,72 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from google.cloud.spanner_admin_instance_v1 import gapic_version as package_version - -__version__ = package_version.__version__ - - -from .services.instance_admin import InstanceAdminClient -from .services.instance_admin import InstanceAdminAsyncClient - -from .types.common import OperationProgress -from .types.spanner_instance_admin import CreateInstanceConfigMetadata -from .types.spanner_instance_admin import CreateInstanceConfigRequest -from .types.spanner_instance_admin import CreateInstanceMetadata -from .types.spanner_instance_admin import CreateInstanceRequest -from .types.spanner_instance_admin import DeleteInstanceConfigRequest -from .types.spanner_instance_admin import DeleteInstanceRequest -from .types.spanner_instance_admin import GetInstanceConfigRequest -from .types.spanner_instance_admin import GetInstanceRequest -from .types.spanner_instance_admin import Instance -from .types.spanner_instance_admin import InstanceConfig -from .types.spanner_instance_admin import ListInstanceConfigOperationsRequest -from .types.spanner_instance_admin import ListInstanceConfigOperationsResponse -from .types.spanner_instance_admin import ListInstanceConfigsRequest -from .types.spanner_instance_admin import ListInstanceConfigsResponse -from .types.spanner_instance_admin import ListInstancesRequest -from .types.spanner_instance_admin import ListInstancesResponse -from .types.spanner_instance_admin import ReplicaInfo -from .types.spanner_instance_admin import UpdateInstanceConfigMetadata -from .types.spanner_instance_admin import UpdateInstanceConfigRequest -from .types.spanner_instance_admin import UpdateInstanceMetadata -from .types.spanner_instance_admin import UpdateInstanceRequest - -__all__ = ( - 'InstanceAdminAsyncClient', -'CreateInstanceConfigMetadata', -'CreateInstanceConfigRequest', -'CreateInstanceMetadata', -'CreateInstanceRequest', -'DeleteInstanceConfigRequest', -'DeleteInstanceRequest', -'GetInstanceConfigRequest', -'GetInstanceRequest', -'Instance', -'InstanceAdminClient', -'InstanceConfig', -'ListInstanceConfigOperationsRequest', -'ListInstanceConfigOperationsResponse', -'ListInstanceConfigsRequest', -'ListInstanceConfigsResponse', -'ListInstancesRequest', -'ListInstancesResponse', -'OperationProgress', -'ReplicaInfo', -'UpdateInstanceConfigMetadata', -'UpdateInstanceConfigRequest', -'UpdateInstanceMetadata', -'UpdateInstanceRequest', -) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_metadata.json b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_metadata.json deleted file mode 100644 index a3ee34c069..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_metadata.json +++ /dev/null @@ -1,238 +0,0 @@ - { - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "python", - "libraryPackage": "google.cloud.spanner_admin_instance_v1", - "protoPackage": "google.spanner.admin.instance.v1", - "schema": "1.0", - "services": { - "InstanceAdmin": { - "clients": { - "grpc": { - "libraryClient": "InstanceAdminClient", - "rpcs": { - "CreateInstance": { - "methods": [ - "create_instance" - ] - }, - "CreateInstanceConfig": { - "methods": [ - "create_instance_config" - ] - }, - "DeleteInstance": { - "methods": [ - "delete_instance" - ] - }, - "DeleteInstanceConfig": { - "methods": [ - "delete_instance_config" - ] - }, - "GetIamPolicy": { - "methods": [ - "get_iam_policy" - ] - }, - "GetInstance": { - "methods": [ - "get_instance" - ] - }, - "GetInstanceConfig": { - "methods": [ - "get_instance_config" - ] - }, - "ListInstanceConfigOperations": { - "methods": [ - "list_instance_config_operations" - ] - }, - "ListInstanceConfigs": { - "methods": [ - "list_instance_configs" - ] - }, - "ListInstances": { - "methods": [ - "list_instances" - ] - }, - "SetIamPolicy": { - "methods": [ - "set_iam_policy" - ] - }, - "TestIamPermissions": { - "methods": [ - "test_iam_permissions" - ] - }, - "UpdateInstance": { - "methods": [ - "update_instance" - ] - }, - "UpdateInstanceConfig": { - "methods": [ - "update_instance_config" - ] - } - } - }, - "grpc-async": { - "libraryClient": "InstanceAdminAsyncClient", - "rpcs": { - "CreateInstance": { - "methods": [ - "create_instance" - ] - }, - "CreateInstanceConfig": { - "methods": [ - "create_instance_config" - ] - }, - "DeleteInstance": { - "methods": [ - "delete_instance" - ] - }, - "DeleteInstanceConfig": { - "methods": [ - "delete_instance_config" - ] - }, - "GetIamPolicy": { - "methods": [ - "get_iam_policy" - ] - }, - "GetInstance": { - "methods": [ - "get_instance" - ] - }, - "GetInstanceConfig": { - "methods": [ - "get_instance_config" - ] - }, - "ListInstanceConfigOperations": { - "methods": [ - "list_instance_config_operations" - ] - }, - "ListInstanceConfigs": { - "methods": [ - "list_instance_configs" - ] - }, - "ListInstances": { - "methods": [ - "list_instances" - ] - }, - "SetIamPolicy": { - "methods": [ - "set_iam_policy" - ] - }, - "TestIamPermissions": { - "methods": [ - "test_iam_permissions" - ] - }, - "UpdateInstance": { - "methods": [ - "update_instance" - ] - }, - "UpdateInstanceConfig": { - "methods": [ - "update_instance_config" - ] - } - } - }, - "rest": { - "libraryClient": "InstanceAdminClient", - "rpcs": { - "CreateInstance": { - "methods": [ - "create_instance" - ] - }, - "CreateInstanceConfig": { - "methods": [ - "create_instance_config" - ] - }, - "DeleteInstance": { - "methods": [ - "delete_instance" - ] - }, - "DeleteInstanceConfig": { - "methods": [ - "delete_instance_config" - ] - }, - "GetIamPolicy": { - "methods": [ - "get_iam_policy" - ] - }, - "GetInstance": { - "methods": [ - "get_instance" - ] - }, - "GetInstanceConfig": { - "methods": [ - "get_instance_config" - ] - }, - "ListInstanceConfigOperations": { - "methods": [ - "list_instance_config_operations" - ] - }, - "ListInstanceConfigs": { - "methods": [ - "list_instance_configs" - ] - }, - "ListInstances": { - "methods": [ - "list_instances" - ] - }, - "SetIamPolicy": { - "methods": [ - "set_iam_policy" - ] - }, - "TestIamPermissions": { - "methods": [ - "test_iam_permissions" - ] - }, - "UpdateInstance": { - "methods": [ - "update_instance" - ] - }, - "UpdateInstanceConfig": { - "methods": [ - "update_instance_config" - ] - } - } - } - } - } - } -} diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_version.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_version.py deleted file mode 100644 index 405b1cebcf..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/gapic_version.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -__version__ = "0.1.0" # {x-release-please-version} diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/py.typed b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/py.typed deleted file mode 100644 index 915a8e55e3..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/py.typed +++ /dev/null @@ -1,2 +0,0 @@ -# Marker file for PEP 561. -# The google-cloud-spanner-admin-instance package uses inline types. diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/__init__.py deleted file mode 100644 index e8e1c3845d..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py deleted file mode 100644 index 4935f1dbc6..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .client import InstanceAdminClient -from .async_client import InstanceAdminAsyncClient - -__all__ = ( - 'InstanceAdminClient', - 'InstanceAdminAsyncClient', -) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py deleted file mode 100644 index 016f8fe122..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py +++ /dev/null @@ -1,2221 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -import functools -import re -from typing import Dict, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union - -from google.cloud.spanner_admin_instance_v1 import gapic_version as package_version - -from google.api_core.client_options import ClientOptions -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore - -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object] # type: ignore - -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.cloud.spanner_admin_instance_v1.services.instance_admin import pagers -from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin -from google.iam.v1 import iam_policy_pb2 # type: ignore -from google.iam.v1 import policy_pb2 # type: ignore -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from .transports.base import InstanceAdminTransport, DEFAULT_CLIENT_INFO -from .transports.grpc_asyncio import InstanceAdminGrpcAsyncIOTransport -from .client import InstanceAdminClient - - -class InstanceAdminAsyncClient: - """Cloud Spanner Instance Admin API - The Cloud Spanner Instance Admin API can be used to create, - delete, modify and list instances. Instances are dedicated Cloud - Spanner serving and storage resources to be used by Cloud - Spanner databases. - Each instance has a "configuration", which dictates where the - serving resources for the Cloud Spanner instance are located - (e.g., US-central, Europe). Configurations are created by Google - based on resource availability. - - Cloud Spanner billing is based on the instances that exist and - their sizes. After an instance exists, there are no additional - per-database or per-operation charges for use of the instance - (though there may be additional network bandwidth charges). - Instances offer isolation: problems with databases in one - instance will not affect other instances. However, within an - instance databases can affect each other. For example, if one - database in an instance receives a lot of requests and consumes - most of the instance resources, fewer resources are available - for other databases in that instance, and their performance may - suffer. - """ - - _client: InstanceAdminClient - - DEFAULT_ENDPOINT = InstanceAdminClient.DEFAULT_ENDPOINT - DEFAULT_MTLS_ENDPOINT = InstanceAdminClient.DEFAULT_MTLS_ENDPOINT - - instance_path = staticmethod(InstanceAdminClient.instance_path) - parse_instance_path = staticmethod(InstanceAdminClient.parse_instance_path) - instance_config_path = staticmethod(InstanceAdminClient.instance_config_path) - parse_instance_config_path = staticmethod(InstanceAdminClient.parse_instance_config_path) - common_billing_account_path = staticmethod(InstanceAdminClient.common_billing_account_path) - parse_common_billing_account_path = staticmethod(InstanceAdminClient.parse_common_billing_account_path) - common_folder_path = staticmethod(InstanceAdminClient.common_folder_path) - parse_common_folder_path = staticmethod(InstanceAdminClient.parse_common_folder_path) - common_organization_path = staticmethod(InstanceAdminClient.common_organization_path) - parse_common_organization_path = staticmethod(InstanceAdminClient.parse_common_organization_path) - common_project_path = staticmethod(InstanceAdminClient.common_project_path) - parse_common_project_path = staticmethod(InstanceAdminClient.parse_common_project_path) - common_location_path = staticmethod(InstanceAdminClient.common_location_path) - parse_common_location_path = staticmethod(InstanceAdminClient.parse_common_location_path) - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - InstanceAdminAsyncClient: The constructed client. - """ - return InstanceAdminClient.from_service_account_info.__func__(InstanceAdminAsyncClient, info, *args, **kwargs) # type: ignore - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - InstanceAdminAsyncClient: The constructed client. - """ - return InstanceAdminClient.from_service_account_file.__func__(InstanceAdminAsyncClient, filename, *args, **kwargs) # type: ignore - - from_service_account_json = from_service_account_file - - @classmethod - def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[ClientOptions] = None): - """Return the API endpoint and client cert source for mutual TLS. - - The client cert source is determined in the following order: - (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the - client cert source is None. - (2) if `client_options.client_cert_source` is provided, use the provided one; if the - default client cert source exists, use the default one; otherwise the client cert - source is None. - - The API endpoint is determined in the following order: - (1) if `client_options.api_endpoint` if provided, use the provided one. - (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the - default mTLS endpoint; if the environment variable is "never", use the default API - endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise - use the default API endpoint. - - More details can be found at https://google.aip.dev/auth/4114. - - Args: - client_options (google.api_core.client_options.ClientOptions): Custom options for the - client. Only the `api_endpoint` and `client_cert_source` properties may be used - in this method. - - Returns: - Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the - client cert source to use. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If any errors happen. - """ - return InstanceAdminClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore - - @property - def transport(self) -> InstanceAdminTransport: - """Returns the transport used by the client instance. - - Returns: - InstanceAdminTransport: The transport used by the client instance. - """ - return self._client.transport - - get_transport_class = functools.partial(type(InstanceAdminClient).get_transport_class, type(InstanceAdminClient)) - - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Union[str, InstanceAdminTransport] = "grpc_asyncio", - client_options: Optional[ClientOptions] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the instance admin client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Union[str, ~.InstanceAdminTransport]): The - transport to use. If set to None, a transport is chosen - automatically. - client_options (ClientOptions): Custom options for the client. It - won't take effect if a ``transport`` instance is provided. - (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT - environment variable can also be used to override the endpoint: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto switch to the - default mTLS endpoint if client certificate is present, this is - the default value). However, the ``api_endpoint`` property takes - precedence if provided. - (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide client certificate for mutual TLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - """ - self._client = InstanceAdminClient( - credentials=credentials, - transport=transport, - client_options=client_options, - client_info=client_info, - - ) - - async def list_instance_configs(self, - request: Optional[Union[spanner_instance_admin.ListInstanceConfigsRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListInstanceConfigsAsyncPager: - r"""Lists the supported instance configurations for a - given project. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - async def sample_list_instance_configs(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.ListInstanceConfigsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_instance_configs(request=request) - - # Handle the response - async for response in page_result: - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest, dict]]): - The request object. The request for - [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. - parent (:class:`str`): - Required. The name of the project for which a list of - supported instance configurations is requested. Values - are of the form ``projects/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigsAsyncPager: - The response for - [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_instance_admin.ListInstanceConfigsRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_instance_configs, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListInstanceConfigsAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def get_instance_config(self, - request: Optional[Union[spanner_instance_admin.GetInstanceConfigRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner_instance_admin.InstanceConfig: - r"""Gets information about a particular instance - configuration. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - async def sample_get_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.GetInstanceConfigRequest( - name="name_value", - ) - - # Make the request - response = await client.get_instance_config(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest, dict]]): - The request object. The request for - [GetInstanceConfigRequest][google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig]. - name (:class:`str`): - Required. The name of the requested instance - configuration. Values are of the form - ``projects//instanceConfigs/``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_instance_v1.types.InstanceConfig: - A possible configuration for a Cloud - Spanner instance. Configurations define - the geographic placement of nodes and - their replication. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_instance_admin.GetInstanceConfigRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_instance_config, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def create_instance_config(self, - request: Optional[Union[spanner_instance_admin.CreateInstanceConfigRequest, dict]] = None, - *, - parent: Optional[str] = None, - instance_config: Optional[spanner_instance_admin.InstanceConfig] = None, - instance_config_id: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Creates an instance config and begins preparing it to be used. - The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of preparing the new instance config. The instance - config name is assigned by the caller. If the named instance - config already exists, ``CreateInstanceConfig`` returns - ``ALREADY_EXISTS``. - - Immediately after the request returns: - - - The instance config is readable via the API, with all - requested attributes. The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field is set to true. Its state is ``CREATING``. - - While the operation is pending: - - - Cancelling the operation renders the instance config - immediately unreadable via the API. - - Except for deleting the creating resource, all other attempts - to modify the instance config are rejected. - - Upon completion of the returned operation: - - - Instances can be created using the instance configuration. - - The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field becomes false. Its state becomes ``READY``. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and - can be used to track creation of the instance config. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. - The [response][google.longrunning.Operation.response] field type - is - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], - if successful. - - Authorization requires ``spanner.instanceConfigs.create`` - permission on the resource - [parent][google.spanner.admin.instance.v1.CreateInstanceConfigRequest.parent]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - async def sample_create_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.CreateInstanceConfigRequest( - parent="parent_value", - instance_config_id="instance_config_id_value", - ) - - # Make the request - operation = client.create_instance_config(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.CreateInstanceConfigRequest, dict]]): - The request object. The request for - [CreateInstanceConfigRequest][InstanceAdmin.CreateInstanceConfigRequest]. - parent (:class:`str`): - Required. The name of the project in which to create the - instance config. Values are of the form - ``projects/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - instance_config (:class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig`): - Required. The InstanceConfig proto of the configuration - to create. instance_config.name must be - ``/instanceConfigs/``. - instance_config.base_config must be a Google managed - configuration name, e.g. /instanceConfigs/us-east1, - /instanceConfigs/nam3. - - This corresponds to the ``instance_config`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - instance_config_id (:class:`str`): - Required. The ID of the instance config to create. Valid - identifiers are of the form - ``custom-[-a-z0-9]*[a-z0-9]`` and must be between 2 and - 64 characters in length. The ``custom-`` prefix is - required to avoid name conflicts with Google managed - configurations. - - This corresponds to the ``instance_config_id`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be :class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig` A possible configuration for a Cloud Spanner instance. Configurations - define the geographic placement of nodes and their - replication. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, instance_config, instance_config_id]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_instance_admin.CreateInstanceConfigRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if instance_config is not None: - request.instance_config = instance_config - if instance_config_id is not None: - request.instance_config_id = instance_config_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.create_instance_config, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - spanner_instance_admin.InstanceConfig, - metadata_type=spanner_instance_admin.CreateInstanceConfigMetadata, - ) - - # Done; return the response. - return response - - async def update_instance_config(self, - request: Optional[Union[spanner_instance_admin.UpdateInstanceConfigRequest, dict]] = None, - *, - instance_config: Optional[spanner_instance_admin.InstanceConfig] = None, - update_mask: Optional[field_mask_pb2.FieldMask] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Updates an instance config. The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of updating the instance. If the named instance - config does not exist, returns ``NOT_FOUND``. - - Only user managed configurations can be updated. - - Immediately after the request returns: - - - The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field is set to true. - - While the operation is pending: - - - Cancelling the operation sets its metadata's - [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata.cancel_time]. - The operation is guaranteed to succeed at undoing all - changes, after which point it terminates with a ``CANCELLED`` - status. - - All other attempts to modify the instance config are - rejected. - - Reading the instance config via the API continues to give the - pre-request values. - - Upon completion of the returned operation: - - - Creating instances using the instance configuration uses the - new values. - - The instance config's new values are readable via the API. - - The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field becomes false. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and - can be used to track the instance config modification. The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateInstanceConfigMetadata][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata]. - The [response][google.longrunning.Operation.response] field type - is - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], - if successful. - - Authorization requires ``spanner.instanceConfigs.update`` - permission on the resource - [name][google.spanner.admin.instance.v1.InstanceConfig.name]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - async def sample_update_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.UpdateInstanceConfigRequest( - ) - - # Make the request - operation = client.update_instance_config(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstanceConfigRequest, dict]]): - The request object. The request for - [UpdateInstanceConfigRequest][InstanceAdmin.UpdateInstanceConfigRequest]. - instance_config (:class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig`): - Required. The user instance config to update, which must - always include the instance config name. Otherwise, only - fields mentioned in - [update_mask][google.spanner.admin.instance.v1.UpdateInstanceConfigRequest.update_mask] - need be included. To prevent conflicts of concurrent - updates, - [etag][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - can be used. - - This corresponds to the ``instance_config`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - Required. A mask specifying which fields in - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] - should be updated. The field mask must always be - specified; this prevents any future fields in - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] - from being erased accidentally by clients that do not - know about them. Only display_name and labels can be - updated. - - This corresponds to the ``update_mask`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be :class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig` A possible configuration for a Cloud Spanner instance. Configurations - define the geographic placement of nodes and their - replication. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([instance_config, update_mask]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_instance_admin.UpdateInstanceConfigRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if instance_config is not None: - request.instance_config = instance_config - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_instance_config, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("instance_config.name", request.instance_config.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - spanner_instance_admin.InstanceConfig, - metadata_type=spanner_instance_admin.UpdateInstanceConfigMetadata, - ) - - # Done; return the response. - return response - - async def delete_instance_config(self, - request: Optional[Union[spanner_instance_admin.DeleteInstanceConfigRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Deletes the instance config. Deletion is only allowed when no - instances are using the configuration. If any instances are - using the config, returns ``FAILED_PRECONDITION``. - - Only user managed configurations can be deleted. - - Authorization requires ``spanner.instanceConfigs.delete`` - permission on the resource - [name][google.spanner.admin.instance.v1.InstanceConfig.name]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - async def sample_delete_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.DeleteInstanceConfigRequest( - name="name_value", - ) - - # Make the request - await client.delete_instance_config(request=request) - - Args: - request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstanceConfigRequest, dict]]): - The request object. The request for - [DeleteInstanceConfigRequest][InstanceAdmin.DeleteInstanceConfigRequest]. - name (:class:`str`): - Required. The name of the instance configuration to be - deleted. Values are of the form - ``projects//instanceConfigs/`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_instance_admin.DeleteInstanceConfigRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.delete_instance_config, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def list_instance_config_operations(self, - request: Optional[Union[spanner_instance_admin.ListInstanceConfigOperationsRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListInstanceConfigOperationsAsyncPager: - r"""Lists the user-managed instance config [long-running - operations][google.longrunning.Operation] in the given project. - An instance config operation has a name of the form - ``projects//instanceConfigs//operations/``. - The long-running operation - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - Operations returned include those that have - completed/failed/canceled within the last 7 days, and pending - operations. Operations returned are ordered by - ``operation.metadata.value.start_time`` in descending order - starting from the most recently started operation. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - async def sample_list_instance_config_operations(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.ListInstanceConfigOperationsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_instance_config_operations(request=request) - - # Handle the response - async for response in page_result: - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest, dict]]): - The request object. The request for - [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. - parent (:class:`str`): - Required. The project of the instance config operations. - Values are of the form ``projects/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigOperationsAsyncPager: - The response for - [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_instance_admin.ListInstanceConfigOperationsRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_instance_config_operations, - default_timeout=None, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListInstanceConfigOperationsAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def list_instances(self, - request: Optional[Union[spanner_instance_admin.ListInstancesRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListInstancesAsyncPager: - r"""Lists all instances in the given project. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - async def sample_list_instances(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.ListInstancesRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_instances(request=request) - - # Handle the response - async for response in page_result: - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest, dict]]): - The request object. The request for - [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. - parent (:class:`str`): - Required. The name of the project for which a list of - instances is requested. Values are of the form - ``projects/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancesAsyncPager: - The response for - [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_instance_admin.ListInstancesRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.list_instances, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__aiter__` convenience method. - response = pagers.ListInstancesAsyncPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def get_instance(self, - request: Optional[Union[spanner_instance_admin.GetInstanceRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner_instance_admin.Instance: - r"""Gets information about a particular instance. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - async def sample_get_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.GetInstanceRequest( - name="name_value", - ) - - # Make the request - response = await client.get_instance(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest, dict]]): - The request object. The request for - [GetInstance][google.spanner.admin.instance.v1.InstanceAdmin.GetInstance]. - name (:class:`str`): - Required. The name of the requested instance. Values are - of the form ``projects//instances/``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_instance_v1.types.Instance: - An isolated set of Cloud Spanner - resources on which databases can be - hosted. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_instance_admin.GetInstanceRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_instance, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def create_instance(self, - request: Optional[Union[spanner_instance_admin.CreateInstanceRequest, dict]] = None, - *, - parent: Optional[str] = None, - instance_id: Optional[str] = None, - instance: Optional[spanner_instance_admin.Instance] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Creates an instance and begins preparing it to begin serving. - The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of preparing the new instance. The instance name is - assigned by the caller. If the named instance already exists, - ``CreateInstance`` returns ``ALREADY_EXISTS``. - - Immediately upon completion of this request: - - - The instance is readable via the API, with all requested - attributes but no allocated resources. Its state is - ``CREATING``. - - Until completion of the returned operation: - - - Cancelling the operation renders the instance immediately - unreadable via the API. - - The instance can be deleted. - - All other attempts to modify the instance are rejected. - - Upon completion of the returned operation: - - - Billing for all successfully-allocated resources begins (some - types may have lower than the requested levels). - - Databases can be created in the instance. - - The instance's allocated resource levels are readable via the - API. - - The instance's state becomes ``READY``. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and can be - used to track creation of the instance. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateInstanceMetadata][google.spanner.admin.instance.v1.CreateInstanceMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Instance][google.spanner.admin.instance.v1.Instance], if - successful. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - async def sample_create_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - instance = spanner_admin_instance_v1.Instance() - instance.name = "name_value" - instance.config = "config_value" - instance.display_name = "display_name_value" - - request = spanner_admin_instance_v1.CreateInstanceRequest( - parent="parent_value", - instance_id="instance_id_value", - instance=instance, - ) - - # Make the request - operation = client.create_instance(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.CreateInstanceRequest, dict]]): - The request object. The request for - [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance]. - parent (:class:`str`): - Required. The name of the project in which to create the - instance. Values are of the form ``projects/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - instance_id (:class:`str`): - Required. The ID of the instance to create. Valid - identifiers are of the form ``[a-z][-a-z0-9]*[a-z0-9]`` - and must be between 2 and 64 characters in length. - - This corresponds to the ``instance_id`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - instance (:class:`google.cloud.spanner_admin_instance_v1.types.Instance`): - Required. The instance to create. The name may be - omitted, but if specified must be - ``/instances/``. - - This corresponds to the ``instance`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.spanner_admin_instance_v1.types.Instance` - An isolated set of Cloud Spanner resources on which - databases can be hosted. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, instance_id, instance]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_instance_admin.CreateInstanceRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if instance_id is not None: - request.instance_id = instance_id - if instance is not None: - request.instance = instance - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.create_instance, - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - spanner_instance_admin.Instance, - metadata_type=spanner_instance_admin.CreateInstanceMetadata, - ) - - # Done; return the response. - return response - - async def update_instance(self, - request: Optional[Union[spanner_instance_admin.UpdateInstanceRequest, dict]] = None, - *, - instance: Optional[spanner_instance_admin.Instance] = None, - field_mask: Optional[field_mask_pb2.FieldMask] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation_async.AsyncOperation: - r"""Updates an instance, and begins allocating or releasing - resources as requested. The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of updating the instance. If the named instance - does not exist, returns ``NOT_FOUND``. - - Immediately upon completion of this request: - - - For resource types for which a decrease in the instance's - allocation has been requested, billing is based on the - newly-requested level. - - Until completion of the returned operation: - - - Cancelling the operation sets its metadata's - [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceMetadata.cancel_time], - and begins restoring resources to their pre-request values. - The operation is guaranteed to succeed at undoing all - resource changes, after which point it terminates with a - ``CANCELLED`` status. - - All other attempts to modify the instance are rejected. - - Reading the instance via the API continues to give the - pre-request resource levels. - - Upon completion of the returned operation: - - - Billing begins for all successfully-allocated resources (some - types may have lower than the requested levels). - - All newly-reserved resources are available for serving the - instance's tables. - - The instance's new resource levels are readable via the API. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and can be - used to track the instance modification. The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateInstanceMetadata][google.spanner.admin.instance.v1.UpdateInstanceMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Instance][google.spanner.admin.instance.v1.Instance], if - successful. - - Authorization requires ``spanner.instances.update`` permission - on the resource - [name][google.spanner.admin.instance.v1.Instance.name]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - async def sample_update_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - instance = spanner_admin_instance_v1.Instance() - instance.name = "name_value" - instance.config = "config_value" - instance.display_name = "display_name_value" - - request = spanner_admin_instance_v1.UpdateInstanceRequest( - instance=instance, - ) - - # Make the request - operation = client.update_instance(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstanceRequest, dict]]): - The request object. The request for - [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance]. - instance (:class:`google.cloud.spanner_admin_instance_v1.types.Instance`): - Required. The instance to update, which must always - include the instance name. Otherwise, only fields - mentioned in - [field_mask][google.spanner.admin.instance.v1.UpdateInstanceRequest.field_mask] - need be included. - - This corresponds to the ``instance`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - field_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - Required. A mask specifying which fields in - [Instance][google.spanner.admin.instance.v1.Instance] - should be updated. The field mask must always be - specified; this prevents any future fields in - [Instance][google.spanner.admin.instance.v1.Instance] - from being erased accidentally by clients that do not - know about them. - - This corresponds to the ``field_mask`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation_async.AsyncOperation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.spanner_admin_instance_v1.types.Instance` - An isolated set of Cloud Spanner resources on which - databases can be hosted. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([instance, field_mask]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_instance_admin.UpdateInstanceRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if instance is not None: - request.instance = instance - if field_mask is not None: - request.field_mask = field_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.update_instance, - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("instance.name", request.instance.name), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation_async.from_gapic( - response, - self._client._transport.operations_client, - spanner_instance_admin.Instance, - metadata_type=spanner_instance_admin.UpdateInstanceMetadata, - ) - - # Done; return the response. - return response - - async def delete_instance(self, - request: Optional[Union[spanner_instance_admin.DeleteInstanceRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Deletes an instance. - - Immediately upon completion of the request: - - - Billing ceases for all of the instance's reserved resources. - - Soon afterward: - - - The instance and *all of its databases* immediately and - irrevocably disappear from the API. All data in the databases - is permanently deleted. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - async def sample_delete_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.DeleteInstanceRequest( - name="name_value", - ) - - # Make the request - await client.delete_instance(request=request) - - Args: - request (Optional[Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstanceRequest, dict]]): - The request object. The request for - [DeleteInstance][google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance]. - name (:class:`str`): - Required. The name of the instance to be deleted. Values - are of the form - ``projects//instances/`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - request = spanner_instance_admin.DeleteInstanceRequest(request) - - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.delete_instance, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - async def set_iam_policy(self, - request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, - *, - resource: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> policy_pb2.Policy: - r"""Sets the access control policy on an instance resource. Replaces - any existing policy. - - Authorization requires ``spanner.instances.setIamPolicy`` on - [resource][google.iam.v1.SetIamPolicyRequest.resource]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - from google.iam.v1 import iam_policy_pb2 # type: ignore - - async def sample_set_iam_policy(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = iam_policy_pb2.SetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = await client.set_iam_policy(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]]): - The request object. Request message for ``SetIamPolicy`` method. - resource (:class:`str`): - REQUIRED: The resource for which the - policy is being specified. See the - operation documentation for the - appropriate value for this field. - - This corresponds to the ``resource`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.iam.v1.policy_pb2.Policy: - An Identity and Access Management (IAM) policy, which specifies access - controls for Google Cloud resources. - - A Policy is a collection of bindings. A binding binds - one or more members, or principals, to a single role. - Principals can be user accounts, service accounts, - Google groups, and domains (such as G Suite). A role - is a named list of permissions; each role can be an - IAM predefined role or a user-created custom role. - - For some types of Google Cloud resources, a binding - can also specify a condition, which is a logical - expression that allows access to a resource only if - the expression evaluates to true. A condition can add - constraints based on attributes of the request, the - resource, or both. To learn which resources support - conditions in their IAM policies, see the [IAM - documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). - - **JSON example:** - - { - "bindings": [ - { - "role": - "roles/resourcemanager.organizationAdmin", - "members": [ "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - - }, { "role": - "roles/resourcemanager.organizationViewer", - "members": [ "user:eve@example.com" ], - "condition": { "title": "expirable access", - "description": "Does not grant access after - Sep 2020", "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", } } - - ], "etag": "BwWWja0YfJA=", "version": 3 - - } - - **YAML example:** - - bindings: - members: - user:\ mike@example.com - - group:\ admins@example.com - domain:google.com - - serviceAccount:\ my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - user:\ eve@example.com role: - roles/resourcemanager.organizationViewer - condition: title: expirable access description: - Does not grant access after Sep 2020 expression: - request.time < - timestamp('2020-10-01T00:00:00.000Z') etag: - BwWWja0YfJA= version: 3 - - For a description of IAM and its features, see the - [IAM - documentation](\ https://cloud.google.com/iam/docs/). - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([resource]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) - elif not request: - request = iam_policy_pb2.SetIamPolicyRequest(resource=resource, ) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.set_iam_policy, - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("resource", request.resource), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def get_iam_policy(self, - request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, - *, - resource: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> policy_pb2.Policy: - r"""Gets the access control policy for an instance resource. Returns - an empty policy if an instance exists but does not have a policy - set. - - Authorization requires ``spanner.instances.getIamPolicy`` on - [resource][google.iam.v1.GetIamPolicyRequest.resource]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - from google.iam.v1 import iam_policy_pb2 # type: ignore - - async def sample_get_iam_policy(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = iam_policy_pb2.GetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = await client.get_iam_policy(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]]): - The request object. Request message for ``GetIamPolicy`` method. - resource (:class:`str`): - REQUIRED: The resource for which the - policy is being requested. See the - operation documentation for the - appropriate value for this field. - - This corresponds to the ``resource`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.iam.v1.policy_pb2.Policy: - An Identity and Access Management (IAM) policy, which specifies access - controls for Google Cloud resources. - - A Policy is a collection of bindings. A binding binds - one or more members, or principals, to a single role. - Principals can be user accounts, service accounts, - Google groups, and domains (such as G Suite). A role - is a named list of permissions; each role can be an - IAM predefined role or a user-created custom role. - - For some types of Google Cloud resources, a binding - can also specify a condition, which is a logical - expression that allows access to a resource only if - the expression evaluates to true. A condition can add - constraints based on attributes of the request, the - resource, or both. To learn which resources support - conditions in their IAM policies, see the [IAM - documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). - - **JSON example:** - - { - "bindings": [ - { - "role": - "roles/resourcemanager.organizationAdmin", - "members": [ "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - - }, { "role": - "roles/resourcemanager.organizationViewer", - "members": [ "user:eve@example.com" ], - "condition": { "title": "expirable access", - "description": "Does not grant access after - Sep 2020", "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", } } - - ], "etag": "BwWWja0YfJA=", "version": 3 - - } - - **YAML example:** - - bindings: - members: - user:\ mike@example.com - - group:\ admins@example.com - domain:google.com - - serviceAccount:\ my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - user:\ eve@example.com role: - roles/resourcemanager.organizationViewer - condition: title: expirable access description: - Does not grant access after Sep 2020 expression: - request.time < - timestamp('2020-10-01T00:00:00.000Z') etag: - BwWWja0YfJA= version: 3 - - For a description of IAM and its features, see the - [IAM - documentation](\ https://cloud.google.com/iam/docs/). - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([resource]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) - elif not request: - request = iam_policy_pb2.GetIamPolicyRequest(resource=resource, ) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.get_iam_policy, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("resource", request.resource), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def test_iam_permissions(self, - request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, - *, - resource: Optional[str] = None, - permissions: Optional[MutableSequence[str]] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> iam_policy_pb2.TestIamPermissionsResponse: - r"""Returns permissions that the caller has on the specified - instance resource. - - Attempting this RPC on a non-existent Cloud Spanner instance - resource will result in a NOT_FOUND error if the user has - ``spanner.instances.list`` permission on the containing Google - Cloud Project. Otherwise returns an empty set of permissions. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - from google.iam.v1 import iam_policy_pb2 # type: ignore - - async def sample_test_iam_permissions(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = iam_policy_pb2.TestIamPermissionsRequest( - resource="resource_value", - permissions=['permissions_value1', 'permissions_value2'], - ) - - # Make the request - response = await client.test_iam_permissions(request=request) - - # Handle the response - print(response) - - Args: - request (Optional[Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]]): - The request object. Request message for ``TestIamPermissions`` method. - resource (:class:`str`): - REQUIRED: The resource for which the - policy detail is being requested. See - the operation documentation for the - appropriate value for this field. - - This corresponds to the ``resource`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - permissions (:class:`MutableSequence[str]`): - The set of permissions to check for the ``resource``. - Permissions with wildcards (such as '*' or 'storage.*') - are not allowed. For more information see `IAM - Overview `__. - - This corresponds to the ``permissions`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: - Response message for TestIamPermissions method. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([resource, permissions]) - if request is not None and has_flattened_params: - raise ValueError("If the `request` argument is set, then none of " - "the individual field arguments should be set.") - - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) - elif not request: - request = iam_policy_pb2.TestIamPermissionsRequest(resource=resource, permissions=permissions, ) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = gapic_v1.method_async.wrap_method( - self._client._transport.test_iam_permissions, - default_timeout=30.0, - client_info=DEFAULT_CLIENT_INFO, - ) - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("resource", request.resource), - )), - ) - - # Send the request. - response = await rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - async def __aenter__(self): - return self - - async def __aexit__(self, exc_type, exc, tb): - await self.transport.close() - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - - -__all__ = ( - "InstanceAdminAsyncClient", -) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py deleted file mode 100644 index 098e55469d..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py +++ /dev/null @@ -1,2391 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -import os -import re -from typing import Dict, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast - -from google.cloud.spanner_admin_instance_v1 import gapic_version as package_version - -from google.api_core import client_options as client_options_lib -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry as retries -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport import mtls # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore -from google.oauth2 import service_account # type: ignore - -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object] # type: ignore - -from google.api_core import operation # type: ignore -from google.api_core import operation_async # type: ignore -from google.cloud.spanner_admin_instance_v1.services.instance_admin import pagers -from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin -from google.iam.v1 import iam_policy_pb2 # type: ignore -from google.iam.v1 import policy_pb2 # type: ignore -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from .transports.base import InstanceAdminTransport, DEFAULT_CLIENT_INFO -from .transports.grpc import InstanceAdminGrpcTransport -from .transports.grpc_asyncio import InstanceAdminGrpcAsyncIOTransport -from .transports.rest import InstanceAdminRestTransport - - -class InstanceAdminClientMeta(type): - """Metaclass for the InstanceAdmin client. - - This provides class-level methods for building and retrieving - support objects (e.g. transport) without polluting the client instance - objects. - """ - _transport_registry = OrderedDict() # type: Dict[str, Type[InstanceAdminTransport]] - _transport_registry["grpc"] = InstanceAdminGrpcTransport - _transport_registry["grpc_asyncio"] = InstanceAdminGrpcAsyncIOTransport - _transport_registry["rest"] = InstanceAdminRestTransport - - def get_transport_class(cls, - label: Optional[str] = None, - ) -> Type[InstanceAdminTransport]: - """Returns an appropriate transport class. - - Args: - label: The name of the desired transport. If none is - provided, then the first transport in the registry is used. - - Returns: - The transport class to use. - """ - # If a specific transport is requested, return that one. - if label: - return cls._transport_registry[label] - - # No transport is requested; return the default (that is, the first one - # in the dictionary). - return next(iter(cls._transport_registry.values())) - - -class InstanceAdminClient(metaclass=InstanceAdminClientMeta): - """Cloud Spanner Instance Admin API - The Cloud Spanner Instance Admin API can be used to create, - delete, modify and list instances. Instances are dedicated Cloud - Spanner serving and storage resources to be used by Cloud - Spanner databases. - Each instance has a "configuration", which dictates where the - serving resources for the Cloud Spanner instance are located - (e.g., US-central, Europe). Configurations are created by Google - based on resource availability. - - Cloud Spanner billing is based on the instances that exist and - their sizes. After an instance exists, there are no additional - per-database or per-operation charges for use of the instance - (though there may be additional network bandwidth charges). - Instances offer isolation: problems with databases in one - instance will not affect other instances. However, within an - instance databases can affect each other. For example, if one - database in an instance receives a lot of requests and consumes - most of the instance resources, fewer resources are available - for other databases in that instance, and their performance may - suffer. - """ - - @staticmethod - def _get_default_mtls_endpoint(api_endpoint): - """Converts api endpoint to mTLS endpoint. - - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. - Args: - api_endpoint (Optional[str]): the api endpoint to convert. - Returns: - str: converted mTLS api endpoint. - """ - if not api_endpoint: - return api_endpoint - - mtls_endpoint_re = re.compile( - r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" - ) - - m = mtls_endpoint_re.match(api_endpoint) - name, mtls, sandbox, googledomain = m.groups() - if mtls or not googledomain: - return api_endpoint - - if sandbox: - return api_endpoint.replace( - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" - ) - - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") - - DEFAULT_ENDPOINT = "spanner.googleapis.com" - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore - DEFAULT_ENDPOINT - ) - - @classmethod - def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials - info. - - Args: - info (dict): The service account private key info. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - InstanceAdminClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_info(info) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - @classmethod - def from_service_account_file(cls, filename: str, *args, **kwargs): - """Creates an instance of this client using the provided credentials - file. - - Args: - filename (str): The path to the service account private key json - file. - args: Additional arguments to pass to the constructor. - kwargs: Additional arguments to pass to the constructor. - - Returns: - InstanceAdminClient: The constructed client. - """ - credentials = service_account.Credentials.from_service_account_file( - filename) - kwargs["credentials"] = credentials - return cls(*args, **kwargs) - - from_service_account_json = from_service_account_file - - @property - def transport(self) -> InstanceAdminTransport: - """Returns the transport used by the client instance. - - Returns: - InstanceAdminTransport: The transport used by the client - instance. - """ - return self._transport - - @staticmethod - def instance_path(project: str,instance: str,) -> str: - """Returns a fully-qualified instance string.""" - return "projects/{project}/instances/{instance}".format(project=project, instance=instance, ) - - @staticmethod - def parse_instance_path(path: str) -> Dict[str,str]: - """Parses a instance path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/instances/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def instance_config_path(project: str,instance_config: str,) -> str: - """Returns a fully-qualified instance_config string.""" - return "projects/{project}/instanceConfigs/{instance_config}".format(project=project, instance_config=instance_config, ) - - @staticmethod - def parse_instance_config_path(path: str) -> Dict[str,str]: - """Parses a instance_config path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/instanceConfigs/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_billing_account_path(billing_account: str, ) -> str: - """Returns a fully-qualified billing_account string.""" - return "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - - @staticmethod - def parse_common_billing_account_path(path: str) -> Dict[str,str]: - """Parse a billing_account path into its component segments.""" - m = re.match(r"^billingAccounts/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_folder_path(folder: str, ) -> str: - """Returns a fully-qualified folder string.""" - return "folders/{folder}".format(folder=folder, ) - - @staticmethod - def parse_common_folder_path(path: str) -> Dict[str,str]: - """Parse a folder path into its component segments.""" - m = re.match(r"^folders/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_organization_path(organization: str, ) -> str: - """Returns a fully-qualified organization string.""" - return "organizations/{organization}".format(organization=organization, ) - - @staticmethod - def parse_common_organization_path(path: str) -> Dict[str,str]: - """Parse a organization path into its component segments.""" - m = re.match(r"^organizations/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_project_path(project: str, ) -> str: - """Returns a fully-qualified project string.""" - return "projects/{project}".format(project=project, ) - - @staticmethod - def parse_common_project_path(path: str) -> Dict[str,str]: - """Parse a project path into its component segments.""" - m = re.match(r"^projects/(?P.+?)$", path) - return m.groupdict() if m else {} - - @staticmethod - def common_location_path(project: str, location: str, ) -> str: - """Returns a fully-qualified location string.""" - return "projects/{project}/locations/{location}".format(project=project, location=location, ) - - @staticmethod - def parse_common_location_path(path: str) -> Dict[str,str]: - """Parse a location path into its component segments.""" - m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) - return m.groupdict() if m else {} - - @classmethod - def get_mtls_endpoint_and_cert_source(cls, client_options: Optional[client_options_lib.ClientOptions] = None): - """Return the API endpoint and client cert source for mutual TLS. - - The client cert source is determined in the following order: - (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the - client cert source is None. - (2) if `client_options.client_cert_source` is provided, use the provided one; if the - default client cert source exists, use the default one; otherwise the client cert - source is None. - - The API endpoint is determined in the following order: - (1) if `client_options.api_endpoint` if provided, use the provided one. - (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the - default mTLS endpoint; if the environment variable is "never", use the default API - endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise - use the default API endpoint. - - More details can be found at https://google.aip.dev/auth/4114. - - Args: - client_options (google.api_core.client_options.ClientOptions): Custom options for the - client. Only the `api_endpoint` and `client_cert_source` properties may be used - in this method. - - Returns: - Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the - client cert source to use. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If any errors happen. - """ - if client_options is None: - client_options = client_options_lib.ClientOptions() - use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") - use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_client_cert not in ("true", "false"): - raise ValueError("Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`") - if use_mtls_endpoint not in ("auto", "never", "always"): - raise MutualTLSChannelError("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`") - - # Figure out the client cert source to use. - client_cert_source = None - if use_client_cert == "true": - if client_options.client_cert_source: - client_cert_source = client_options.client_cert_source - elif mtls.has_default_client_cert_source(): - client_cert_source = mtls.default_client_cert_source() - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source): - api_endpoint = cls.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = cls.DEFAULT_ENDPOINT - - return api_endpoint, client_cert_source - - def __init__(self, *, - credentials: Optional[ga_credentials.Credentials] = None, - transport: Optional[Union[str, InstanceAdminTransport]] = None, - client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - ) -> None: - """Instantiates the instance admin client. - - Args: - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - transport (Union[str, InstanceAdminTransport]): The - transport to use. If set to None, a transport is chosen - automatically. - client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the - client. It won't take effect if a ``transport`` instance is provided. - (1) The ``api_endpoint`` property can be used to override the - default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT - environment variable can also be used to override the endpoint: - "always" (always use the default mTLS endpoint), "never" (always - use the default regular endpoint) and "auto" (auto switch to the - default mTLS endpoint if client certificate is present, this is - the default value). However, the ``api_endpoint`` property takes - precedence if provided. - (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable - is "true", then the ``client_cert_source`` property can be used - to provide client certificate for mutual TLS transport. If - not provided, the default SSL client certificate will be used if - present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not - set, no client certificate will be used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - """ - if isinstance(client_options, dict): - client_options = client_options_lib.from_dict(client_options) - if client_options is None: - client_options = client_options_lib.ClientOptions() - client_options = cast(client_options_lib.ClientOptions, client_options) - - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source(client_options) - - api_key_value = getattr(client_options, "api_key", None) - if api_key_value and credentials: - raise ValueError("client_options.api_key and credentials are mutually exclusive") - - # Save or instantiate the transport. - # Ordinarily, we provide the transport, but allowing a custom transport - # instance provides an extensibility point for unusual situations. - if isinstance(transport, InstanceAdminTransport): - # transport is a InstanceAdminTransport instance. - if credentials or client_options.credentials_file or api_key_value: - raise ValueError("When providing a transport instance, " - "provide its credentials directly.") - if client_options.scopes: - raise ValueError( - "When providing a transport instance, provide its scopes " - "directly." - ) - self._transport = transport - else: - import google.auth._default # type: ignore - - if api_key_value and hasattr(google.auth._default, "get_api_key_credentials"): - credentials = google.auth._default.get_api_key_credentials(api_key_value) - - Transport = type(self).get_transport_class(transport) - self._transport = Transport( - credentials=credentials, - credentials_file=client_options.credentials_file, - host=api_endpoint, - scopes=client_options.scopes, - client_cert_source_for_mtls=client_cert_source_func, - quota_project_id=client_options.quota_project_id, - client_info=client_info, - always_use_jwt_access=True, - api_audience=client_options.api_audience, - ) - - def list_instance_configs(self, - request: Optional[Union[spanner_instance_admin.ListInstanceConfigsRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListInstanceConfigsPager: - r"""Lists the supported instance configurations for a - given project. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - def sample_list_instance_configs(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.ListInstanceConfigsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_instance_configs(request=request) - - # Handle the response - for response in page_result: - print(response) - - Args: - request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest, dict]): - The request object. The request for - [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. - parent (str): - Required. The name of the project for which a list of - supported instance configurations is requested. Values - are of the form ``projects/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigsPager: - The response for - [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_instance_admin.ListInstanceConfigsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_instance_admin.ListInstanceConfigsRequest): - request = spanner_instance_admin.ListInstanceConfigsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_instance_configs] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListInstanceConfigsPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def get_instance_config(self, - request: Optional[Union[spanner_instance_admin.GetInstanceConfigRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner_instance_admin.InstanceConfig: - r"""Gets information about a particular instance - configuration. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - def sample_get_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.GetInstanceConfigRequest( - name="name_value", - ) - - # Make the request - response = client.get_instance_config(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest, dict]): - The request object. The request for - [GetInstanceConfigRequest][google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig]. - name (str): - Required. The name of the requested instance - configuration. Values are of the form - ``projects//instanceConfigs/``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_instance_v1.types.InstanceConfig: - A possible configuration for a Cloud - Spanner instance. Configurations define - the geographic placement of nodes and - their replication. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_instance_admin.GetInstanceConfigRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_instance_admin.GetInstanceConfigRequest): - request = spanner_instance_admin.GetInstanceConfigRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.get_instance_config] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def create_instance_config(self, - request: Optional[Union[spanner_instance_admin.CreateInstanceConfigRequest, dict]] = None, - *, - parent: Optional[str] = None, - instance_config: Optional[spanner_instance_admin.InstanceConfig] = None, - instance_config_id: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Creates an instance config and begins preparing it to be used. - The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of preparing the new instance config. The instance - config name is assigned by the caller. If the named instance - config already exists, ``CreateInstanceConfig`` returns - ``ALREADY_EXISTS``. - - Immediately after the request returns: - - - The instance config is readable via the API, with all - requested attributes. The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field is set to true. Its state is ``CREATING``. - - While the operation is pending: - - - Cancelling the operation renders the instance config - immediately unreadable via the API. - - Except for deleting the creating resource, all other attempts - to modify the instance config are rejected. - - Upon completion of the returned operation: - - - Instances can be created using the instance configuration. - - The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field becomes false. Its state becomes ``READY``. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and - can be used to track creation of the instance config. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. - The [response][google.longrunning.Operation.response] field type - is - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], - if successful. - - Authorization requires ``spanner.instanceConfigs.create`` - permission on the resource - [parent][google.spanner.admin.instance.v1.CreateInstanceConfigRequest.parent]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - def sample_create_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.CreateInstanceConfigRequest( - parent="parent_value", - instance_config_id="instance_config_id_value", - ) - - # Make the request - operation = client.create_instance_config(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_instance_v1.types.CreateInstanceConfigRequest, dict]): - The request object. The request for - [CreateInstanceConfigRequest][InstanceAdmin.CreateInstanceConfigRequest]. - parent (str): - Required. The name of the project in which to create the - instance config. Values are of the form - ``projects/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): - Required. The InstanceConfig proto of the configuration - to create. instance_config.name must be - ``/instanceConfigs/``. - instance_config.base_config must be a Google managed - configuration name, e.g. /instanceConfigs/us-east1, - /instanceConfigs/nam3. - - This corresponds to the ``instance_config`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - instance_config_id (str): - Required. The ID of the instance config to create. Valid - identifiers are of the form - ``custom-[-a-z0-9]*[a-z0-9]`` and must be between 2 and - 64 characters in length. The ``custom-`` prefix is - required to avoid name conflicts with Google managed - configurations. - - This corresponds to the ``instance_config_id`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be :class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig` A possible configuration for a Cloud Spanner instance. Configurations - define the geographic placement of nodes and their - replication. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, instance_config, instance_config_id]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_instance_admin.CreateInstanceConfigRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_instance_admin.CreateInstanceConfigRequest): - request = spanner_instance_admin.CreateInstanceConfigRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if instance_config is not None: - request.instance_config = instance_config - if instance_config_id is not None: - request.instance_config_id = instance_config_id - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_instance_config] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - spanner_instance_admin.InstanceConfig, - metadata_type=spanner_instance_admin.CreateInstanceConfigMetadata, - ) - - # Done; return the response. - return response - - def update_instance_config(self, - request: Optional[Union[spanner_instance_admin.UpdateInstanceConfigRequest, dict]] = None, - *, - instance_config: Optional[spanner_instance_admin.InstanceConfig] = None, - update_mask: Optional[field_mask_pb2.FieldMask] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Updates an instance config. The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of updating the instance. If the named instance - config does not exist, returns ``NOT_FOUND``. - - Only user managed configurations can be updated. - - Immediately after the request returns: - - - The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field is set to true. - - While the operation is pending: - - - Cancelling the operation sets its metadata's - [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata.cancel_time]. - The operation is guaranteed to succeed at undoing all - changes, after which point it terminates with a ``CANCELLED`` - status. - - All other attempts to modify the instance config are - rejected. - - Reading the instance config via the API continues to give the - pre-request values. - - Upon completion of the returned operation: - - - Creating instances using the instance configuration uses the - new values. - - The instance config's new values are readable via the API. - - The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field becomes false. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and - can be used to track the instance config modification. The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateInstanceConfigMetadata][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata]. - The [response][google.longrunning.Operation.response] field type - is - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], - if successful. - - Authorization requires ``spanner.instanceConfigs.update`` - permission on the resource - [name][google.spanner.admin.instance.v1.InstanceConfig.name]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - def sample_update_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.UpdateInstanceConfigRequest( - ) - - # Make the request - operation = client.update_instance_config(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstanceConfigRequest, dict]): - The request object. The request for - [UpdateInstanceConfigRequest][InstanceAdmin.UpdateInstanceConfigRequest]. - instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): - Required. The user instance config to update, which must - always include the instance config name. Otherwise, only - fields mentioned in - [update_mask][google.spanner.admin.instance.v1.UpdateInstanceConfigRequest.update_mask] - need be included. To prevent conflicts of concurrent - updates, - [etag][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - can be used. - - This corresponds to the ``instance_config`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. A mask specifying which fields in - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] - should be updated. The field mask must always be - specified; this prevents any future fields in - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] - from being erased accidentally by clients that do not - know about them. Only display_name and labels can be - updated. - - This corresponds to the ``update_mask`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be :class:`google.cloud.spanner_admin_instance_v1.types.InstanceConfig` A possible configuration for a Cloud Spanner instance. Configurations - define the geographic placement of nodes and their - replication. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([instance_config, update_mask]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_instance_admin.UpdateInstanceConfigRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_instance_admin.UpdateInstanceConfigRequest): - request = spanner_instance_admin.UpdateInstanceConfigRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if instance_config is not None: - request.instance_config = instance_config - if update_mask is not None: - request.update_mask = update_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.update_instance_config] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("instance_config.name", request.instance_config.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - spanner_instance_admin.InstanceConfig, - metadata_type=spanner_instance_admin.UpdateInstanceConfigMetadata, - ) - - # Done; return the response. - return response - - def delete_instance_config(self, - request: Optional[Union[spanner_instance_admin.DeleteInstanceConfigRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Deletes the instance config. Deletion is only allowed when no - instances are using the configuration. If any instances are - using the config, returns ``FAILED_PRECONDITION``. - - Only user managed configurations can be deleted. - - Authorization requires ``spanner.instanceConfigs.delete`` - permission on the resource - [name][google.spanner.admin.instance.v1.InstanceConfig.name]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - def sample_delete_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.DeleteInstanceConfigRequest( - name="name_value", - ) - - # Make the request - client.delete_instance_config(request=request) - - Args: - request (Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstanceConfigRequest, dict]): - The request object. The request for - [DeleteInstanceConfigRequest][InstanceAdmin.DeleteInstanceConfigRequest]. - name (str): - Required. The name of the instance configuration to be - deleted. Values are of the form - ``projects//instanceConfigs/`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_instance_admin.DeleteInstanceConfigRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_instance_admin.DeleteInstanceConfigRequest): - request = spanner_instance_admin.DeleteInstanceConfigRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.delete_instance_config] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def list_instance_config_operations(self, - request: Optional[Union[spanner_instance_admin.ListInstanceConfigOperationsRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListInstanceConfigOperationsPager: - r"""Lists the user-managed instance config [long-running - operations][google.longrunning.Operation] in the given project. - An instance config operation has a name of the form - ``projects//instanceConfigs//operations/``. - The long-running operation - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - Operations returned include those that have - completed/failed/canceled within the last 7 days, and pending - operations. Operations returned are ordered by - ``operation.metadata.value.start_time`` in descending order - starting from the most recently started operation. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - def sample_list_instance_config_operations(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.ListInstanceConfigOperationsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_instance_config_operations(request=request) - - # Handle the response - for response in page_result: - print(response) - - Args: - request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest, dict]): - The request object. The request for - [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. - parent (str): - Required. The project of the instance config operations. - Values are of the form ``projects/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigOperationsPager: - The response for - [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_instance_admin.ListInstanceConfigOperationsRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_instance_admin.ListInstanceConfigOperationsRequest): - request = spanner_instance_admin.ListInstanceConfigOperationsRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_instance_config_operations] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListInstanceConfigOperationsPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def list_instances(self, - request: Optional[Union[spanner_instance_admin.ListInstancesRequest, dict]] = None, - *, - parent: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListInstancesPager: - r"""Lists all instances in the given project. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - def sample_list_instances(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.ListInstancesRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_instances(request=request) - - # Handle the response - for response in page_result: - print(response) - - Args: - request (Union[google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest, dict]): - The request object. The request for - [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. - parent (str): - Required. The name of the project for which a list of - instances is requested. Values are of the form - ``projects/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancesPager: - The response for - [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. - - Iterating over this object will yield results and - resolve additional pages automatically. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_instance_admin.ListInstancesRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_instance_admin.ListInstancesRequest): - request = spanner_instance_admin.ListInstancesRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_instances] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # This method is paged; wrap the response in a pager, which provides - # an `__iter__` convenience method. - response = pagers.ListInstancesPager( - method=rpc, - request=request, - response=response, - metadata=metadata, - ) - - # Done; return the response. - return response - - def get_instance(self, - request: Optional[Union[spanner_instance_admin.GetInstanceRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> spanner_instance_admin.Instance: - r"""Gets information about a particular instance. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - def sample_get_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.GetInstanceRequest( - name="name_value", - ) - - # Make the request - response = client.get_instance(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest, dict]): - The request object. The request for - [GetInstance][google.spanner.admin.instance.v1.InstanceAdmin.GetInstance]. - name (str): - Required. The name of the requested instance. Values are - of the form ``projects//instances/``. - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.cloud.spanner_admin_instance_v1.types.Instance: - An isolated set of Cloud Spanner - resources on which databases can be - hosted. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_instance_admin.GetInstanceRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_instance_admin.GetInstanceRequest): - request = spanner_instance_admin.GetInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.get_instance] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def create_instance(self, - request: Optional[Union[spanner_instance_admin.CreateInstanceRequest, dict]] = None, - *, - parent: Optional[str] = None, - instance_id: Optional[str] = None, - instance: Optional[spanner_instance_admin.Instance] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Creates an instance and begins preparing it to begin serving. - The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of preparing the new instance. The instance name is - assigned by the caller. If the named instance already exists, - ``CreateInstance`` returns ``ALREADY_EXISTS``. - - Immediately upon completion of this request: - - - The instance is readable via the API, with all requested - attributes but no allocated resources. Its state is - ``CREATING``. - - Until completion of the returned operation: - - - Cancelling the operation renders the instance immediately - unreadable via the API. - - The instance can be deleted. - - All other attempts to modify the instance are rejected. - - Upon completion of the returned operation: - - - Billing for all successfully-allocated resources begins (some - types may have lower than the requested levels). - - Databases can be created in the instance. - - The instance's allocated resource levels are readable via the - API. - - The instance's state becomes ``READY``. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and can be - used to track creation of the instance. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateInstanceMetadata][google.spanner.admin.instance.v1.CreateInstanceMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Instance][google.spanner.admin.instance.v1.Instance], if - successful. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - def sample_create_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - instance = spanner_admin_instance_v1.Instance() - instance.name = "name_value" - instance.config = "config_value" - instance.display_name = "display_name_value" - - request = spanner_admin_instance_v1.CreateInstanceRequest( - parent="parent_value", - instance_id="instance_id_value", - instance=instance, - ) - - # Make the request - operation = client.create_instance(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_instance_v1.types.CreateInstanceRequest, dict]): - The request object. The request for - [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance]. - parent (str): - Required. The name of the project in which to create the - instance. Values are of the form ``projects/``. - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - instance_id (str): - Required. The ID of the instance to create. Valid - identifiers are of the form ``[a-z][-a-z0-9]*[a-z0-9]`` - and must be between 2 and 64 characters in length. - - This corresponds to the ``instance_id`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - instance (google.cloud.spanner_admin_instance_v1.types.Instance): - Required. The instance to create. The name may be - omitted, but if specified must be - ``/instances/``. - - This corresponds to the ``instance`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.spanner_admin_instance_v1.types.Instance` - An isolated set of Cloud Spanner resources on which - databases can be hosted. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([parent, instance_id, instance]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_instance_admin.CreateInstanceRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_instance_admin.CreateInstanceRequest): - request = spanner_instance_admin.CreateInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if parent is not None: - request.parent = parent - if instance_id is not None: - request.instance_id = instance_id - if instance is not None: - request.instance = instance - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.create_instance] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("parent", request.parent), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - spanner_instance_admin.Instance, - metadata_type=spanner_instance_admin.CreateInstanceMetadata, - ) - - # Done; return the response. - return response - - def update_instance(self, - request: Optional[Union[spanner_instance_admin.UpdateInstanceRequest, dict]] = None, - *, - instance: Optional[spanner_instance_admin.Instance] = None, - field_mask: Optional[field_mask_pb2.FieldMask] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> operation.Operation: - r"""Updates an instance, and begins allocating or releasing - resources as requested. The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of updating the instance. If the named instance - does not exist, returns ``NOT_FOUND``. - - Immediately upon completion of this request: - - - For resource types for which a decrease in the instance's - allocation has been requested, billing is based on the - newly-requested level. - - Until completion of the returned operation: - - - Cancelling the operation sets its metadata's - [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceMetadata.cancel_time], - and begins restoring resources to their pre-request values. - The operation is guaranteed to succeed at undoing all - resource changes, after which point it terminates with a - ``CANCELLED`` status. - - All other attempts to modify the instance are rejected. - - Reading the instance via the API continues to give the - pre-request resource levels. - - Upon completion of the returned operation: - - - Billing begins for all successfully-allocated resources (some - types may have lower than the requested levels). - - All newly-reserved resources are available for serving the - instance's tables. - - The instance's new resource levels are readable via the API. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and can be - used to track the instance modification. The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateInstanceMetadata][google.spanner.admin.instance.v1.UpdateInstanceMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Instance][google.spanner.admin.instance.v1.Instance], if - successful. - - Authorization requires ``spanner.instances.update`` permission - on the resource - [name][google.spanner.admin.instance.v1.Instance.name]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - def sample_update_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - instance = spanner_admin_instance_v1.Instance() - instance.name = "name_value" - instance.config = "config_value" - instance.display_name = "display_name_value" - - request = spanner_admin_instance_v1.UpdateInstanceRequest( - instance=instance, - ) - - # Make the request - operation = client.update_instance(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - - Args: - request (Union[google.cloud.spanner_admin_instance_v1.types.UpdateInstanceRequest, dict]): - The request object. The request for - [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance]. - instance (google.cloud.spanner_admin_instance_v1.types.Instance): - Required. The instance to update, which must always - include the instance name. Otherwise, only fields - mentioned in - [field_mask][google.spanner.admin.instance.v1.UpdateInstanceRequest.field_mask] - need be included. - - This corresponds to the ``instance`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - field_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. A mask specifying which fields in - [Instance][google.spanner.admin.instance.v1.Instance] - should be updated. The field mask must always be - specified; this prevents any future fields in - [Instance][google.spanner.admin.instance.v1.Instance] - from being erased accidentally by clients that do not - know about them. - - This corresponds to the ``field_mask`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.api_core.operation.Operation: - An object representing a long-running operation. - - The result type for the operation will be - :class:`google.cloud.spanner_admin_instance_v1.types.Instance` - An isolated set of Cloud Spanner resources on which - databases can be hosted. - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([instance, field_mask]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_instance_admin.UpdateInstanceRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_instance_admin.UpdateInstanceRequest): - request = spanner_instance_admin.UpdateInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if instance is not None: - request.instance = instance - if field_mask is not None: - request.field_mask = field_mask - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.update_instance] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("instance.name", request.instance.name), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Wrap the response in an operation future. - response = operation.from_gapic( - response, - self._transport.operations_client, - spanner_instance_admin.Instance, - metadata_type=spanner_instance_admin.UpdateInstanceMetadata, - ) - - # Done; return the response. - return response - - def delete_instance(self, - request: Optional[Union[spanner_instance_admin.DeleteInstanceRequest, dict]] = None, - *, - name: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> None: - r"""Deletes an instance. - - Immediately upon completion of the request: - - - Billing ceases for all of the instance's reserved resources. - - Soon afterward: - - - The instance and *all of its databases* immediately and - irrevocably disappear from the API. All data in the databases - is permanently deleted. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - - def sample_delete_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.DeleteInstanceRequest( - name="name_value", - ) - - # Make the request - client.delete_instance(request=request) - - Args: - request (Union[google.cloud.spanner_admin_instance_v1.types.DeleteInstanceRequest, dict]): - The request object. The request for - [DeleteInstance][google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance]. - name (str): - Required. The name of the instance to be deleted. Values - are of the form - ``projects//instances/`` - - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([name]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - # Minor optimization to avoid making a copy if the user passes - # in a spanner_instance_admin.DeleteInstanceRequest. - # There's no risk of modifying the input as we've already verified - # there are no flattened fields. - if not isinstance(request, spanner_instance_admin.DeleteInstanceRequest): - request = spanner_instance_admin.DeleteInstanceRequest(request) - # If we have keyword arguments corresponding to fields on the - # request, apply these. - if name is not None: - request.name = name - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.delete_instance] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("name", request.name), - )), - ) - - # Send the request. - rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - def set_iam_policy(self, - request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, - *, - resource: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> policy_pb2.Policy: - r"""Sets the access control policy on an instance resource. Replaces - any existing policy. - - Authorization requires ``spanner.instances.setIamPolicy`` on - [resource][google.iam.v1.SetIamPolicyRequest.resource]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - from google.iam.v1 import iam_policy_pb2 # type: ignore - - def sample_set_iam_policy(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = iam_policy_pb2.SetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = client.set_iam_policy(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.iam.v1.iam_policy_pb2.SetIamPolicyRequest, dict]): - The request object. Request message for ``SetIamPolicy`` method. - resource (str): - REQUIRED: The resource for which the - policy is being specified. See the - operation documentation for the - appropriate value for this field. - - This corresponds to the ``resource`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.iam.v1.policy_pb2.Policy: - An Identity and Access Management (IAM) policy, which specifies access - controls for Google Cloud resources. - - A Policy is a collection of bindings. A binding binds - one or more members, or principals, to a single role. - Principals can be user accounts, service accounts, - Google groups, and domains (such as G Suite). A role - is a named list of permissions; each role can be an - IAM predefined role or a user-created custom role. - - For some types of Google Cloud resources, a binding - can also specify a condition, which is a logical - expression that allows access to a resource only if - the expression evaluates to true. A condition can add - constraints based on attributes of the request, the - resource, or both. To learn which resources support - conditions in their IAM policies, see the [IAM - documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). - - **JSON example:** - - { - "bindings": [ - { - "role": - "roles/resourcemanager.organizationAdmin", - "members": [ "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - - }, { "role": - "roles/resourcemanager.organizationViewer", - "members": [ "user:eve@example.com" ], - "condition": { "title": "expirable access", - "description": "Does not grant access after - Sep 2020", "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", } } - - ], "etag": "BwWWja0YfJA=", "version": 3 - - } - - **YAML example:** - - bindings: - members: - user:\ mike@example.com - - group:\ admins@example.com - domain:google.com - - serviceAccount:\ my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - user:\ eve@example.com role: - roles/resourcemanager.organizationViewer - condition: title: expirable access description: - Does not grant access after Sep 2020 expression: - request.time < - timestamp('2020-10-01T00:00:00.000Z') etag: - BwWWja0YfJA= version: 3 - - For a description of IAM and its features, see the - [IAM - documentation](\ https://cloud.google.com/iam/docs/). - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([resource]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - if isinstance(request, dict): - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - request = iam_policy_pb2.SetIamPolicyRequest(**request) - elif not request: - # Null request, just make one. - request = iam_policy_pb2.SetIamPolicyRequest() - if resource is not None: - request.resource = resource - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.set_iam_policy] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("resource", request.resource), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def get_iam_policy(self, - request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, - *, - resource: Optional[str] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> policy_pb2.Policy: - r"""Gets the access control policy for an instance resource. Returns - an empty policy if an instance exists but does not have a policy - set. - - Authorization requires ``spanner.instances.getIamPolicy`` on - [resource][google.iam.v1.GetIamPolicyRequest.resource]. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - from google.iam.v1 import iam_policy_pb2 # type: ignore - - def sample_get_iam_policy(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = iam_policy_pb2.GetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = client.get_iam_policy(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.iam.v1.iam_policy_pb2.GetIamPolicyRequest, dict]): - The request object. Request message for ``GetIamPolicy`` method. - resource (str): - REQUIRED: The resource for which the - policy is being requested. See the - operation documentation for the - appropriate value for this field. - - This corresponds to the ``resource`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.iam.v1.policy_pb2.Policy: - An Identity and Access Management (IAM) policy, which specifies access - controls for Google Cloud resources. - - A Policy is a collection of bindings. A binding binds - one or more members, or principals, to a single role. - Principals can be user accounts, service accounts, - Google groups, and domains (such as G Suite). A role - is a named list of permissions; each role can be an - IAM predefined role or a user-created custom role. - - For some types of Google Cloud resources, a binding - can also specify a condition, which is a logical - expression that allows access to a resource only if - the expression evaluates to true. A condition can add - constraints based on attributes of the request, the - resource, or both. To learn which resources support - conditions in their IAM policies, see the [IAM - documentation](\ https://cloud.google.com/iam/help/conditions/resource-policies). - - **JSON example:** - - { - "bindings": [ - { - "role": - "roles/resourcemanager.organizationAdmin", - "members": [ "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - - }, { "role": - "roles/resourcemanager.organizationViewer", - "members": [ "user:eve@example.com" ], - "condition": { "title": "expirable access", - "description": "Does not grant access after - Sep 2020", "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", } } - - ], "etag": "BwWWja0YfJA=", "version": 3 - - } - - **YAML example:** - - bindings: - members: - user:\ mike@example.com - - group:\ admins@example.com - domain:google.com - - serviceAccount:\ my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - user:\ eve@example.com role: - roles/resourcemanager.organizationViewer - condition: title: expirable access description: - Does not grant access after Sep 2020 expression: - request.time < - timestamp('2020-10-01T00:00:00.000Z') etag: - BwWWja0YfJA= version: 3 - - For a description of IAM and its features, see the - [IAM - documentation](\ https://cloud.google.com/iam/docs/). - - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([resource]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - if isinstance(request, dict): - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - request = iam_policy_pb2.GetIamPolicyRequest(**request) - elif not request: - # Null request, just make one. - request = iam_policy_pb2.GetIamPolicyRequest() - if resource is not None: - request.resource = resource - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.get_iam_policy] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("resource", request.resource), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def test_iam_permissions(self, - request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, - *, - resource: Optional[str] = None, - permissions: Optional[MutableSequence[str]] = None, - retry: OptionalRetry = gapic_v1.method.DEFAULT, - timeout: Union[float, object] = gapic_v1.method.DEFAULT, - metadata: Sequence[Tuple[str, str]] = (), - ) -> iam_policy_pb2.TestIamPermissionsResponse: - r"""Returns permissions that the caller has on the specified - instance resource. - - Attempting this RPC on a non-existent Cloud Spanner instance - resource will result in a NOT_FOUND error if the user has - ``spanner.instances.list`` permission on the containing Google - Cloud Project. Otherwise returns an empty set of permissions. - - .. code-block:: python - - # This snippet has been automatically generated and should be regarded as a - # code template only. - # It will require modifications to work: - # - It may require correct/in-range values for request initialization. - # - It may require specifying regional endpoints when creating the service - # client as shown in: - # https://googleapis.dev/python/google-api-core/latest/client_options.html - from google.cloud import spanner_admin_instance_v1 - from google.iam.v1 import iam_policy_pb2 # type: ignore - - def sample_test_iam_permissions(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = iam_policy_pb2.TestIamPermissionsRequest( - resource="resource_value", - permissions=['permissions_value1', 'permissions_value2'], - ) - - # Make the request - response = client.test_iam_permissions(request=request) - - # Handle the response - print(response) - - Args: - request (Union[google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest, dict]): - The request object. Request message for ``TestIamPermissions`` method. - resource (str): - REQUIRED: The resource for which the - policy detail is being requested. See - the operation documentation for the - appropriate value for this field. - - This corresponds to the ``resource`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - permissions (MutableSequence[str]): - The set of permissions to check for the ``resource``. - Permissions with wildcards (such as '*' or 'storage.*') - are not allowed. For more information see `IAM - Overview `__. - - This corresponds to the ``permissions`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: - Response message for TestIamPermissions method. - """ - # Create or coerce a protobuf request object. - # Quick check: If we got a request object, we should *not* have - # gotten any keyword arguments that map to the request. - has_flattened_params = any([resource, permissions]) - if request is not None and has_flattened_params: - raise ValueError('If the `request` argument is set, then none of ' - 'the individual field arguments should be set.') - - if isinstance(request, dict): - # The request isn't a proto-plus wrapped type, - # so it must be constructed via keyword expansion. - request = iam_policy_pb2.TestIamPermissionsRequest(**request) - elif not request: - # Null request, just make one. - request = iam_policy_pb2.TestIamPermissionsRequest() - if resource is not None: - request.resource = resource - if permissions: - request.permissions.extend(permissions) - - # Wrap the RPC method; this adds retry and timeout information, - # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions] - - # Certain fields should be provided within the metadata header; - # add these here. - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ("resource", request.resource), - )), - ) - - # Send the request. - response = rpc( - request, - retry=retry, - timeout=timeout, - metadata=metadata, - ) - - # Done; return the response. - return response - - def __enter__(self) -> "InstanceAdminClient": - return self - - def __exit__(self, type, value, traceback): - """Releases underlying transport's resources. - - .. warning:: - ONLY use as a context manager if the transport is NOT shared - with other clients! Exiting the with block will CLOSE the transport - and may cause errors in other clients! - """ - self.transport.close() - - - - - - - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - - -__all__ = ( - "InstanceAdminClient", -) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py deleted file mode 100644 index 747e91af6b..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py +++ /dev/null @@ -1,382 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from typing import Any, AsyncIterator, Awaitable, Callable, Sequence, Tuple, Optional, Iterator - -from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin -from google.longrunning import operations_pb2 # type: ignore - - -class ListInstanceConfigsPager: - """A pager for iterating through ``list_instance_configs`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsResponse` object, and - provides an ``__iter__`` method to iterate through its - ``instance_configs`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListInstanceConfigs`` requests and continue to iterate - through the ``instance_configs`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., spanner_instance_admin.ListInstanceConfigsResponse], - request: spanner_instance_admin.ListInstanceConfigsRequest, - response: spanner_instance_admin.ListInstanceConfigsResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest): - The initial request object. - response (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = spanner_instance_admin.ListInstanceConfigsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[spanner_instance_admin.ListInstanceConfigsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, metadata=self._metadata) - yield self._response - - def __iter__(self) -> Iterator[spanner_instance_admin.InstanceConfig]: - for page in self.pages: - yield from page.instance_configs - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListInstanceConfigsAsyncPager: - """A pager for iterating through ``list_instance_configs`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``instance_configs`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListInstanceConfigs`` requests and continue to iterate - through the ``instance_configs`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., Awaitable[spanner_instance_admin.ListInstanceConfigsResponse]], - request: spanner_instance_admin.ListInstanceConfigsRequest, - response: spanner_instance_admin.ListInstanceConfigsResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiates the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest): - The initial request object. - response (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = spanner_instance_admin.ListInstanceConfigsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[spanner_instance_admin.ListInstanceConfigsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, metadata=self._metadata) - yield self._response - def __aiter__(self) -> AsyncIterator[spanner_instance_admin.InstanceConfig]: - async def async_generator(): - async for page in self.pages: - for response in page.instance_configs: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListInstanceConfigOperationsPager: - """A pager for iterating through ``list_instance_config_operations`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse` object, and - provides an ``__iter__`` method to iterate through its - ``operations`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListInstanceConfigOperations`` requests and continue to iterate - through the ``operations`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., spanner_instance_admin.ListInstanceConfigOperationsResponse], - request: spanner_instance_admin.ListInstanceConfigOperationsRequest, - response: spanner_instance_admin.ListInstanceConfigOperationsResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest): - The initial request object. - response (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = spanner_instance_admin.ListInstanceConfigOperationsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[spanner_instance_admin.ListInstanceConfigOperationsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, metadata=self._metadata) - yield self._response - - def __iter__(self) -> Iterator[operations_pb2.Operation]: - for page in self.pages: - yield from page.operations - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListInstanceConfigOperationsAsyncPager: - """A pager for iterating through ``list_instance_config_operations`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``operations`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListInstanceConfigOperations`` requests and continue to iterate - through the ``operations`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., Awaitable[spanner_instance_admin.ListInstanceConfigOperationsResponse]], - request: spanner_instance_admin.ListInstanceConfigOperationsRequest, - response: spanner_instance_admin.ListInstanceConfigOperationsResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiates the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest): - The initial request object. - response (google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = spanner_instance_admin.ListInstanceConfigOperationsRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[spanner_instance_admin.ListInstanceConfigOperationsResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, metadata=self._metadata) - yield self._response - def __aiter__(self) -> AsyncIterator[operations_pb2.Operation]: - async def async_generator(): - async for page in self.pages: - for response in page.operations: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListInstancesPager: - """A pager for iterating through ``list_instances`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_instance_v1.types.ListInstancesResponse` object, and - provides an ``__iter__`` method to iterate through its - ``instances`` field. - - If there are more pages, the ``__iter__`` method will make additional - ``ListInstances`` requests and continue to iterate - through the ``instances`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_instance_v1.types.ListInstancesResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., spanner_instance_admin.ListInstancesResponse], - request: spanner_instance_admin.ListInstancesRequest, - response: spanner_instance_admin.ListInstancesResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiate the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest): - The initial request object. - response (google.cloud.spanner_admin_instance_v1.types.ListInstancesResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = spanner_instance_admin.ListInstancesRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - def pages(self) -> Iterator[spanner_instance_admin.ListInstancesResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = self._method(self._request, metadata=self._metadata) - yield self._response - - def __iter__(self) -> Iterator[spanner_instance_admin.Instance]: - for page in self.pages: - yield from page.instances - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) - - -class ListInstancesAsyncPager: - """A pager for iterating through ``list_instances`` requests. - - This class thinly wraps an initial - :class:`google.cloud.spanner_admin_instance_v1.types.ListInstancesResponse` object, and - provides an ``__aiter__`` method to iterate through its - ``instances`` field. - - If there are more pages, the ``__aiter__`` method will make additional - ``ListInstances`` requests and continue to iterate - through the ``instances`` field on the - corresponding responses. - - All the usual :class:`google.cloud.spanner_admin_instance_v1.types.ListInstancesResponse` - attributes are available on the pager. If multiple requests are made, only - the most recent response is retained, and thus used for attribute lookup. - """ - def __init__(self, - method: Callable[..., Awaitable[spanner_instance_admin.ListInstancesResponse]], - request: spanner_instance_admin.ListInstancesRequest, - response: spanner_instance_admin.ListInstancesResponse, - *, - metadata: Sequence[Tuple[str, str]] = ()): - """Instantiates the pager. - - Args: - method (Callable): The method that was originally called, and - which instantiated this pager. - request (google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest): - The initial request object. - response (google.cloud.spanner_admin_instance_v1.types.ListInstancesResponse): - The initial response object. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - self._method = method - self._request = spanner_instance_admin.ListInstancesRequest(request) - self._response = response - self._metadata = metadata - - def __getattr__(self, name: str) -> Any: - return getattr(self._response, name) - - @property - async def pages(self) -> AsyncIterator[spanner_instance_admin.ListInstancesResponse]: - yield self._response - while self._response.next_page_token: - self._request.page_token = self._response.next_page_token - self._response = await self._method(self._request, metadata=self._metadata) - yield self._response - def __aiter__(self) -> AsyncIterator[spanner_instance_admin.Instance]: - async def async_generator(): - async for page in self.pages: - for response in page.instances: - yield response - - return async_generator() - - def __repr__(self) -> str: - return '{0}<{1!r}>'.format(self.__class__.__name__, self._response) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py deleted file mode 100644 index 14ec3ceb61..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py +++ /dev/null @@ -1,38 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from collections import OrderedDict -from typing import Dict, Type - -from .base import InstanceAdminTransport -from .grpc import InstanceAdminGrpcTransport -from .grpc_asyncio import InstanceAdminGrpcAsyncIOTransport -from .rest import InstanceAdminRestTransport -from .rest import InstanceAdminRestInterceptor - - -# Compile a registry of transports. -_transport_registry = OrderedDict() # type: Dict[str, Type[InstanceAdminTransport]] -_transport_registry['grpc'] = InstanceAdminGrpcTransport -_transport_registry['grpc_asyncio'] = InstanceAdminGrpcAsyncIOTransport -_transport_registry['rest'] = InstanceAdminRestTransport - -__all__ = ( - 'InstanceAdminTransport', - 'InstanceAdminGrpcTransport', - 'InstanceAdminGrpcAsyncIOTransport', - 'InstanceAdminRestTransport', - 'InstanceAdminRestInterceptor', -) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py deleted file mode 100644 index d37e40fb4c..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py +++ /dev/null @@ -1,383 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union - -from google.cloud.spanner_admin_instance_v1 import gapic_version as package_version - -import google.auth # type: ignore -import google.api_core -from google.api_core import exceptions as core_exceptions -from google.api_core import gapic_v1 -from google.api_core import retry as retries -from google.api_core import operations_v1 -from google.auth import credentials as ga_credentials # type: ignore -from google.oauth2 import service_account # type: ignore - -from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin -from google.iam.v1 import iam_policy_pb2 # type: ignore -from google.iam.v1 import policy_pb2 # type: ignore -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__) - - -class InstanceAdminTransport(abc.ABC): - """Abstract transport class for InstanceAdmin.""" - - AUTH_SCOPES = ( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.admin', - ) - - DEFAULT_HOST: str = 'spanner.googleapis.com' - def __init__( - self, *, - host: str = DEFAULT_HOST, - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - **kwargs, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A list of scopes. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - """ - - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - - # Save the scopes. - self._scopes = scopes - - # If no credentials are provided, then determine the appropriate - # defaults. - if credentials and credentials_file: - raise core_exceptions.DuplicateCredentialArgs("'credentials_file' and 'credentials' are mutually exclusive") - - if credentials_file is not None: - credentials, _ = google.auth.load_credentials_from_file( - credentials_file, - **scopes_kwargs, - quota_project_id=quota_project_id - ) - elif credentials is None: - credentials, _ = google.auth.default(**scopes_kwargs, quota_project_id=quota_project_id) - # Don't apply audience if the credentials file passed from user. - if hasattr(credentials, "with_gdch_audience"): - credentials = credentials.with_gdch_audience(api_audience if api_audience else host) - - # If the credentials are service account credentials, then always try to use self signed JWT. - if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"): - credentials = credentials.with_always_use_jwt_access(True) - - # Save the credentials. - self._credentials = credentials - - # Save the hostname. Default to port 443 (HTTPS) if none is specified. - if ':' not in host: - host += ':443' - self._host = host - - def _prep_wrapped_messages(self, client_info): - # Precompute the wrapped methods. - self._wrapped_methods = { - self.list_instance_configs: gapic_v1.method.wrap_method( - self.list_instance_configs, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.get_instance_config: gapic_v1.method.wrap_method( - self.get_instance_config, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.create_instance_config: gapic_v1.method.wrap_method( - self.create_instance_config, - default_timeout=None, - client_info=client_info, - ), - self.update_instance_config: gapic_v1.method.wrap_method( - self.update_instance_config, - default_timeout=None, - client_info=client_info, - ), - self.delete_instance_config: gapic_v1.method.wrap_method( - self.delete_instance_config, - default_timeout=None, - client_info=client_info, - ), - self.list_instance_config_operations: gapic_v1.method.wrap_method( - self.list_instance_config_operations, - default_timeout=None, - client_info=client_info, - ), - self.list_instances: gapic_v1.method.wrap_method( - self.list_instances, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.get_instance: gapic_v1.method.wrap_method( - self.get_instance, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.create_instance: gapic_v1.method.wrap_method( - self.create_instance, - default_timeout=3600.0, - client_info=client_info, - ), - self.update_instance: gapic_v1.method.wrap_method( - self.update_instance, - default_timeout=3600.0, - client_info=client_info, - ), - self.delete_instance: gapic_v1.method.wrap_method( - self.delete_instance, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=3600.0, - ), - default_timeout=3600.0, - client_info=client_info, - ), - self.set_iam_policy: gapic_v1.method.wrap_method( - self.set_iam_policy, - default_timeout=30.0, - client_info=client_info, - ), - self.get_iam_policy: gapic_v1.method.wrap_method( - self.get_iam_policy, - default_retry=retries.Retry( -initial=1.0,maximum=32.0,multiplier=1.3, predicate=retries.if_exception_type( - core_exceptions.DeadlineExceeded, - core_exceptions.ServiceUnavailable, - ), - deadline=30.0, - ), - default_timeout=30.0, - client_info=client_info, - ), - self.test_iam_permissions: gapic_v1.method.wrap_method( - self.test_iam_permissions, - default_timeout=30.0, - client_info=client_info, - ), - } - - def close(self): - """Closes resources associated with the transport. - - .. warning:: - Only call this method if the transport is NOT shared - with other clients - this may cause errors in other clients! - """ - raise NotImplementedError() - - @property - def operations_client(self): - """Return the client designed to process long-running operations.""" - raise NotImplementedError() - - @property - def list_instance_configs(self) -> Callable[ - [spanner_instance_admin.ListInstanceConfigsRequest], - Union[ - spanner_instance_admin.ListInstanceConfigsResponse, - Awaitable[spanner_instance_admin.ListInstanceConfigsResponse] - ]]: - raise NotImplementedError() - - @property - def get_instance_config(self) -> Callable[ - [spanner_instance_admin.GetInstanceConfigRequest], - Union[ - spanner_instance_admin.InstanceConfig, - Awaitable[spanner_instance_admin.InstanceConfig] - ]]: - raise NotImplementedError() - - @property - def create_instance_config(self) -> Callable[ - [spanner_instance_admin.CreateInstanceConfigRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def update_instance_config(self) -> Callable[ - [spanner_instance_admin.UpdateInstanceConfigRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def delete_instance_config(self) -> Callable[ - [spanner_instance_admin.DeleteInstanceConfigRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def list_instance_config_operations(self) -> Callable[ - [spanner_instance_admin.ListInstanceConfigOperationsRequest], - Union[ - spanner_instance_admin.ListInstanceConfigOperationsResponse, - Awaitable[spanner_instance_admin.ListInstanceConfigOperationsResponse] - ]]: - raise NotImplementedError() - - @property - def list_instances(self) -> Callable[ - [spanner_instance_admin.ListInstancesRequest], - Union[ - spanner_instance_admin.ListInstancesResponse, - Awaitable[spanner_instance_admin.ListInstancesResponse] - ]]: - raise NotImplementedError() - - @property - def get_instance(self) -> Callable[ - [spanner_instance_admin.GetInstanceRequest], - Union[ - spanner_instance_admin.Instance, - Awaitable[spanner_instance_admin.Instance] - ]]: - raise NotImplementedError() - - @property - def create_instance(self) -> Callable[ - [spanner_instance_admin.CreateInstanceRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def update_instance(self) -> Callable[ - [spanner_instance_admin.UpdateInstanceRequest], - Union[ - operations_pb2.Operation, - Awaitable[operations_pb2.Operation] - ]]: - raise NotImplementedError() - - @property - def delete_instance(self) -> Callable[ - [spanner_instance_admin.DeleteInstanceRequest], - Union[ - empty_pb2.Empty, - Awaitable[empty_pb2.Empty] - ]]: - raise NotImplementedError() - - @property - def set_iam_policy(self) -> Callable[ - [iam_policy_pb2.SetIamPolicyRequest], - Union[ - policy_pb2.Policy, - Awaitable[policy_pb2.Policy] - ]]: - raise NotImplementedError() - - @property - def get_iam_policy(self) -> Callable[ - [iam_policy_pb2.GetIamPolicyRequest], - Union[ - policy_pb2.Policy, - Awaitable[policy_pb2.Policy] - ]]: - raise NotImplementedError() - - @property - def test_iam_permissions(self) -> Callable[ - [iam_policy_pb2.TestIamPermissionsRequest], - Union[ - iam_policy_pb2.TestIamPermissionsResponse, - Awaitable[iam_policy_pb2.TestIamPermissionsResponse] - ]]: - raise NotImplementedError() - - @property - def kind(self) -> str: - raise NotImplementedError() - - -__all__ = ( - 'InstanceAdminTransport', -) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py deleted file mode 100644 index 38b21a589f..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py +++ /dev/null @@ -1,861 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import warnings -from typing import Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import grpc_helpers -from google.api_core import operations_v1 -from google.api_core import gapic_v1 -import google.auth # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore - -import grpc # type: ignore - -from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin -from google.iam.v1 import iam_policy_pb2 # type: ignore -from google.iam.v1 import policy_pb2 # type: ignore -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from .base import InstanceAdminTransport, DEFAULT_CLIENT_INFO - - -class InstanceAdminGrpcTransport(InstanceAdminTransport): - """gRPC backend transport for InstanceAdmin. - - Cloud Spanner Instance Admin API - The Cloud Spanner Instance Admin API can be used to create, - delete, modify and list instances. Instances are dedicated Cloud - Spanner serving and storage resources to be used by Cloud - Spanner databases. - Each instance has a "configuration", which dictates where the - serving resources for the Cloud Spanner instance are located - (e.g., US-central, Europe). Configurations are created by Google - based on resource availability. - - Cloud Spanner billing is based on the instances that exist and - their sizes. After an instance exists, there are no additional - per-database or per-operation charges for use of the instance - (though there may be additional network bandwidth charges). - Instances offer isolation: problems with databases in one - instance will not affect other instances. However, within an - instance databases can affect each other. For example, if one - database in an instance receives a lot of requests and consumes - most of the instance resources, fewer resources are available - for other databases in that instance, and their performance may - suffer. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - _stubs: Dict[str, Callable] - - def __init__(self, *, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: Optional[grpc.Channel] = None, - api_mtls_endpoint: Optional[str] = None, - client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, - client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if ``channel`` is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - channel (Optional[grpc.Channel]): A ``Channel`` instance through - which to make calls. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or application default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if ``channel`` is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - self._operations_client: Optional[operations_v1.OperationsClient] = None - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if channel: - # Ignore credentials if a channel was passed. - credentials = False - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience, - ) - - if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( - self._host, - # use the credentials which are saved - credentials=self._credentials, - # Set ``credentials_file`` to ``None`` here as - # the credentials that we saved earlier should be used. - credentials_file=None, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Wrap messages. This must be done after self._grpc_channel exists - self._prep_wrapped_messages(client_info) - - @classmethod - def create_channel(cls, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> grpc.Channel: - """Create and return a gRPC channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is mutually exclusive with credentials. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - grpc.Channel: A gRPC channel object. - - Raises: - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - - return grpc_helpers.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - @property - def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ - return self._grpc_channel - - @property - def operations_client(self) -> operations_v1.OperationsClient: - """Create the client designed to process long-running operations. - - This property caches on the instance; repeated calls return the same - client. - """ - # Quick check: Only create a new client if we do not already have one. - if self._operations_client is None: - self._operations_client = operations_v1.OperationsClient( - self.grpc_channel - ) - - # Return the client from cache. - return self._operations_client - - @property - def list_instance_configs(self) -> Callable[ - [spanner_instance_admin.ListInstanceConfigsRequest], - spanner_instance_admin.ListInstanceConfigsResponse]: - r"""Return a callable for the list instance configs method over gRPC. - - Lists the supported instance configurations for a - given project. - - Returns: - Callable[[~.ListInstanceConfigsRequest], - ~.ListInstanceConfigsResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_instance_configs' not in self._stubs: - self._stubs['list_instance_configs'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/ListInstanceConfigs', - request_serializer=spanner_instance_admin.ListInstanceConfigsRequest.serialize, - response_deserializer=spanner_instance_admin.ListInstanceConfigsResponse.deserialize, - ) - return self._stubs['list_instance_configs'] - - @property - def get_instance_config(self) -> Callable[ - [spanner_instance_admin.GetInstanceConfigRequest], - spanner_instance_admin.InstanceConfig]: - r"""Return a callable for the get instance config method over gRPC. - - Gets information about a particular instance - configuration. - - Returns: - Callable[[~.GetInstanceConfigRequest], - ~.InstanceConfig]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_instance_config' not in self._stubs: - self._stubs['get_instance_config'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/GetInstanceConfig', - request_serializer=spanner_instance_admin.GetInstanceConfigRequest.serialize, - response_deserializer=spanner_instance_admin.InstanceConfig.deserialize, - ) - return self._stubs['get_instance_config'] - - @property - def create_instance_config(self) -> Callable[ - [spanner_instance_admin.CreateInstanceConfigRequest], - operations_pb2.Operation]: - r"""Return a callable for the create instance config method over gRPC. - - Creates an instance config and begins preparing it to be used. - The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of preparing the new instance config. The instance - config name is assigned by the caller. If the named instance - config already exists, ``CreateInstanceConfig`` returns - ``ALREADY_EXISTS``. - - Immediately after the request returns: - - - The instance config is readable via the API, with all - requested attributes. The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field is set to true. Its state is ``CREATING``. - - While the operation is pending: - - - Cancelling the operation renders the instance config - immediately unreadable via the API. - - Except for deleting the creating resource, all other attempts - to modify the instance config are rejected. - - Upon completion of the returned operation: - - - Instances can be created using the instance configuration. - - The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field becomes false. Its state becomes ``READY``. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and - can be used to track creation of the instance config. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. - The [response][google.longrunning.Operation.response] field type - is - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], - if successful. - - Authorization requires ``spanner.instanceConfigs.create`` - permission on the resource - [parent][google.spanner.admin.instance.v1.CreateInstanceConfigRequest.parent]. - - Returns: - Callable[[~.CreateInstanceConfigRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'create_instance_config' not in self._stubs: - self._stubs['create_instance_config'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/CreateInstanceConfig', - request_serializer=spanner_instance_admin.CreateInstanceConfigRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['create_instance_config'] - - @property - def update_instance_config(self) -> Callable[ - [spanner_instance_admin.UpdateInstanceConfigRequest], - operations_pb2.Operation]: - r"""Return a callable for the update instance config method over gRPC. - - Updates an instance config. The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of updating the instance. If the named instance - config does not exist, returns ``NOT_FOUND``. - - Only user managed configurations can be updated. - - Immediately after the request returns: - - - The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field is set to true. - - While the operation is pending: - - - Cancelling the operation sets its metadata's - [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata.cancel_time]. - The operation is guaranteed to succeed at undoing all - changes, after which point it terminates with a ``CANCELLED`` - status. - - All other attempts to modify the instance config are - rejected. - - Reading the instance config via the API continues to give the - pre-request values. - - Upon completion of the returned operation: - - - Creating instances using the instance configuration uses the - new values. - - The instance config's new values are readable via the API. - - The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field becomes false. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and - can be used to track the instance config modification. The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateInstanceConfigMetadata][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata]. - The [response][google.longrunning.Operation.response] field type - is - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], - if successful. - - Authorization requires ``spanner.instanceConfigs.update`` - permission on the resource - [name][google.spanner.admin.instance.v1.InstanceConfig.name]. - - Returns: - Callable[[~.UpdateInstanceConfigRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'update_instance_config' not in self._stubs: - self._stubs['update_instance_config'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/UpdateInstanceConfig', - request_serializer=spanner_instance_admin.UpdateInstanceConfigRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['update_instance_config'] - - @property - def delete_instance_config(self) -> Callable[ - [spanner_instance_admin.DeleteInstanceConfigRequest], - empty_pb2.Empty]: - r"""Return a callable for the delete instance config method over gRPC. - - Deletes the instance config. Deletion is only allowed when no - instances are using the configuration. If any instances are - using the config, returns ``FAILED_PRECONDITION``. - - Only user managed configurations can be deleted. - - Authorization requires ``spanner.instanceConfigs.delete`` - permission on the resource - [name][google.spanner.admin.instance.v1.InstanceConfig.name]. - - Returns: - Callable[[~.DeleteInstanceConfigRequest], - ~.Empty]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'delete_instance_config' not in self._stubs: - self._stubs['delete_instance_config'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/DeleteInstanceConfig', - request_serializer=spanner_instance_admin.DeleteInstanceConfigRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_instance_config'] - - @property - def list_instance_config_operations(self) -> Callable[ - [spanner_instance_admin.ListInstanceConfigOperationsRequest], - spanner_instance_admin.ListInstanceConfigOperationsResponse]: - r"""Return a callable for the list instance config - operations method over gRPC. - - Lists the user-managed instance config [long-running - operations][google.longrunning.Operation] in the given project. - An instance config operation has a name of the form - ``projects//instanceConfigs//operations/``. - The long-running operation - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - Operations returned include those that have - completed/failed/canceled within the last 7 days, and pending - operations. Operations returned are ordered by - ``operation.metadata.value.start_time`` in descending order - starting from the most recently started operation. - - Returns: - Callable[[~.ListInstanceConfigOperationsRequest], - ~.ListInstanceConfigOperationsResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_instance_config_operations' not in self._stubs: - self._stubs['list_instance_config_operations'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/ListInstanceConfigOperations', - request_serializer=spanner_instance_admin.ListInstanceConfigOperationsRequest.serialize, - response_deserializer=spanner_instance_admin.ListInstanceConfigOperationsResponse.deserialize, - ) - return self._stubs['list_instance_config_operations'] - - @property - def list_instances(self) -> Callable[ - [spanner_instance_admin.ListInstancesRequest], - spanner_instance_admin.ListInstancesResponse]: - r"""Return a callable for the list instances method over gRPC. - - Lists all instances in the given project. - - Returns: - Callable[[~.ListInstancesRequest], - ~.ListInstancesResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_instances' not in self._stubs: - self._stubs['list_instances'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/ListInstances', - request_serializer=spanner_instance_admin.ListInstancesRequest.serialize, - response_deserializer=spanner_instance_admin.ListInstancesResponse.deserialize, - ) - return self._stubs['list_instances'] - - @property - def get_instance(self) -> Callable[ - [spanner_instance_admin.GetInstanceRequest], - spanner_instance_admin.Instance]: - r"""Return a callable for the get instance method over gRPC. - - Gets information about a particular instance. - - Returns: - Callable[[~.GetInstanceRequest], - ~.Instance]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_instance' not in self._stubs: - self._stubs['get_instance'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/GetInstance', - request_serializer=spanner_instance_admin.GetInstanceRequest.serialize, - response_deserializer=spanner_instance_admin.Instance.deserialize, - ) - return self._stubs['get_instance'] - - @property - def create_instance(self) -> Callable[ - [spanner_instance_admin.CreateInstanceRequest], - operations_pb2.Operation]: - r"""Return a callable for the create instance method over gRPC. - - Creates an instance and begins preparing it to begin serving. - The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of preparing the new instance. The instance name is - assigned by the caller. If the named instance already exists, - ``CreateInstance`` returns ``ALREADY_EXISTS``. - - Immediately upon completion of this request: - - - The instance is readable via the API, with all requested - attributes but no allocated resources. Its state is - ``CREATING``. - - Until completion of the returned operation: - - - Cancelling the operation renders the instance immediately - unreadable via the API. - - The instance can be deleted. - - All other attempts to modify the instance are rejected. - - Upon completion of the returned operation: - - - Billing for all successfully-allocated resources begins (some - types may have lower than the requested levels). - - Databases can be created in the instance. - - The instance's allocated resource levels are readable via the - API. - - The instance's state becomes ``READY``. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and can be - used to track creation of the instance. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateInstanceMetadata][google.spanner.admin.instance.v1.CreateInstanceMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Instance][google.spanner.admin.instance.v1.Instance], if - successful. - - Returns: - Callable[[~.CreateInstanceRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'create_instance' not in self._stubs: - self._stubs['create_instance'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/CreateInstance', - request_serializer=spanner_instance_admin.CreateInstanceRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['create_instance'] - - @property - def update_instance(self) -> Callable[ - [spanner_instance_admin.UpdateInstanceRequest], - operations_pb2.Operation]: - r"""Return a callable for the update instance method over gRPC. - - Updates an instance, and begins allocating or releasing - resources as requested. The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of updating the instance. If the named instance - does not exist, returns ``NOT_FOUND``. - - Immediately upon completion of this request: - - - For resource types for which a decrease in the instance's - allocation has been requested, billing is based on the - newly-requested level. - - Until completion of the returned operation: - - - Cancelling the operation sets its metadata's - [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceMetadata.cancel_time], - and begins restoring resources to their pre-request values. - The operation is guaranteed to succeed at undoing all - resource changes, after which point it terminates with a - ``CANCELLED`` status. - - All other attempts to modify the instance are rejected. - - Reading the instance via the API continues to give the - pre-request resource levels. - - Upon completion of the returned operation: - - - Billing begins for all successfully-allocated resources (some - types may have lower than the requested levels). - - All newly-reserved resources are available for serving the - instance's tables. - - The instance's new resource levels are readable via the API. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and can be - used to track the instance modification. The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateInstanceMetadata][google.spanner.admin.instance.v1.UpdateInstanceMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Instance][google.spanner.admin.instance.v1.Instance], if - successful. - - Authorization requires ``spanner.instances.update`` permission - on the resource - [name][google.spanner.admin.instance.v1.Instance.name]. - - Returns: - Callable[[~.UpdateInstanceRequest], - ~.Operation]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'update_instance' not in self._stubs: - self._stubs['update_instance'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/UpdateInstance', - request_serializer=spanner_instance_admin.UpdateInstanceRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['update_instance'] - - @property - def delete_instance(self) -> Callable[ - [spanner_instance_admin.DeleteInstanceRequest], - empty_pb2.Empty]: - r"""Return a callable for the delete instance method over gRPC. - - Deletes an instance. - - Immediately upon completion of the request: - - - Billing ceases for all of the instance's reserved resources. - - Soon afterward: - - - The instance and *all of its databases* immediately and - irrevocably disappear from the API. All data in the databases - is permanently deleted. - - Returns: - Callable[[~.DeleteInstanceRequest], - ~.Empty]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'delete_instance' not in self._stubs: - self._stubs['delete_instance'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/DeleteInstance', - request_serializer=spanner_instance_admin.DeleteInstanceRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_instance'] - - @property - def set_iam_policy(self) -> Callable[ - [iam_policy_pb2.SetIamPolicyRequest], - policy_pb2.Policy]: - r"""Return a callable for the set iam policy method over gRPC. - - Sets the access control policy on an instance resource. Replaces - any existing policy. - - Authorization requires ``spanner.instances.setIamPolicy`` on - [resource][google.iam.v1.SetIamPolicyRequest.resource]. - - Returns: - Callable[[~.SetIamPolicyRequest], - ~.Policy]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'set_iam_policy' not in self._stubs: - self._stubs['set_iam_policy'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/SetIamPolicy', - request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, - response_deserializer=policy_pb2.Policy.FromString, - ) - return self._stubs['set_iam_policy'] - - @property - def get_iam_policy(self) -> Callable[ - [iam_policy_pb2.GetIamPolicyRequest], - policy_pb2.Policy]: - r"""Return a callable for the get iam policy method over gRPC. - - Gets the access control policy for an instance resource. Returns - an empty policy if an instance exists but does not have a policy - set. - - Authorization requires ``spanner.instances.getIamPolicy`` on - [resource][google.iam.v1.GetIamPolicyRequest.resource]. - - Returns: - Callable[[~.GetIamPolicyRequest], - ~.Policy]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_iam_policy' not in self._stubs: - self._stubs['get_iam_policy'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/GetIamPolicy', - request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, - response_deserializer=policy_pb2.Policy.FromString, - ) - return self._stubs['get_iam_policy'] - - @property - def test_iam_permissions(self) -> Callable[ - [iam_policy_pb2.TestIamPermissionsRequest], - iam_policy_pb2.TestIamPermissionsResponse]: - r"""Return a callable for the test iam permissions method over gRPC. - - Returns permissions that the caller has on the specified - instance resource. - - Attempting this RPC on a non-existent Cloud Spanner instance - resource will result in a NOT_FOUND error if the user has - ``spanner.instances.list`` permission on the containing Google - Cloud Project. Otherwise returns an empty set of permissions. - - Returns: - Callable[[~.TestIamPermissionsRequest], - ~.TestIamPermissionsResponse]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'test_iam_permissions' not in self._stubs: - self._stubs['test_iam_permissions'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/TestIamPermissions', - request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, - response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, - ) - return self._stubs['test_iam_permissions'] - - def close(self): - self.grpc_channel.close() - - @property - def kind(self) -> str: - return "grpc" - - -__all__ = ( - 'InstanceAdminGrpcTransport', -) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py deleted file mode 100644 index dd08641298..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py +++ /dev/null @@ -1,860 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import warnings -from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union - -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers_async -from google.api_core import operations_v1 -from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore - -import grpc # type: ignore -from grpc.experimental import aio # type: ignore - -from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin -from google.iam.v1 import iam_policy_pb2 # type: ignore -from google.iam.v1 import policy_pb2 # type: ignore -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore -from .base import InstanceAdminTransport, DEFAULT_CLIENT_INFO -from .grpc import InstanceAdminGrpcTransport - - -class InstanceAdminGrpcAsyncIOTransport(InstanceAdminTransport): - """gRPC AsyncIO backend transport for InstanceAdmin. - - Cloud Spanner Instance Admin API - The Cloud Spanner Instance Admin API can be used to create, - delete, modify and list instances. Instances are dedicated Cloud - Spanner serving and storage resources to be used by Cloud - Spanner databases. - Each instance has a "configuration", which dictates where the - serving resources for the Cloud Spanner instance are located - (e.g., US-central, Europe). Configurations are created by Google - based on resource availability. - - Cloud Spanner billing is based on the instances that exist and - their sizes. After an instance exists, there are no additional - per-database or per-operation charges for use of the instance - (though there may be additional network bandwidth charges). - Instances offer isolation: problems with databases in one - instance will not affect other instances. However, within an - instance databases can affect each other. For example, if one - database in an instance receives a lot of requests and consumes - most of the instance resources, fewer resources are available - for other databases in that instance, and their performance may - suffer. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends protocol buffers over the wire using gRPC (which is built on - top of HTTP/2); the ``grpcio`` package must be installed. - """ - - _grpc_channel: aio.Channel - _stubs: Dict[str, Callable] = {} - - @classmethod - def create_channel(cls, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - quota_project_id: Optional[str] = None, - **kwargs) -> aio.Channel: - """Create and return a gRPC AsyncIO channel object. - Args: - host (Optional[str]): The host for the channel to use. - credentials (Optional[~.Credentials]): The - authorization credentials to attach to requests. These - credentials identify this application to the service. If - none are specified, the client will attempt to ascertain - the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - kwargs (Optional[dict]): Keyword arguments, which are passed to the - channel creation. - Returns: - aio.Channel: A gRPC AsyncIO channel object. - """ - - return grpc_helpers_async.create_channel( - host, - credentials=credentials, - credentials_file=credentials_file, - quota_project_id=quota_project_id, - default_scopes=cls.AUTH_SCOPES, - scopes=scopes, - default_host=cls.DEFAULT_HOST, - **kwargs - ) - - def __init__(self, *, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - channel: Optional[aio.Channel] = None, - api_mtls_endpoint: Optional[str] = None, - client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, - client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - This argument is ignored if ``channel`` is provided. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional[Sequence[str]]): A optional list of scopes needed for this - service. These are only used when credentials are not specified and - are passed to :func:`google.auth.default`. - channel (Optional[aio.Channel]): A ``Channel`` instance through - which to make calls. - api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. - If provided, it overrides the ``host`` argument and tries to create - a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or application default SSL credentials. - client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): - Deprecated. A callback to provide client SSL certificate bytes and - private key bytes, both in PEM format. It is ignored if - ``api_mtls_endpoint`` is None. - ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for the grpc channel. It is ignored if ``channel`` is provided. - client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): - A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure a mutual TLS channel. It is - ignored if ``channel`` or ``ssl_channel_credentials`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - - Raises: - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport - creation failed for any reason. - google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` - and ``credentials_file`` are passed. - """ - self._grpc_channel = None - self._ssl_channel_credentials = ssl_channel_credentials - self._stubs: Dict[str, Callable] = {} - self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None - - if api_mtls_endpoint: - warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) - if client_cert_source: - warnings.warn("client_cert_source is deprecated", DeprecationWarning) - - if channel: - # Ignore credentials if a channel was passed. - credentials = False - # If a channel was explicitly provided, set it. - self._grpc_channel = channel - self._ssl_channel_credentials = None - else: - if api_mtls_endpoint: - host = api_mtls_endpoint - - # Create SSL credentials with client_cert_source or application - # default SSL credentials. - if client_cert_source: - cert, key = client_cert_source() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - else: - self._ssl_channel_credentials = SslCredentials().ssl_credentials - - else: - if client_cert_source_for_mtls and not ssl_channel_credentials: - cert, key = client_cert_source_for_mtls() - self._ssl_channel_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) - - # The base transport sets the host, credentials and scopes - super().__init__( - host=host, - credentials=credentials, - credentials_file=credentials_file, - scopes=scopes, - quota_project_id=quota_project_id, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience, - ) - - if not self._grpc_channel: - self._grpc_channel = type(self).create_channel( - self._host, - # use the credentials which are saved - credentials=self._credentials, - # Set ``credentials_file`` to ``None`` here as - # the credentials that we saved earlier should be used. - credentials_file=None, - scopes=self._scopes, - ssl_credentials=self._ssl_channel_credentials, - quota_project_id=quota_project_id, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Wrap messages. This must be done after self._grpc_channel exists - self._prep_wrapped_messages(client_info) - - @property - def grpc_channel(self) -> aio.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. - """ - # Return the channel from cache. - return self._grpc_channel - - @property - def operations_client(self) -> operations_v1.OperationsAsyncClient: - """Create the client designed to process long-running operations. - - This property caches on the instance; repeated calls return the same - client. - """ - # Quick check: Only create a new client if we do not already have one. - if self._operations_client is None: - self._operations_client = operations_v1.OperationsAsyncClient( - self.grpc_channel - ) - - # Return the client from cache. - return self._operations_client - - @property - def list_instance_configs(self) -> Callable[ - [spanner_instance_admin.ListInstanceConfigsRequest], - Awaitable[spanner_instance_admin.ListInstanceConfigsResponse]]: - r"""Return a callable for the list instance configs method over gRPC. - - Lists the supported instance configurations for a - given project. - - Returns: - Callable[[~.ListInstanceConfigsRequest], - Awaitable[~.ListInstanceConfigsResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_instance_configs' not in self._stubs: - self._stubs['list_instance_configs'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/ListInstanceConfigs', - request_serializer=spanner_instance_admin.ListInstanceConfigsRequest.serialize, - response_deserializer=spanner_instance_admin.ListInstanceConfigsResponse.deserialize, - ) - return self._stubs['list_instance_configs'] - - @property - def get_instance_config(self) -> Callable[ - [spanner_instance_admin.GetInstanceConfigRequest], - Awaitable[spanner_instance_admin.InstanceConfig]]: - r"""Return a callable for the get instance config method over gRPC. - - Gets information about a particular instance - configuration. - - Returns: - Callable[[~.GetInstanceConfigRequest], - Awaitable[~.InstanceConfig]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_instance_config' not in self._stubs: - self._stubs['get_instance_config'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/GetInstanceConfig', - request_serializer=spanner_instance_admin.GetInstanceConfigRequest.serialize, - response_deserializer=spanner_instance_admin.InstanceConfig.deserialize, - ) - return self._stubs['get_instance_config'] - - @property - def create_instance_config(self) -> Callable[ - [spanner_instance_admin.CreateInstanceConfigRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the create instance config method over gRPC. - - Creates an instance config and begins preparing it to be used. - The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of preparing the new instance config. The instance - config name is assigned by the caller. If the named instance - config already exists, ``CreateInstanceConfig`` returns - ``ALREADY_EXISTS``. - - Immediately after the request returns: - - - The instance config is readable via the API, with all - requested attributes. The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field is set to true. Its state is ``CREATING``. - - While the operation is pending: - - - Cancelling the operation renders the instance config - immediately unreadable via the API. - - Except for deleting the creating resource, all other attempts - to modify the instance config are rejected. - - Upon completion of the returned operation: - - - Instances can be created using the instance configuration. - - The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field becomes false. Its state becomes ``READY``. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and - can be used to track creation of the instance config. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. - The [response][google.longrunning.Operation.response] field type - is - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], - if successful. - - Authorization requires ``spanner.instanceConfigs.create`` - permission on the resource - [parent][google.spanner.admin.instance.v1.CreateInstanceConfigRequest.parent]. - - Returns: - Callable[[~.CreateInstanceConfigRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'create_instance_config' not in self._stubs: - self._stubs['create_instance_config'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/CreateInstanceConfig', - request_serializer=spanner_instance_admin.CreateInstanceConfigRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['create_instance_config'] - - @property - def update_instance_config(self) -> Callable[ - [spanner_instance_admin.UpdateInstanceConfigRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the update instance config method over gRPC. - - Updates an instance config. The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of updating the instance. If the named instance - config does not exist, returns ``NOT_FOUND``. - - Only user managed configurations can be updated. - - Immediately after the request returns: - - - The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field is set to true. - - While the operation is pending: - - - Cancelling the operation sets its metadata's - [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata.cancel_time]. - The operation is guaranteed to succeed at undoing all - changes, after which point it terminates with a ``CANCELLED`` - status. - - All other attempts to modify the instance config are - rejected. - - Reading the instance config via the API continues to give the - pre-request values. - - Upon completion of the returned operation: - - - Creating instances using the instance configuration uses the - new values. - - The instance config's new values are readable via the API. - - The instance config's - [reconciling][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - field becomes false. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and - can be used to track the instance config modification. The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateInstanceConfigMetadata][google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata]. - The [response][google.longrunning.Operation.response] field type - is - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig], - if successful. - - Authorization requires ``spanner.instanceConfigs.update`` - permission on the resource - [name][google.spanner.admin.instance.v1.InstanceConfig.name]. - - Returns: - Callable[[~.UpdateInstanceConfigRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'update_instance_config' not in self._stubs: - self._stubs['update_instance_config'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/UpdateInstanceConfig', - request_serializer=spanner_instance_admin.UpdateInstanceConfigRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['update_instance_config'] - - @property - def delete_instance_config(self) -> Callable[ - [spanner_instance_admin.DeleteInstanceConfigRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the delete instance config method over gRPC. - - Deletes the instance config. Deletion is only allowed when no - instances are using the configuration. If any instances are - using the config, returns ``FAILED_PRECONDITION``. - - Only user managed configurations can be deleted. - - Authorization requires ``spanner.instanceConfigs.delete`` - permission on the resource - [name][google.spanner.admin.instance.v1.InstanceConfig.name]. - - Returns: - Callable[[~.DeleteInstanceConfigRequest], - Awaitable[~.Empty]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'delete_instance_config' not in self._stubs: - self._stubs['delete_instance_config'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/DeleteInstanceConfig', - request_serializer=spanner_instance_admin.DeleteInstanceConfigRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_instance_config'] - - @property - def list_instance_config_operations(self) -> Callable[ - [spanner_instance_admin.ListInstanceConfigOperationsRequest], - Awaitable[spanner_instance_admin.ListInstanceConfigOperationsResponse]]: - r"""Return a callable for the list instance config - operations method over gRPC. - - Lists the user-managed instance config [long-running - operations][google.longrunning.Operation] in the given project. - An instance config operation has a name of the form - ``projects//instanceConfigs//operations/``. - The long-running operation - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - Operations returned include those that have - completed/failed/canceled within the last 7 days, and pending - operations. Operations returned are ordered by - ``operation.metadata.value.start_time`` in descending order - starting from the most recently started operation. - - Returns: - Callable[[~.ListInstanceConfigOperationsRequest], - Awaitable[~.ListInstanceConfigOperationsResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_instance_config_operations' not in self._stubs: - self._stubs['list_instance_config_operations'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/ListInstanceConfigOperations', - request_serializer=spanner_instance_admin.ListInstanceConfigOperationsRequest.serialize, - response_deserializer=spanner_instance_admin.ListInstanceConfigOperationsResponse.deserialize, - ) - return self._stubs['list_instance_config_operations'] - - @property - def list_instances(self) -> Callable[ - [spanner_instance_admin.ListInstancesRequest], - Awaitable[spanner_instance_admin.ListInstancesResponse]]: - r"""Return a callable for the list instances method over gRPC. - - Lists all instances in the given project. - - Returns: - Callable[[~.ListInstancesRequest], - Awaitable[~.ListInstancesResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'list_instances' not in self._stubs: - self._stubs['list_instances'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/ListInstances', - request_serializer=spanner_instance_admin.ListInstancesRequest.serialize, - response_deserializer=spanner_instance_admin.ListInstancesResponse.deserialize, - ) - return self._stubs['list_instances'] - - @property - def get_instance(self) -> Callable[ - [spanner_instance_admin.GetInstanceRequest], - Awaitable[spanner_instance_admin.Instance]]: - r"""Return a callable for the get instance method over gRPC. - - Gets information about a particular instance. - - Returns: - Callable[[~.GetInstanceRequest], - Awaitable[~.Instance]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_instance' not in self._stubs: - self._stubs['get_instance'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/GetInstance', - request_serializer=spanner_instance_admin.GetInstanceRequest.serialize, - response_deserializer=spanner_instance_admin.Instance.deserialize, - ) - return self._stubs['get_instance'] - - @property - def create_instance(self) -> Callable[ - [spanner_instance_admin.CreateInstanceRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the create instance method over gRPC. - - Creates an instance and begins preparing it to begin serving. - The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of preparing the new instance. The instance name is - assigned by the caller. If the named instance already exists, - ``CreateInstance`` returns ``ALREADY_EXISTS``. - - Immediately upon completion of this request: - - - The instance is readable via the API, with all requested - attributes but no allocated resources. Its state is - ``CREATING``. - - Until completion of the returned operation: - - - Cancelling the operation renders the instance immediately - unreadable via the API. - - The instance can be deleted. - - All other attempts to modify the instance are rejected. - - Upon completion of the returned operation: - - - Billing for all successfully-allocated resources begins (some - types may have lower than the requested levels). - - Databases can be created in the instance. - - The instance's allocated resource levels are readable via the - API. - - The instance's state becomes ``READY``. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and can be - used to track creation of the instance. The - [metadata][google.longrunning.Operation.metadata] field type is - [CreateInstanceMetadata][google.spanner.admin.instance.v1.CreateInstanceMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Instance][google.spanner.admin.instance.v1.Instance], if - successful. - - Returns: - Callable[[~.CreateInstanceRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'create_instance' not in self._stubs: - self._stubs['create_instance'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/CreateInstance', - request_serializer=spanner_instance_admin.CreateInstanceRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['create_instance'] - - @property - def update_instance(self) -> Callable[ - [spanner_instance_admin.UpdateInstanceRequest], - Awaitable[operations_pb2.Operation]]: - r"""Return a callable for the update instance method over gRPC. - - Updates an instance, and begins allocating or releasing - resources as requested. The returned [long-running - operation][google.longrunning.Operation] can be used to track - the progress of updating the instance. If the named instance - does not exist, returns ``NOT_FOUND``. - - Immediately upon completion of this request: - - - For resource types for which a decrease in the instance's - allocation has been requested, billing is based on the - newly-requested level. - - Until completion of the returned operation: - - - Cancelling the operation sets its metadata's - [cancel_time][google.spanner.admin.instance.v1.UpdateInstanceMetadata.cancel_time], - and begins restoring resources to their pre-request values. - The operation is guaranteed to succeed at undoing all - resource changes, after which point it terminates with a - ``CANCELLED`` status. - - All other attempts to modify the instance are rejected. - - Reading the instance via the API continues to give the - pre-request resource levels. - - Upon completion of the returned operation: - - - Billing begins for all successfully-allocated resources (some - types may have lower than the requested levels). - - All newly-reserved resources are available for serving the - instance's tables. - - The instance's new resource levels are readable via the API. - - The returned [long-running - operation][google.longrunning.Operation] will have a name of the - format ``/operations/`` and can be - used to track the instance modification. The - [metadata][google.longrunning.Operation.metadata] field type is - [UpdateInstanceMetadata][google.spanner.admin.instance.v1.UpdateInstanceMetadata]. - The [response][google.longrunning.Operation.response] field type - is [Instance][google.spanner.admin.instance.v1.Instance], if - successful. - - Authorization requires ``spanner.instances.update`` permission - on the resource - [name][google.spanner.admin.instance.v1.Instance.name]. - - Returns: - Callable[[~.UpdateInstanceRequest], - Awaitable[~.Operation]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'update_instance' not in self._stubs: - self._stubs['update_instance'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/UpdateInstance', - request_serializer=spanner_instance_admin.UpdateInstanceRequest.serialize, - response_deserializer=operations_pb2.Operation.FromString, - ) - return self._stubs['update_instance'] - - @property - def delete_instance(self) -> Callable[ - [spanner_instance_admin.DeleteInstanceRequest], - Awaitable[empty_pb2.Empty]]: - r"""Return a callable for the delete instance method over gRPC. - - Deletes an instance. - - Immediately upon completion of the request: - - - Billing ceases for all of the instance's reserved resources. - - Soon afterward: - - - The instance and *all of its databases* immediately and - irrevocably disappear from the API. All data in the databases - is permanently deleted. - - Returns: - Callable[[~.DeleteInstanceRequest], - Awaitable[~.Empty]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'delete_instance' not in self._stubs: - self._stubs['delete_instance'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/DeleteInstance', - request_serializer=spanner_instance_admin.DeleteInstanceRequest.serialize, - response_deserializer=empty_pb2.Empty.FromString, - ) - return self._stubs['delete_instance'] - - @property - def set_iam_policy(self) -> Callable[ - [iam_policy_pb2.SetIamPolicyRequest], - Awaitable[policy_pb2.Policy]]: - r"""Return a callable for the set iam policy method over gRPC. - - Sets the access control policy on an instance resource. Replaces - any existing policy. - - Authorization requires ``spanner.instances.setIamPolicy`` on - [resource][google.iam.v1.SetIamPolicyRequest.resource]. - - Returns: - Callable[[~.SetIamPolicyRequest], - Awaitable[~.Policy]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'set_iam_policy' not in self._stubs: - self._stubs['set_iam_policy'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/SetIamPolicy', - request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, - response_deserializer=policy_pb2.Policy.FromString, - ) - return self._stubs['set_iam_policy'] - - @property - def get_iam_policy(self) -> Callable[ - [iam_policy_pb2.GetIamPolicyRequest], - Awaitable[policy_pb2.Policy]]: - r"""Return a callable for the get iam policy method over gRPC. - - Gets the access control policy for an instance resource. Returns - an empty policy if an instance exists but does not have a policy - set. - - Authorization requires ``spanner.instances.getIamPolicy`` on - [resource][google.iam.v1.GetIamPolicyRequest.resource]. - - Returns: - Callable[[~.GetIamPolicyRequest], - Awaitable[~.Policy]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'get_iam_policy' not in self._stubs: - self._stubs['get_iam_policy'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/GetIamPolicy', - request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, - response_deserializer=policy_pb2.Policy.FromString, - ) - return self._stubs['get_iam_policy'] - - @property - def test_iam_permissions(self) -> Callable[ - [iam_policy_pb2.TestIamPermissionsRequest], - Awaitable[iam_policy_pb2.TestIamPermissionsResponse]]: - r"""Return a callable for the test iam permissions method over gRPC. - - Returns permissions that the caller has on the specified - instance resource. - - Attempting this RPC on a non-existent Cloud Spanner instance - resource will result in a NOT_FOUND error if the user has - ``spanner.instances.list`` permission on the containing Google - Cloud Project. Otherwise returns an empty set of permissions. - - Returns: - Callable[[~.TestIamPermissionsRequest], - Awaitable[~.TestIamPermissionsResponse]]: - A function that, when called, will call the underlying RPC - on the server. - """ - # Generate a "stub function" on-the-fly which will actually make - # the request. - # gRPC handles serialization and deserialization, so we just need - # to pass in the functions for each. - if 'test_iam_permissions' not in self._stubs: - self._stubs['test_iam_permissions'] = self.grpc_channel.unary_unary( - '/google.spanner.admin.instance.v1.InstanceAdmin/TestIamPermissions', - request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, - response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, - ) - return self._stubs['test_iam_permissions'] - - def close(self): - return self.grpc_channel.close() - - -__all__ = ( - 'InstanceAdminGrpcAsyncIOTransport', -) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest.py deleted file mode 100644 index 689055a758..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest.py +++ /dev/null @@ -1,2003 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from google.auth.transport.requests import AuthorizedSession # type: ignore -import json # type: ignore -import grpc # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth import credentials as ga_credentials # type: ignore -from google.api_core import exceptions as core_exceptions -from google.api_core import retry as retries -from google.api_core import rest_helpers -from google.api_core import rest_streaming -from google.api_core import path_template -from google.api_core import gapic_v1 - -from google.protobuf import json_format -from google.api_core import operations_v1 -from requests import __version__ as requests_version -import dataclasses -import re -from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union -import warnings - -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object] # type: ignore - - -from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin -from google.iam.v1 import iam_policy_pb2 # type: ignore -from google.iam.v1 import policy_pb2 # type: ignore -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore - -from .base import InstanceAdminTransport, DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO - - -DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( - gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, - grpc_version=None, - rest_version=requests_version, -) - - -class InstanceAdminRestInterceptor: - """Interceptor for InstanceAdmin. - - Interceptors are used to manipulate requests, request metadata, and responses - in arbitrary ways. - Example use cases include: - * Logging - * Verifying requests according to service or custom semantics - * Stripping extraneous information from responses - - These use cases and more can be enabled by injecting an - instance of a custom subclass when constructing the InstanceAdminRestTransport. - - .. code-block:: python - class MyCustomInstanceAdminInterceptor(InstanceAdminRestInterceptor): - def pre_create_instance(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_create_instance(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_create_instance_config(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_create_instance_config(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_delete_instance(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def pre_delete_instance_config(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def pre_get_iam_policy(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_get_iam_policy(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_get_instance(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_get_instance(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_get_instance_config(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_get_instance_config(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_list_instance_config_operations(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_list_instance_config_operations(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_list_instance_configs(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_list_instance_configs(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_list_instances(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_list_instances(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_set_iam_policy(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_set_iam_policy(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_test_iam_permissions(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_test_iam_permissions(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_update_instance(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_update_instance(self, response): - logging.log(f"Received response: {response}") - return response - - def pre_update_instance_config(self, request, metadata): - logging.log(f"Received request: {request}") - return request, metadata - - def post_update_instance_config(self, response): - logging.log(f"Received response: {response}") - return response - - transport = InstanceAdminRestTransport(interceptor=MyCustomInstanceAdminInterceptor()) - client = InstanceAdminClient(transport=transport) - - - """ - def pre_create_instance(self, request: spanner_instance_admin.CreateInstanceRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.CreateInstanceRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for create_instance - - Override in a subclass to manipulate the request or metadata - before they are sent to the InstanceAdmin server. - """ - return request, metadata - - def post_create_instance(self, response: operations_pb2.Operation) -> operations_pb2.Operation: - """Post-rpc interceptor for create_instance - - Override in a subclass to manipulate the response - after it is returned by the InstanceAdmin server but before - it is returned to user code. - """ - return response - def pre_create_instance_config(self, request: spanner_instance_admin.CreateInstanceConfigRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.CreateInstanceConfigRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for create_instance_config - - Override in a subclass to manipulate the request or metadata - before they are sent to the InstanceAdmin server. - """ - return request, metadata - - def post_create_instance_config(self, response: operations_pb2.Operation) -> operations_pb2.Operation: - """Post-rpc interceptor for create_instance_config - - Override in a subclass to manipulate the response - after it is returned by the InstanceAdmin server but before - it is returned to user code. - """ - return response - def pre_delete_instance(self, request: spanner_instance_admin.DeleteInstanceRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.DeleteInstanceRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for delete_instance - - Override in a subclass to manipulate the request or metadata - before they are sent to the InstanceAdmin server. - """ - return request, metadata - - def pre_delete_instance_config(self, request: spanner_instance_admin.DeleteInstanceConfigRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.DeleteInstanceConfigRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for delete_instance_config - - Override in a subclass to manipulate the request or metadata - before they are sent to the InstanceAdmin server. - """ - return request, metadata - - def pre_get_iam_policy(self, request: iam_policy_pb2.GetIamPolicyRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[iam_policy_pb2.GetIamPolicyRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for get_iam_policy - - Override in a subclass to manipulate the request or metadata - before they are sent to the InstanceAdmin server. - """ - return request, metadata - - def post_get_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: - """Post-rpc interceptor for get_iam_policy - - Override in a subclass to manipulate the response - after it is returned by the InstanceAdmin server but before - it is returned to user code. - """ - return response - def pre_get_instance(self, request: spanner_instance_admin.GetInstanceRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.GetInstanceRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for get_instance - - Override in a subclass to manipulate the request or metadata - before they are sent to the InstanceAdmin server. - """ - return request, metadata - - def post_get_instance(self, response: spanner_instance_admin.Instance) -> spanner_instance_admin.Instance: - """Post-rpc interceptor for get_instance - - Override in a subclass to manipulate the response - after it is returned by the InstanceAdmin server but before - it is returned to user code. - """ - return response - def pre_get_instance_config(self, request: spanner_instance_admin.GetInstanceConfigRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.GetInstanceConfigRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for get_instance_config - - Override in a subclass to manipulate the request or metadata - before they are sent to the InstanceAdmin server. - """ - return request, metadata - - def post_get_instance_config(self, response: spanner_instance_admin.InstanceConfig) -> spanner_instance_admin.InstanceConfig: - """Post-rpc interceptor for get_instance_config - - Override in a subclass to manipulate the response - after it is returned by the InstanceAdmin server but before - it is returned to user code. - """ - return response - def pre_list_instance_config_operations(self, request: spanner_instance_admin.ListInstanceConfigOperationsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.ListInstanceConfigOperationsRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for list_instance_config_operations - - Override in a subclass to manipulate the request or metadata - before they are sent to the InstanceAdmin server. - """ - return request, metadata - - def post_list_instance_config_operations(self, response: spanner_instance_admin.ListInstanceConfigOperationsResponse) -> spanner_instance_admin.ListInstanceConfigOperationsResponse: - """Post-rpc interceptor for list_instance_config_operations - - Override in a subclass to manipulate the response - after it is returned by the InstanceAdmin server but before - it is returned to user code. - """ - return response - def pre_list_instance_configs(self, request: spanner_instance_admin.ListInstanceConfigsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.ListInstanceConfigsRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for list_instance_configs - - Override in a subclass to manipulate the request or metadata - before they are sent to the InstanceAdmin server. - """ - return request, metadata - - def post_list_instance_configs(self, response: spanner_instance_admin.ListInstanceConfigsResponse) -> spanner_instance_admin.ListInstanceConfigsResponse: - """Post-rpc interceptor for list_instance_configs - - Override in a subclass to manipulate the response - after it is returned by the InstanceAdmin server but before - it is returned to user code. - """ - return response - def pre_list_instances(self, request: spanner_instance_admin.ListInstancesRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.ListInstancesRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for list_instances - - Override in a subclass to manipulate the request or metadata - before they are sent to the InstanceAdmin server. - """ - return request, metadata - - def post_list_instances(self, response: spanner_instance_admin.ListInstancesResponse) -> spanner_instance_admin.ListInstancesResponse: - """Post-rpc interceptor for list_instances - - Override in a subclass to manipulate the response - after it is returned by the InstanceAdmin server but before - it is returned to user code. - """ - return response - def pre_set_iam_policy(self, request: iam_policy_pb2.SetIamPolicyRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[iam_policy_pb2.SetIamPolicyRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for set_iam_policy - - Override in a subclass to manipulate the request or metadata - before they are sent to the InstanceAdmin server. - """ - return request, metadata - - def post_set_iam_policy(self, response: policy_pb2.Policy) -> policy_pb2.Policy: - """Post-rpc interceptor for set_iam_policy - - Override in a subclass to manipulate the response - after it is returned by the InstanceAdmin server but before - it is returned to user code. - """ - return response - def pre_test_iam_permissions(self, request: iam_policy_pb2.TestIamPermissionsRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[iam_policy_pb2.TestIamPermissionsRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for test_iam_permissions - - Override in a subclass to manipulate the request or metadata - before they are sent to the InstanceAdmin server. - """ - return request, metadata - - def post_test_iam_permissions(self, response: iam_policy_pb2.TestIamPermissionsResponse) -> iam_policy_pb2.TestIamPermissionsResponse: - """Post-rpc interceptor for test_iam_permissions - - Override in a subclass to manipulate the response - after it is returned by the InstanceAdmin server but before - it is returned to user code. - """ - return response - def pre_update_instance(self, request: spanner_instance_admin.UpdateInstanceRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.UpdateInstanceRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for update_instance - - Override in a subclass to manipulate the request or metadata - before they are sent to the InstanceAdmin server. - """ - return request, metadata - - def post_update_instance(self, response: operations_pb2.Operation) -> operations_pb2.Operation: - """Post-rpc interceptor for update_instance - - Override in a subclass to manipulate the response - after it is returned by the InstanceAdmin server but before - it is returned to user code. - """ - return response - def pre_update_instance_config(self, request: spanner_instance_admin.UpdateInstanceConfigRequest, metadata: Sequence[Tuple[str, str]]) -> Tuple[spanner_instance_admin.UpdateInstanceConfigRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for update_instance_config - - Override in a subclass to manipulate the request or metadata - before they are sent to the InstanceAdmin server. - """ - return request, metadata - - def post_update_instance_config(self, response: operations_pb2.Operation) -> operations_pb2.Operation: - """Post-rpc interceptor for update_instance_config - - Override in a subclass to manipulate the response - after it is returned by the InstanceAdmin server but before - it is returned to user code. - """ - return response - - -@dataclasses.dataclass -class InstanceAdminRestStub: - _session: AuthorizedSession - _host: str - _interceptor: InstanceAdminRestInterceptor - - -class InstanceAdminRestTransport(InstanceAdminTransport): - """REST backend transport for InstanceAdmin. - - Cloud Spanner Instance Admin API - The Cloud Spanner Instance Admin API can be used to create, - delete, modify and list instances. Instances are dedicated Cloud - Spanner serving and storage resources to be used by Cloud - Spanner databases. - Each instance has a "configuration", which dictates where the - serving resources for the Cloud Spanner instance are located - (e.g., US-central, Europe). Configurations are created by Google - based on resource availability. - - Cloud Spanner billing is based on the instances that exist and - their sizes. After an instance exists, there are no additional - per-database or per-operation charges for use of the instance - (though there may be additional network bandwidth charges). - Instances offer isolation: problems with databases in one - instance will not affect other instances. However, within an - instance databases can affect each other. For example, if one - database in an instance receives a lot of requests and consumes - most of the instance resources, fewer resources are available - for other databases in that instance, and their performance may - suffer. - - This class defines the same methods as the primary client, so the - primary client can load the underlying transport implementation - and call it. - - It sends JSON representations of protocol buffers over HTTP/1.1 - - """ - - def __init__(self, *, - host: str = 'spanner.googleapis.com', - credentials: Optional[ga_credentials.Credentials] = None, - credentials_file: Optional[str] = None, - scopes: Optional[Sequence[str]] = None, - client_cert_source_for_mtls: Optional[Callable[[ - ], Tuple[bytes, bytes]]] = None, - quota_project_id: Optional[str] = None, - client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, - always_use_jwt_access: Optional[bool] = False, - url_scheme: str = 'https', - interceptor: Optional[InstanceAdminRestInterceptor] = None, - api_audience: Optional[str] = None, - ) -> None: - """Instantiate the transport. - - Args: - host (Optional[str]): - The hostname to connect to. - credentials (Optional[google.auth.credentials.Credentials]): The - authorization credentials to attach to requests. These - credentials identify the application to the service; if none - are specified, the client will attempt to ascertain the - credentials from the environment. - - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client - certificate to configure mutual TLS HTTP channel. It is ignored - if ``channel`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you are developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - url_scheme: the protocol scheme for the API endpoint. Normally - "https", but for testing or local servers, - "http" can be specified. - """ - # Run the base constructor - # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. - # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the - # credentials object - maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) - if maybe_url_match is None: - raise ValueError(f"Unexpected hostname structure: {host}") # pragma: NO COVER - - url_match_items = maybe_url_match.groupdict() - - host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host - - super().__init__( - host=host, - credentials=credentials, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience - ) - self._session = AuthorizedSession( - self._credentials, default_host=self.DEFAULT_HOST) - self._operations_client: Optional[operations_v1.AbstractOperationsClient] = None - if client_cert_source_for_mtls: - self._session.configure_mtls_channel(client_cert_source_for_mtls) - self._interceptor = interceptor or InstanceAdminRestInterceptor() - self._prep_wrapped_messages(client_info) - - @property - def operations_client(self) -> operations_v1.AbstractOperationsClient: - """Create the client designed to process long-running operations. - - This property caches on the instance; repeated calls return the same - client. - """ - # Only create a new client if we do not already have one. - if self._operations_client is None: - http_options: Dict[str, List[Dict[str, str]]] = { - 'google.longrunning.Operations.GetOperation': [ - { - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}', - }, - { - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/operations/*}', - }, - ], - 'google.longrunning.Operations.ListOperations': [ - { - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations}', - }, - { - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*/operations}', - }, - ], - 'google.longrunning.Operations.CancelOperation': [ - { - 'method': 'post', - 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}:cancel', - }, - { - 'method': 'post', - 'uri': '/v1/{name=projects/*/instances/*/operations/*}:cancel', - }, - ], - 'google.longrunning.Operations.DeleteOperation': [ - { - 'method': 'delete', - 'uri': '/v1/{name=projects/*/instances/*/databases/*/operations/*}', - }, - { - 'method': 'delete', - 'uri': '/v1/{name=projects/*/instances/*/operations/*}', - }, - ], - } - - rest_transport = operations_v1.OperationsRestTransport( - host=self._host, - # use the credentials which are saved - credentials=self._credentials, - scopes=self._scopes, - http_options=http_options, - path_prefix="v1") - - self._operations_client = operations_v1.AbstractOperationsClient(transport=rest_transport) - - # Return the client from cache. - return self._operations_client - - class _CreateInstance(InstanceAdminRestStub): - def __hash__(self): - return hash("CreateInstance") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_instance_admin.CreateInstanceRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> operations_pb2.Operation: - r"""Call the create instance method over HTTP. - - Args: - request (~.spanner_instance_admin.CreateInstanceRequest): - The request object. The request for - [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.operations_pb2.Operation: - This resource represents a - long-running operation that is the - result of a network API call. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{parent=projects/*}/instances', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_create_instance(request, metadata) - pb_request = spanner_instance_admin.CreateInstanceRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = operations_pb2.Operation() - json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_create_instance(resp) - return resp - - class _CreateInstanceConfig(InstanceAdminRestStub): - def __hash__(self): - return hash("CreateInstanceConfig") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_instance_admin.CreateInstanceConfigRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> operations_pb2.Operation: - r"""Call the create instance config method over HTTP. - - Args: - request (~.spanner_instance_admin.CreateInstanceConfigRequest): - The request object. The request for - [CreateInstanceConfigRequest][InstanceAdmin.CreateInstanceConfigRequest]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.operations_pb2.Operation: - This resource represents a - long-running operation that is the - result of a network API call. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{parent=projects/*}/instanceConfigs', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_create_instance_config(request, metadata) - pb_request = spanner_instance_admin.CreateInstanceConfigRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = operations_pb2.Operation() - json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_create_instance_config(resp) - return resp - - class _DeleteInstance(InstanceAdminRestStub): - def __hash__(self): - return hash("DeleteInstance") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_instance_admin.DeleteInstanceRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ): - r"""Call the delete instance method over HTTP. - - Args: - request (~.spanner_instance_admin.DeleteInstanceRequest): - The request object. The request for - [DeleteInstance][google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'delete', - 'uri': '/v1/{name=projects/*/instances/*}', - }, - ] - request, metadata = self._interceptor.pre_delete_instance(request, metadata) - pb_request = spanner_instance_admin.DeleteInstanceRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - class _DeleteInstanceConfig(InstanceAdminRestStub): - def __hash__(self): - return hash("DeleteInstanceConfig") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_instance_admin.DeleteInstanceConfigRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ): - r"""Call the delete instance config method over HTTP. - - Args: - request (~.spanner_instance_admin.DeleteInstanceConfigRequest): - The request object. The request for - [DeleteInstanceConfigRequest][InstanceAdmin.DeleteInstanceConfigRequest]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'delete', - 'uri': '/v1/{name=projects/*/instanceConfigs/*}', - }, - ] - request, metadata = self._interceptor.pre_delete_instance_config(request, metadata) - pb_request = spanner_instance_admin.DeleteInstanceConfigRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - class _GetIamPolicy(InstanceAdminRestStub): - def __hash__(self): - return hash("GetIamPolicy") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: iam_policy_pb2.GetIamPolicyRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> policy_pb2.Policy: - r"""Call the get iam policy method over HTTP. - - Args: - request (~.iam_policy_pb2.GetIamPolicyRequest): - The request object. Request message for ``GetIamPolicy`` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.policy_pb2.Policy: - An Identity and Access Management (IAM) policy, which - specifies access controls for Google Cloud resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members``, or - principals, to a single ``role``. Principals can be user - accounts, service accounts, Google groups, and domains - (such as G Suite). A ``role`` is a named list of - permissions; each ``role`` can be an IAM predefined role - or a user-created custom role. - - For some types of Google Cloud resources, a ``binding`` - can also specify a ``condition``, which is a logical - expression that allows access to a resource only if the - expression evaluates to ``true``. A condition can add - constraints based on attributes of the request, the - resource, or both. To learn which resources support - conditions in their IAM policies, see the `IAM - documentation `__. - - **JSON example:** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": [ - "user:eve@example.com" - ], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ], - "etag": "BwWWja0YfJA=", - "version": 3 - } - - **YAML example:** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - etag: BwWWja0YfJA= - version: 3 - - For a description of IAM and its features, see the `IAM - documentation `__. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{resource=projects/*/instances/*}:getIamPolicy', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_get_iam_policy(request, metadata) - pb_request = request - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = policy_pb2.Policy() - pb_resp = resp - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_iam_policy(resp) - return resp - - class _GetInstance(InstanceAdminRestStub): - def __hash__(self): - return hash("GetInstance") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_instance_admin.GetInstanceRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner_instance_admin.Instance: - r"""Call the get instance method over HTTP. - - Args: - request (~.spanner_instance_admin.GetInstanceRequest): - The request object. The request for - [GetInstance][google.spanner.admin.instance.v1.InstanceAdmin.GetInstance]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner_instance_admin.Instance: - An isolated set of Cloud Spanner - resources on which databases can be - hosted. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{name=projects/*/instances/*}', - }, - ] - request, metadata = self._interceptor.pre_get_instance(request, metadata) - pb_request = spanner_instance_admin.GetInstanceRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner_instance_admin.Instance() - pb_resp = spanner_instance_admin.Instance.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_instance(resp) - return resp - - class _GetInstanceConfig(InstanceAdminRestStub): - def __hash__(self): - return hash("GetInstanceConfig") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_instance_admin.GetInstanceConfigRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner_instance_admin.InstanceConfig: - r"""Call the get instance config method over HTTP. - - Args: - request (~.spanner_instance_admin.GetInstanceConfigRequest): - The request object. The request for - [GetInstanceConfigRequest][google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner_instance_admin.InstanceConfig: - A possible configuration for a Cloud - Spanner instance. Configurations define - the geographic placement of nodes and - their replication. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{name=projects/*/instanceConfigs/*}', - }, - ] - request, metadata = self._interceptor.pre_get_instance_config(request, metadata) - pb_request = spanner_instance_admin.GetInstanceConfigRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner_instance_admin.InstanceConfig() - pb_resp = spanner_instance_admin.InstanceConfig.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_instance_config(resp) - return resp - - class _ListInstanceConfigOperations(InstanceAdminRestStub): - def __hash__(self): - return hash("ListInstanceConfigOperations") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_instance_admin.ListInstanceConfigOperationsRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner_instance_admin.ListInstanceConfigOperationsResponse: - r"""Call the list instance config - operations method over HTTP. - - Args: - request (~.spanner_instance_admin.ListInstanceConfigOperationsRequest): - The request object. The request for - [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner_instance_admin.ListInstanceConfigOperationsResponse: - The response for - [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{parent=projects/*}/instanceConfigOperations', - }, - ] - request, metadata = self._interceptor.pre_list_instance_config_operations(request, metadata) - pb_request = spanner_instance_admin.ListInstanceConfigOperationsRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner_instance_admin.ListInstanceConfigOperationsResponse() - pb_resp = spanner_instance_admin.ListInstanceConfigOperationsResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_instance_config_operations(resp) - return resp - - class _ListInstanceConfigs(InstanceAdminRestStub): - def __hash__(self): - return hash("ListInstanceConfigs") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_instance_admin.ListInstanceConfigsRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner_instance_admin.ListInstanceConfigsResponse: - r"""Call the list instance configs method over HTTP. - - Args: - request (~.spanner_instance_admin.ListInstanceConfigsRequest): - The request object. The request for - [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner_instance_admin.ListInstanceConfigsResponse: - The response for - [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{parent=projects/*}/instanceConfigs', - }, - ] - request, metadata = self._interceptor.pre_list_instance_configs(request, metadata) - pb_request = spanner_instance_admin.ListInstanceConfigsRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner_instance_admin.ListInstanceConfigsResponse() - pb_resp = spanner_instance_admin.ListInstanceConfigsResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_instance_configs(resp) - return resp - - class _ListInstances(InstanceAdminRestStub): - def __hash__(self): - return hash("ListInstances") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_instance_admin.ListInstancesRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> spanner_instance_admin.ListInstancesResponse: - r"""Call the list instances method over HTTP. - - Args: - request (~.spanner_instance_admin.ListInstancesRequest): - The request object. The request for - [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.spanner_instance_admin.ListInstancesResponse: - The response for - [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'get', - 'uri': '/v1/{parent=projects/*}/instances', - }, - ] - request, metadata = self._interceptor.pre_list_instances(request, metadata) - pb_request = spanner_instance_admin.ListInstancesRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = spanner_instance_admin.ListInstancesResponse() - pb_resp = spanner_instance_admin.ListInstancesResponse.pb(resp) - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_instances(resp) - return resp - - class _SetIamPolicy(InstanceAdminRestStub): - def __hash__(self): - return hash("SetIamPolicy") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: iam_policy_pb2.SetIamPolicyRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> policy_pb2.Policy: - r"""Call the set iam policy method over HTTP. - - Args: - request (~.iam_policy_pb2.SetIamPolicyRequest): - The request object. Request message for ``SetIamPolicy`` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.policy_pb2.Policy: - An Identity and Access Management (IAM) policy, which - specifies access controls for Google Cloud resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members``, or - principals, to a single ``role``. Principals can be user - accounts, service accounts, Google groups, and domains - (such as G Suite). A ``role`` is a named list of - permissions; each ``role`` can be an IAM predefined role - or a user-created custom role. - - For some types of Google Cloud resources, a ``binding`` - can also specify a ``condition``, which is a logical - expression that allows access to a resource only if the - expression evaluates to ``true``. A condition can add - constraints based on attributes of the request, the - resource, or both. To learn which resources support - conditions in their IAM policies, see the `IAM - documentation `__. - - **JSON example:** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": [ - "user:eve@example.com" - ], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ], - "etag": "BwWWja0YfJA=", - "version": 3 - } - - **YAML example:** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - etag: BwWWja0YfJA= - version: 3 - - For a description of IAM and its features, see the `IAM - documentation `__. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{resource=projects/*/instances/*}:setIamPolicy', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_set_iam_policy(request, metadata) - pb_request = request - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = policy_pb2.Policy() - pb_resp = resp - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_set_iam_policy(resp) - return resp - - class _TestIamPermissions(InstanceAdminRestStub): - def __hash__(self): - return hash("TestIamPermissions") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: iam_policy_pb2.TestIamPermissionsRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> iam_policy_pb2.TestIamPermissionsResponse: - r"""Call the test iam permissions method over HTTP. - - Args: - request (~.iam_policy_pb2.TestIamPermissionsRequest): - The request object. Request message for ``TestIamPermissions`` method. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.iam_policy_pb2.TestIamPermissionsResponse: - Response message for ``TestIamPermissions`` method. - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'post', - 'uri': '/v1/{resource=projects/*/instances/*}:testIamPermissions', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_test_iam_permissions(request, metadata) - pb_request = request - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = iam_policy_pb2.TestIamPermissionsResponse() - pb_resp = resp - - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_test_iam_permissions(resp) - return resp - - class _UpdateInstance(InstanceAdminRestStub): - def __hash__(self): - return hash("UpdateInstance") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_instance_admin.UpdateInstanceRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> operations_pb2.Operation: - r"""Call the update instance method over HTTP. - - Args: - request (~.spanner_instance_admin.UpdateInstanceRequest): - The request object. The request for - [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.operations_pb2.Operation: - This resource represents a - long-running operation that is the - result of a network API call. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'patch', - 'uri': '/v1/{instance.name=projects/*/instances/*}', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_update_instance(request, metadata) - pb_request = spanner_instance_admin.UpdateInstanceRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = operations_pb2.Operation() - json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_update_instance(resp) - return resp - - class _UpdateInstanceConfig(InstanceAdminRestStub): - def __hash__(self): - return hash("UpdateInstanceConfig") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return {k: v for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() if k not in message_dict} - - def __call__(self, - request: spanner_instance_admin.UpdateInstanceConfigRequest, *, - retry: OptionalRetry=gapic_v1.method.DEFAULT, - timeout: Optional[float]=None, - metadata: Sequence[Tuple[str, str]]=(), - ) -> operations_pb2.Operation: - r"""Call the update instance config method over HTTP. - - Args: - request (~.spanner_instance_admin.UpdateInstanceConfigRequest): - The request object. The request for - [UpdateInstanceConfigRequest][InstanceAdmin.UpdateInstanceConfigRequest]. - retry (google.api_core.retry.Retry): Designation of what errors, if any, - should be retried. - timeout (float): The timeout for this request. - metadata (Sequence[Tuple[str, str]]): Strings which should be - sent along with the request as metadata. - - Returns: - ~.operations_pb2.Operation: - This resource represents a - long-running operation that is the - result of a network API call. - - """ - - http_options: List[Dict[str, str]] = [{ - 'method': 'patch', - 'uri': '/v1/{instance_config.name=projects/*/instanceConfigs/*}', - 'body': '*', - }, - ] - request, metadata = self._interceptor.pre_update_instance_config(request, metadata) - pb_request = spanner_instance_admin.UpdateInstanceConfigRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - - body = json_format.MessageToJson( - transcoded_request['body'], - including_default_value_fields=False, - use_integers_for_enums=True - ) - uri = transcoded_request['uri'] - method = transcoded_request['method'] - - # Jsonify the query params - query_params = json.loads(json_format.MessageToJson( - transcoded_request['query_params'], - including_default_value_fields=False, - use_integers_for_enums=True, - )) - query_params.update(self._get_unset_required_fields(query_params)) - - query_params["$alt"] = "json;enum-encoding=int" - - # Send the request - headers = dict(metadata) - headers['Content-Type'] = 'application/json' - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, - ) - - # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception - # subclass. - if response.status_code >= 400: - raise core_exceptions.from_http_response(response) - - # Return the response - resp = operations_pb2.Operation() - json_format.Parse(response.content, resp, ignore_unknown_fields=True) - resp = self._interceptor.post_update_instance_config(resp) - return resp - - @property - def create_instance(self) -> Callable[ - [spanner_instance_admin.CreateInstanceRequest], - operations_pb2.Operation]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._CreateInstance(self._session, self._host, self._interceptor) # type: ignore - - @property - def create_instance_config(self) -> Callable[ - [spanner_instance_admin.CreateInstanceConfigRequest], - operations_pb2.Operation]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._CreateInstanceConfig(self._session, self._host, self._interceptor) # type: ignore - - @property - def delete_instance(self) -> Callable[ - [spanner_instance_admin.DeleteInstanceRequest], - empty_pb2.Empty]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._DeleteInstance(self._session, self._host, self._interceptor) # type: ignore - - @property - def delete_instance_config(self) -> Callable[ - [spanner_instance_admin.DeleteInstanceConfigRequest], - empty_pb2.Empty]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._DeleteInstanceConfig(self._session, self._host, self._interceptor) # type: ignore - - @property - def get_iam_policy(self) -> Callable[ - [iam_policy_pb2.GetIamPolicyRequest], - policy_pb2.Policy]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._GetIamPolicy(self._session, self._host, self._interceptor) # type: ignore - - @property - def get_instance(self) -> Callable[ - [spanner_instance_admin.GetInstanceRequest], - spanner_instance_admin.Instance]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._GetInstance(self._session, self._host, self._interceptor) # type: ignore - - @property - def get_instance_config(self) -> Callable[ - [spanner_instance_admin.GetInstanceConfigRequest], - spanner_instance_admin.InstanceConfig]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._GetInstanceConfig(self._session, self._host, self._interceptor) # type: ignore - - @property - def list_instance_config_operations(self) -> Callable[ - [spanner_instance_admin.ListInstanceConfigOperationsRequest], - spanner_instance_admin.ListInstanceConfigOperationsResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._ListInstanceConfigOperations(self._session, self._host, self._interceptor) # type: ignore - - @property - def list_instance_configs(self) -> Callable[ - [spanner_instance_admin.ListInstanceConfigsRequest], - spanner_instance_admin.ListInstanceConfigsResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._ListInstanceConfigs(self._session, self._host, self._interceptor) # type: ignore - - @property - def list_instances(self) -> Callable[ - [spanner_instance_admin.ListInstancesRequest], - spanner_instance_admin.ListInstancesResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._ListInstances(self._session, self._host, self._interceptor) # type: ignore - - @property - def set_iam_policy(self) -> Callable[ - [iam_policy_pb2.SetIamPolicyRequest], - policy_pb2.Policy]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._SetIamPolicy(self._session, self._host, self._interceptor) # type: ignore - - @property - def test_iam_permissions(self) -> Callable[ - [iam_policy_pb2.TestIamPermissionsRequest], - iam_policy_pb2.TestIamPermissionsResponse]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._TestIamPermissions(self._session, self._host, self._interceptor) # type: ignore - - @property - def update_instance(self) -> Callable[ - [spanner_instance_admin.UpdateInstanceRequest], - operations_pb2.Operation]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._UpdateInstance(self._session, self._host, self._interceptor) # type: ignore - - @property - def update_instance_config(self) -> Callable[ - [spanner_instance_admin.UpdateInstanceConfigRequest], - operations_pb2.Operation]: - # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. - # In C++ this would require a dynamic_cast - return self._UpdateInstanceConfig(self._session, self._host, self._interceptor) # type: ignore - - @property - def kind(self) -> str: - return "rest" - - def close(self): - self._session.close() - - -__all__=( - 'InstanceAdminRestTransport', -) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/__init__.py deleted file mode 100644 index 5631a2a2ca..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/__init__.py +++ /dev/null @@ -1,66 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from .common import ( - OperationProgress, -) -from .spanner_instance_admin import ( - CreateInstanceConfigMetadata, - CreateInstanceConfigRequest, - CreateInstanceMetadata, - CreateInstanceRequest, - DeleteInstanceConfigRequest, - DeleteInstanceRequest, - GetInstanceConfigRequest, - GetInstanceRequest, - Instance, - InstanceConfig, - ListInstanceConfigOperationsRequest, - ListInstanceConfigOperationsResponse, - ListInstanceConfigsRequest, - ListInstanceConfigsResponse, - ListInstancesRequest, - ListInstancesResponse, - ReplicaInfo, - UpdateInstanceConfigMetadata, - UpdateInstanceConfigRequest, - UpdateInstanceMetadata, - UpdateInstanceRequest, -) - -__all__ = ( - 'OperationProgress', - 'CreateInstanceConfigMetadata', - 'CreateInstanceConfigRequest', - 'CreateInstanceMetadata', - 'CreateInstanceRequest', - 'DeleteInstanceConfigRequest', - 'DeleteInstanceRequest', - 'GetInstanceConfigRequest', - 'GetInstanceRequest', - 'Instance', - 'InstanceConfig', - 'ListInstanceConfigOperationsRequest', - 'ListInstanceConfigOperationsResponse', - 'ListInstanceConfigsRequest', - 'ListInstanceConfigsResponse', - 'ListInstancesRequest', - 'ListInstancesResponse', - 'ReplicaInfo', - 'UpdateInstanceConfigMetadata', - 'UpdateInstanceConfigRequest', - 'UpdateInstanceMetadata', - 'UpdateInstanceRequest', -) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/common.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/common.py deleted file mode 100644 index d354cfffea..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/common.py +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.protobuf import timestamp_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.spanner.admin.instance.v1', - manifest={ - 'OperationProgress', - }, -) - - -class OperationProgress(proto.Message): - r"""Encapsulates progress related information for a Cloud Spanner - long running instance operations. - - Attributes: - progress_percent (int): - Percent completion of the operation. - Values are between 0 and 100 inclusive. - start_time (google.protobuf.timestamp_pb2.Timestamp): - Time the request was received. - end_time (google.protobuf.timestamp_pb2.Timestamp): - If set, the time at which this operation - failed or was completed successfully. - """ - - progress_percent: int = proto.Field( - proto.INT32, - number=1, - ) - start_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=2, - message=timestamp_pb2.Timestamp, - ) - end_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py b/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py deleted file mode 100644 index 55e620e172..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py +++ /dev/null @@ -1,1128 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -from __future__ import annotations - -from typing import MutableMapping, MutableSequence - -import proto # type: ignore - -from google.cloud.spanner_admin_instance_v1.types import common -from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore - - -__protobuf__ = proto.module( - package='google.spanner.admin.instance.v1', - manifest={ - 'ReplicaInfo', - 'InstanceConfig', - 'Instance', - 'ListInstanceConfigsRequest', - 'ListInstanceConfigsResponse', - 'GetInstanceConfigRequest', - 'CreateInstanceConfigRequest', - 'UpdateInstanceConfigRequest', - 'DeleteInstanceConfigRequest', - 'ListInstanceConfigOperationsRequest', - 'ListInstanceConfigOperationsResponse', - 'GetInstanceRequest', - 'CreateInstanceRequest', - 'ListInstancesRequest', - 'ListInstancesResponse', - 'UpdateInstanceRequest', - 'DeleteInstanceRequest', - 'CreateInstanceMetadata', - 'UpdateInstanceMetadata', - 'CreateInstanceConfigMetadata', - 'UpdateInstanceConfigMetadata', - }, -) - - -class ReplicaInfo(proto.Message): - r""" - - Attributes: - location (str): - The location of the serving resources, e.g. - "us-central1". - type_ (google.cloud.spanner_admin_instance_v1.types.ReplicaInfo.ReplicaType): - The type of replica. - default_leader_location (bool): - If true, this location is designated as the default leader - location where leader replicas are placed. See the `region - types - documentation `__ - for more details. - """ - class ReplicaType(proto.Enum): - r"""Indicates the type of replica. See the `replica types - documentation `__ - for more details. - - Values: - TYPE_UNSPECIFIED (0): - Not specified. - READ_WRITE (1): - Read-write replicas support both reads and writes. These - replicas: - - - Maintain a full copy of your data. - - Serve reads. - - Can vote whether to commit a write. - - Participate in leadership election. - - Are eligible to become a leader. - READ_ONLY (2): - Read-only replicas only support reads (not writes). - Read-only replicas: - - - Maintain a full copy of your data. - - Serve reads. - - Do not participate in voting to commit writes. - - Are not eligible to become a leader. - WITNESS (3): - Witness replicas don't support reads but do participate in - voting to commit writes. Witness replicas: - - - Do not maintain a full copy of data. - - Do not serve reads. - - Vote whether to commit writes. - - Participate in leader election but are not eligible to - become leader. - """ - TYPE_UNSPECIFIED = 0 - READ_WRITE = 1 - READ_ONLY = 2 - WITNESS = 3 - - location: str = proto.Field( - proto.STRING, - number=1, - ) - type_: ReplicaType = proto.Field( - proto.ENUM, - number=2, - enum=ReplicaType, - ) - default_leader_location: bool = proto.Field( - proto.BOOL, - number=3, - ) - - -class InstanceConfig(proto.Message): - r"""A possible configuration for a Cloud Spanner instance. - Configurations define the geographic placement of nodes and - their replication. - - Attributes: - name (str): - A unique identifier for the instance configuration. Values - are of the form - ``projects//instanceConfigs/[a-z][-a-z0-9]*``. - display_name (str): - The name of this instance configuration as it - appears in UIs. - config_type (google.cloud.spanner_admin_instance_v1.types.InstanceConfig.Type): - Output only. Whether this instance config is - a Google or User Managed Configuration. - replicas (MutableSequence[google.cloud.spanner_admin_instance_v1.types.ReplicaInfo]): - The geographic placement of nodes in this - instance configuration and their replication - properties. - optional_replicas (MutableSequence[google.cloud.spanner_admin_instance_v1.types.ReplicaInfo]): - Output only. The available optional replicas - to choose from for user managed configurations. - Populated for Google managed configurations. - base_config (str): - Base configuration name, e.g. - projects//instanceConfigs/nam3, based on which - this configuration is created. Only set for user managed - configurations. ``base_config`` must refer to a - configuration of type GOOGLE_MANAGED in the same project as - this configuration. - labels (MutableMapping[str, str]): - Cloud Labels are a flexible and lightweight mechanism for - organizing cloud resources into groups that reflect a - customer's organizational needs and deployment strategies. - Cloud Labels can be used to filter collections of resources. - They can be used to control how resource metrics are - aggregated. And they can be used as arguments to policy - management rules (e.g. route, firewall, load balancing, - etc.). - - - Label keys must be between 1 and 63 characters long and - must conform to the following regular expression: - ``[a-z][a-z0-9_-]{0,62}``. - - Label values must be between 0 and 63 characters long and - must conform to the regular expression - ``[a-z0-9_-]{0,63}``. - - No more than 64 labels can be associated with a given - resource. - - See https://goo.gl/xmQnxf for more information on and - examples of labels. - - If you plan to use labels in your own code, please note that - additional characters may be allowed in the future. - Therefore, you are advised to use an internal label - representation, such as JSON, which doesn't rely upon - specific characters being disallowed. For example, - representing labels as the string: name + "*" + value would - prove problematic if we were to allow "*" in a future - release. - etag (str): - etag is used for optimistic concurrency - control as a way to help prevent simultaneous - updates of a instance config from overwriting - each other. It is strongly suggested that - systems make use of the etag in the - read-modify-write cycle to perform instance - config updates in order to avoid race - conditions: An etag is returned in the response - which contains instance configs, and systems are - expected to put that etag in the request to - update instance config to ensure that their - change will be applied to the same version of - the instance config. - If no etag is provided in the call to update - instance config, then the existing instance - config is overwritten blindly. - leader_options (MutableSequence[str]): - Allowed values of the "default_leader" schema option for - databases in instances that use this instance configuration. - reconciling (bool): - Output only. If true, the instance config is - being created or updated. If false, there are no - ongoing operations for the instance config. - state (google.cloud.spanner_admin_instance_v1.types.InstanceConfig.State): - Output only. The current instance config - state. - """ - class Type(proto.Enum): - r"""The type of this configuration. - - Values: - TYPE_UNSPECIFIED (0): - Unspecified. - GOOGLE_MANAGED (1): - Google managed configuration. - USER_MANAGED (2): - User managed configuration. - """ - TYPE_UNSPECIFIED = 0 - GOOGLE_MANAGED = 1 - USER_MANAGED = 2 - - class State(proto.Enum): - r"""Indicates the current state of the instance config. - - Values: - STATE_UNSPECIFIED (0): - Not specified. - CREATING (1): - The instance config is still being created. - READY (2): - The instance config is fully created and - ready to be used to create instances. - """ - STATE_UNSPECIFIED = 0 - CREATING = 1 - READY = 2 - - name: str = proto.Field( - proto.STRING, - number=1, - ) - display_name: str = proto.Field( - proto.STRING, - number=2, - ) - config_type: Type = proto.Field( - proto.ENUM, - number=5, - enum=Type, - ) - replicas: MutableSequence['ReplicaInfo'] = proto.RepeatedField( - proto.MESSAGE, - number=3, - message='ReplicaInfo', - ) - optional_replicas: MutableSequence['ReplicaInfo'] = proto.RepeatedField( - proto.MESSAGE, - number=6, - message='ReplicaInfo', - ) - base_config: str = proto.Field( - proto.STRING, - number=7, - ) - labels: MutableMapping[str, str] = proto.MapField( - proto.STRING, - proto.STRING, - number=8, - ) - etag: str = proto.Field( - proto.STRING, - number=9, - ) - leader_options: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=4, - ) - reconciling: bool = proto.Field( - proto.BOOL, - number=10, - ) - state: State = proto.Field( - proto.ENUM, - number=11, - enum=State, - ) - - -class Instance(proto.Message): - r"""An isolated set of Cloud Spanner resources on which databases - can be hosted. - - Attributes: - name (str): - Required. A unique identifier for the instance, which cannot - be changed after the instance is created. Values are of the - form - ``projects//instances/[a-z][-a-z0-9]*[a-z0-9]``. - The final segment of the name must be between 2 and 64 - characters in length. - config (str): - Required. The name of the instance's configuration. Values - are of the form - ``projects//instanceConfigs/``. See - also - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] - and - [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. - display_name (str): - Required. The descriptive name for this - instance as it appears in UIs. Must be unique - per project and between 4 and 30 characters in - length. - node_count (int): - The number of nodes allocated to this instance. At most one - of either node_count or processing_units should be present - in the message. This may be zero in API responses for - instances that are not yet in state ``READY``. - - See `the - documentation `__ - for more information about nodes and processing units. - processing_units (int): - The number of processing units allocated to this instance. - At most one of processing_units or node_count should be - present in the message. This may be zero in API responses - for instances that are not yet in state ``READY``. - - See `the - documentation `__ - for more information about nodes and processing units. - state (google.cloud.spanner_admin_instance_v1.types.Instance.State): - Output only. The current instance state. For - [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance], - the state must be either omitted or set to ``CREATING``. For - [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance], - the state must be either omitted or set to ``READY``. - labels (MutableMapping[str, str]): - Cloud Labels are a flexible and lightweight mechanism for - organizing cloud resources into groups that reflect a - customer's organizational needs and deployment strategies. - Cloud Labels can be used to filter collections of resources. - They can be used to control how resource metrics are - aggregated. And they can be used as arguments to policy - management rules (e.g. route, firewall, load balancing, - etc.). - - - Label keys must be between 1 and 63 characters long and - must conform to the following regular expression: - ``[a-z][a-z0-9_-]{0,62}``. - - Label values must be between 0 and 63 characters long and - must conform to the regular expression - ``[a-z0-9_-]{0,63}``. - - No more than 64 labels can be associated with a given - resource. - - See https://goo.gl/xmQnxf for more information on and - examples of labels. - - If you plan to use labels in your own code, please note that - additional characters may be allowed in the future. And so - you are advised to use an internal label representation, - such as JSON, which doesn't rely upon specific characters - being disallowed. For example, representing labels as the - string: name + "*" + value would prove problematic if we - were to allow "*" in a future release. - endpoint_uris (MutableSequence[str]): - Deprecated. This field is not populated. - create_time (google.protobuf.timestamp_pb2.Timestamp): - Output only. The time at which the instance - was created. - update_time (google.protobuf.timestamp_pb2.Timestamp): - Output only. The time at which the instance - was most recently updated. - """ - class State(proto.Enum): - r"""Indicates the current state of the instance. - - Values: - STATE_UNSPECIFIED (0): - Not specified. - CREATING (1): - The instance is still being created. - Resources may not be available yet, and - operations such as database creation may not - work. - READY (2): - The instance is fully created and ready to do - work such as creating databases. - """ - STATE_UNSPECIFIED = 0 - CREATING = 1 - READY = 2 - - name: str = proto.Field( - proto.STRING, - number=1, - ) - config: str = proto.Field( - proto.STRING, - number=2, - ) - display_name: str = proto.Field( - proto.STRING, - number=3, - ) - node_count: int = proto.Field( - proto.INT32, - number=5, - ) - processing_units: int = proto.Field( - proto.INT32, - number=9, - ) - state: State = proto.Field( - proto.ENUM, - number=6, - enum=State, - ) - labels: MutableMapping[str, str] = proto.MapField( - proto.STRING, - proto.STRING, - number=7, - ) - endpoint_uris: MutableSequence[str] = proto.RepeatedField( - proto.STRING, - number=8, - ) - create_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=11, - message=timestamp_pb2.Timestamp, - ) - update_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=12, - message=timestamp_pb2.Timestamp, - ) - - -class ListInstanceConfigsRequest(proto.Message): - r"""The request for - [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. - - Attributes: - parent (str): - Required. The name of the project for which a list of - supported instance configurations is requested. Values are - of the form ``projects/``. - page_size (int): - Number of instance configurations to be - returned in the response. If 0 or less, defaults - to the server's maximum allowed page size. - page_token (str): - If non-empty, ``page_token`` should contain a - [next_page_token][google.spanner.admin.instance.v1.ListInstanceConfigsResponse.next_page_token] - from a previous - [ListInstanceConfigsResponse][google.spanner.admin.instance.v1.ListInstanceConfigsResponse]. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - page_size: int = proto.Field( - proto.INT32, - number=2, - ) - page_token: str = proto.Field( - proto.STRING, - number=3, - ) - - -class ListInstanceConfigsResponse(proto.Message): - r"""The response for - [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs]. - - Attributes: - instance_configs (MutableSequence[google.cloud.spanner_admin_instance_v1.types.InstanceConfig]): - The list of requested instance - configurations. - next_page_token (str): - ``next_page_token`` can be sent in a subsequent - [ListInstanceConfigs][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs] - call to fetch more of the matching instance configurations. - """ - - @property - def raw_page(self): - return self - - instance_configs: MutableSequence['InstanceConfig'] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='InstanceConfig', - ) - next_page_token: str = proto.Field( - proto.STRING, - number=2, - ) - - -class GetInstanceConfigRequest(proto.Message): - r"""The request for - [GetInstanceConfigRequest][google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig]. - - Attributes: - name (str): - Required. The name of the requested instance configuration. - Values are of the form - ``projects//instanceConfigs/``. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - - -class CreateInstanceConfigRequest(proto.Message): - r"""The request for - [CreateInstanceConfigRequest][InstanceAdmin.CreateInstanceConfigRequest]. - - Attributes: - parent (str): - Required. The name of the project in which to create the - instance config. Values are of the form - ``projects/``. - instance_config_id (str): - Required. The ID of the instance config to create. Valid - identifiers are of the form ``custom-[-a-z0-9]*[a-z0-9]`` - and must be between 2 and 64 characters in length. The - ``custom-`` prefix is required to avoid name conflicts with - Google managed configurations. - instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): - Required. The InstanceConfig proto of the configuration to - create. instance_config.name must be - ``/instanceConfigs/``. - instance_config.base_config must be a Google managed - configuration name, e.g. /instanceConfigs/us-east1, - /instanceConfigs/nam3. - validate_only (bool): - An option to validate, but not actually - execute, a request, and provide the same - response. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - instance_config_id: str = proto.Field( - proto.STRING, - number=2, - ) - instance_config: 'InstanceConfig' = proto.Field( - proto.MESSAGE, - number=3, - message='InstanceConfig', - ) - validate_only: bool = proto.Field( - proto.BOOL, - number=4, - ) - - -class UpdateInstanceConfigRequest(proto.Message): - r"""The request for - [UpdateInstanceConfigRequest][InstanceAdmin.UpdateInstanceConfigRequest]. - - Attributes: - instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): - Required. The user instance config to update, which must - always include the instance config name. Otherwise, only - fields mentioned in - [update_mask][google.spanner.admin.instance.v1.UpdateInstanceConfigRequest.update_mask] - need be included. To prevent conflicts of concurrent - updates, - [etag][google.spanner.admin.instance.v1.InstanceConfig.reconciling] - can be used. - update_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. A mask specifying which fields in - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] - should be updated. The field mask must always be specified; - this prevents any future fields in - [InstanceConfig][google.spanner.admin.instance.v1.InstanceConfig] - from being erased accidentally by clients that do not know - about them. Only display_name and labels can be updated. - validate_only (bool): - An option to validate, but not actually - execute, a request, and provide the same - response. - """ - - instance_config: 'InstanceConfig' = proto.Field( - proto.MESSAGE, - number=1, - message='InstanceConfig', - ) - update_mask: field_mask_pb2.FieldMask = proto.Field( - proto.MESSAGE, - number=2, - message=field_mask_pb2.FieldMask, - ) - validate_only: bool = proto.Field( - proto.BOOL, - number=3, - ) - - -class DeleteInstanceConfigRequest(proto.Message): - r"""The request for - [DeleteInstanceConfigRequest][InstanceAdmin.DeleteInstanceConfigRequest]. - - Attributes: - name (str): - Required. The name of the instance configuration to be - deleted. Values are of the form - ``projects//instanceConfigs/`` - etag (str): - Used for optimistic concurrency control as a - way to help prevent simultaneous deletes of an - instance config from overwriting each other. If - not empty, the API - only deletes the instance config when the etag - provided matches the current status of the - requested instance config. Otherwise, deletes - the instance config without checking the current - status of the requested instance config. - validate_only (bool): - An option to validate, but not actually - execute, a request, and provide the same - response. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - etag: str = proto.Field( - proto.STRING, - number=2, - ) - validate_only: bool = proto.Field( - proto.BOOL, - number=3, - ) - - -class ListInstanceConfigOperationsRequest(proto.Message): - r"""The request for - [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. - - Attributes: - parent (str): - Required. The project of the instance config operations. - Values are of the form ``projects/``. - filter (str): - An expression that filters the list of returned operations. - - A filter expression consists of a field name, a comparison - operator, and a value for filtering. The value must be a - string, a number, or a boolean. The comparison operator must - be one of: ``<``, ``>``, ``<=``, ``>=``, ``!=``, ``=``, or - ``:``. Colon ``:`` is the contains operator. Filter rules - are not case sensitive. - - The following fields in the - [Operation][google.longrunning.Operation] are eligible for - filtering: - - - ``name`` - The name of the long-running operation - - ``done`` - False if the operation is in progress, else - true. - - ``metadata.@type`` - the type of metadata. For example, - the type string for - [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata] - is - ``type.googleapis.com/google.spanner.admin.instance.v1.CreateInstanceConfigMetadata``. - - ``metadata.`` - any field in metadata.value. - ``metadata.@type`` must be specified first, if filtering - on metadata fields. - - ``error`` - Error associated with the long-running - operation. - - ``response.@type`` - the type of response. - - ``response.`` - any field in response.value. - - You can combine multiple expressions by enclosing each - expression in parentheses. By default, expressions are - combined with AND logic. However, you can specify AND, OR, - and NOT logic explicitly. - - Here are a few examples: - - - ``done:true`` - The operation is complete. - - ``(metadata.@type=`` - ``type.googleapis.com/google.spanner.admin.instance.v1.CreateInstanceConfigMetadata) AND`` - ``(metadata.instance_config.name:custom-config) AND`` - ``(metadata.progress.start_time < \"2021-03-28T14:50:00Z\") AND`` - ``(error:*)`` - Return operations where: - - - The operation's metadata type is - [CreateInstanceConfigMetadata][google.spanner.admin.instance.v1.CreateInstanceConfigMetadata]. - - The instance config name contains "custom-config". - - The operation started before 2021-03-28T14:50:00Z. - - The operation resulted in an error. - page_size (int): - Number of operations to be returned in the - response. If 0 or less, defaults to the server's - maximum allowed page size. - page_token (str): - If non-empty, ``page_token`` should contain a - [next_page_token][google.spanner.admin.instance.v1.ListInstanceConfigOperationsResponse.next_page_token] - from a previous - [ListInstanceConfigOperationsResponse][google.spanner.admin.instance.v1.ListInstanceConfigOperationsResponse] - to the same ``parent`` and with the same ``filter``. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - filter: str = proto.Field( - proto.STRING, - number=2, - ) - page_size: int = proto.Field( - proto.INT32, - number=3, - ) - page_token: str = proto.Field( - proto.STRING, - number=4, - ) - - -class ListInstanceConfigOperationsResponse(proto.Message): - r"""The response for - [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations]. - - Attributes: - operations (MutableSequence[google.longrunning.operations_pb2.Operation]): - The list of matching instance config [long-running - operations][google.longrunning.Operation]. Each operation's - name will be prefixed by the instance config's name. The - operation's - [metadata][google.longrunning.Operation.metadata] field type - ``metadata.type_url`` describes the type of the metadata. - next_page_token (str): - ``next_page_token`` can be sent in a subsequent - [ListInstanceConfigOperations][google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations] - call to fetch more of the matching metadata. - """ - - @property - def raw_page(self): - return self - - operations: MutableSequence[operations_pb2.Operation] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message=operations_pb2.Operation, - ) - next_page_token: str = proto.Field( - proto.STRING, - number=2, - ) - - -class GetInstanceRequest(proto.Message): - r"""The request for - [GetInstance][google.spanner.admin.instance.v1.InstanceAdmin.GetInstance]. - - Attributes: - name (str): - Required. The name of the requested instance. Values are of - the form ``projects//instances/``. - field_mask (google.protobuf.field_mask_pb2.FieldMask): - If field_mask is present, specifies the subset of - [Instance][google.spanner.admin.instance.v1.Instance] fields - that should be returned. If absent, all - [Instance][google.spanner.admin.instance.v1.Instance] fields - are returned. - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - field_mask: field_mask_pb2.FieldMask = proto.Field( - proto.MESSAGE, - number=2, - message=field_mask_pb2.FieldMask, - ) - - -class CreateInstanceRequest(proto.Message): - r"""The request for - [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance]. - - Attributes: - parent (str): - Required. The name of the project in which to create the - instance. Values are of the form ``projects/``. - instance_id (str): - Required. The ID of the instance to create. Valid - identifiers are of the form ``[a-z][-a-z0-9]*[a-z0-9]`` and - must be between 2 and 64 characters in length. - instance (google.cloud.spanner_admin_instance_v1.types.Instance): - Required. The instance to create. The name may be omitted, - but if specified must be - ``/instances/``. - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - instance_id: str = proto.Field( - proto.STRING, - number=2, - ) - instance: 'Instance' = proto.Field( - proto.MESSAGE, - number=3, - message='Instance', - ) - - -class ListInstancesRequest(proto.Message): - r"""The request for - [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. - - Attributes: - parent (str): - Required. The name of the project for which a list of - instances is requested. Values are of the form - ``projects/``. - page_size (int): - Number of instances to be returned in the - response. If 0 or less, defaults to the server's - maximum allowed page size. - page_token (str): - If non-empty, ``page_token`` should contain a - [next_page_token][google.spanner.admin.instance.v1.ListInstancesResponse.next_page_token] - from a previous - [ListInstancesResponse][google.spanner.admin.instance.v1.ListInstancesResponse]. - filter (str): - An expression for filtering the results of the request. - Filter rules are case insensitive. The fields eligible for - filtering are: - - - ``name`` - - ``display_name`` - - ``labels.key`` where key is the name of a label - - Some examples of using filters are: - - - ``name:*`` --> The instance has a name. - - ``name:Howl`` --> The instance's name contains the string - "howl". - - ``name:HOWL`` --> Equivalent to above. - - ``NAME:howl`` --> Equivalent to above. - - ``labels.env:*`` --> The instance has the label "env". - - ``labels.env:dev`` --> The instance has the label "env" - and the value of the label contains the string "dev". - - ``name:howl labels.env:dev`` --> The instance's name - contains "howl" and it has the label "env" with its value - containing "dev". - """ - - parent: str = proto.Field( - proto.STRING, - number=1, - ) - page_size: int = proto.Field( - proto.INT32, - number=2, - ) - page_token: str = proto.Field( - proto.STRING, - number=3, - ) - filter: str = proto.Field( - proto.STRING, - number=4, - ) - - -class ListInstancesResponse(proto.Message): - r"""The response for - [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances]. - - Attributes: - instances (MutableSequence[google.cloud.spanner_admin_instance_v1.types.Instance]): - The list of requested instances. - next_page_token (str): - ``next_page_token`` can be sent in a subsequent - [ListInstances][google.spanner.admin.instance.v1.InstanceAdmin.ListInstances] - call to fetch more of the matching instances. - """ - - @property - def raw_page(self): - return self - - instances: MutableSequence['Instance'] = proto.RepeatedField( - proto.MESSAGE, - number=1, - message='Instance', - ) - next_page_token: str = proto.Field( - proto.STRING, - number=2, - ) - - -class UpdateInstanceRequest(proto.Message): - r"""The request for - [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance]. - - Attributes: - instance (google.cloud.spanner_admin_instance_v1.types.Instance): - Required. The instance to update, which must always include - the instance name. Otherwise, only fields mentioned in - [field_mask][google.spanner.admin.instance.v1.UpdateInstanceRequest.field_mask] - need be included. - field_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. A mask specifying which fields in - [Instance][google.spanner.admin.instance.v1.Instance] should - be updated. The field mask must always be specified; this - prevents any future fields in - [Instance][google.spanner.admin.instance.v1.Instance] from - being erased accidentally by clients that do not know about - them. - """ - - instance: 'Instance' = proto.Field( - proto.MESSAGE, - number=1, - message='Instance', - ) - field_mask: field_mask_pb2.FieldMask = proto.Field( - proto.MESSAGE, - number=2, - message=field_mask_pb2.FieldMask, - ) - - -class DeleteInstanceRequest(proto.Message): - r"""The request for - [DeleteInstance][google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance]. - - Attributes: - name (str): - Required. The name of the instance to be deleted. Values are - of the form ``projects//instances/`` - """ - - name: str = proto.Field( - proto.STRING, - number=1, - ) - - -class CreateInstanceMetadata(proto.Message): - r"""Metadata type for the operation returned by - [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance]. - - Attributes: - instance (google.cloud.spanner_admin_instance_v1.types.Instance): - The instance being created. - start_time (google.protobuf.timestamp_pb2.Timestamp): - The time at which the - [CreateInstance][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance] - request was received. - cancel_time (google.protobuf.timestamp_pb2.Timestamp): - The time at which this operation was - cancelled. If set, this operation is in the - process of undoing itself (which is guaranteed - to succeed) and cannot be cancelled again. - end_time (google.protobuf.timestamp_pb2.Timestamp): - The time at which this operation failed or - was completed successfully. - """ - - instance: 'Instance' = proto.Field( - proto.MESSAGE, - number=1, - message='Instance', - ) - start_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=2, - message=timestamp_pb2.Timestamp, - ) - cancel_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - end_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp_pb2.Timestamp, - ) - - -class UpdateInstanceMetadata(proto.Message): - r"""Metadata type for the operation returned by - [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance]. - - Attributes: - instance (google.cloud.spanner_admin_instance_v1.types.Instance): - The desired end state of the update. - start_time (google.protobuf.timestamp_pb2.Timestamp): - The time at which - [UpdateInstance][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance] - request was received. - cancel_time (google.protobuf.timestamp_pb2.Timestamp): - The time at which this operation was - cancelled. If set, this operation is in the - process of undoing itself (which is guaranteed - to succeed) and cannot be cancelled again. - end_time (google.protobuf.timestamp_pb2.Timestamp): - The time at which this operation failed or - was completed successfully. - """ - - instance: 'Instance' = proto.Field( - proto.MESSAGE, - number=1, - message='Instance', - ) - start_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=2, - message=timestamp_pb2.Timestamp, - ) - cancel_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - end_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=4, - message=timestamp_pb2.Timestamp, - ) - - -class CreateInstanceConfigMetadata(proto.Message): - r"""Metadata type for the operation returned by - [CreateInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig]. - - Attributes: - instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): - The target instance config end state. - progress (google.cloud.spanner_admin_instance_v1.types.OperationProgress): - The progress of the - [CreateInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig] - operation. - cancel_time (google.protobuf.timestamp_pb2.Timestamp): - The time at which this operation was - cancelled. - """ - - instance_config: 'InstanceConfig' = proto.Field( - proto.MESSAGE, - number=1, - message='InstanceConfig', - ) - progress: common.OperationProgress = proto.Field( - proto.MESSAGE, - number=2, - message=common.OperationProgress, - ) - cancel_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - - -class UpdateInstanceConfigMetadata(proto.Message): - r"""Metadata type for the operation returned by - [UpdateInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstanceConfig]. - - Attributes: - instance_config (google.cloud.spanner_admin_instance_v1.types.InstanceConfig): - The desired instance config after updating. - progress (google.cloud.spanner_admin_instance_v1.types.OperationProgress): - The progress of the - [UpdateInstanceConfig][google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstanceConfig] - operation. - cancel_time (google.protobuf.timestamp_pb2.Timestamp): - The time at which this operation was - cancelled. - """ - - instance_config: 'InstanceConfig' = proto.Field( - proto.MESSAGE, - number=1, - message='InstanceConfig', - ) - progress: common.OperationProgress = proto.Field( - proto.MESSAGE, - number=2, - message=common.OperationProgress, - ) - cancel_time: timestamp_pb2.Timestamp = proto.Field( - proto.MESSAGE, - number=3, - message=timestamp_pb2.Timestamp, - ) - - -__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/owl-bot-staging/spanner_admin_instance/v1/mypy.ini b/owl-bot-staging/spanner_admin_instance/v1/mypy.ini deleted file mode 100644 index 574c5aed39..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/mypy.ini +++ /dev/null @@ -1,3 +0,0 @@ -[mypy] -python_version = 3.7 -namespace_packages = True diff --git a/owl-bot-staging/spanner_admin_instance/v1/noxfile.py b/owl-bot-staging/spanner_admin_instance/v1/noxfile.py deleted file mode 100644 index 445d92b157..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/noxfile.py +++ /dev/null @@ -1,184 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -import pathlib -import shutil -import subprocess -import sys - - -import nox # type: ignore - -ALL_PYTHON = [ - "3.7", - "3.8", - "3.9", - "3.10", - "3.11", -] - -CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() - -LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt" -PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8") - -BLACK_VERSION = "black==22.3.0" -BLACK_PATHS = ["docs", "google", "tests", "samples", "noxfile.py", "setup.py"] -DEFAULT_PYTHON_VERSION = "3.11" - -nox.sessions = [ - "unit", - "cover", - "mypy", - "check_lower_bounds" - # exclude update_lower_bounds from default - "docs", - "blacken", - "lint", - "lint_setup_py", -] - -@nox.session(python=ALL_PYTHON) -def unit(session): - """Run the unit test suite.""" - - session.install('coverage', 'pytest', 'pytest-cov', 'pytest-asyncio', 'asyncmock; python_version < "3.8"') - session.install('-e', '.') - - session.run( - 'py.test', - '--quiet', - '--cov=google/cloud/spanner_admin_instance_v1/', - '--cov=tests/', - '--cov-config=.coveragerc', - '--cov-report=term', - '--cov-report=html', - os.path.join('tests', 'unit', ''.join(session.posargs)) - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def cover(session): - """Run the final coverage report. - This outputs the coverage report aggregating coverage from the unit - test runs (not system test runs), and then erases coverage data. - """ - session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=100") - - session.run("coverage", "erase") - - -@nox.session(python=ALL_PYTHON) -def mypy(session): - """Run the type checker.""" - session.install( - 'mypy', - 'types-requests', - 'types-protobuf' - ) - session.install('.') - session.run( - 'mypy', - '--explicit-package-bases', - 'google', - ) - - -@nox.session -def update_lower_bounds(session): - """Update lower bounds in constraints.txt to match setup.py""" - session.install('google-cloud-testutils') - session.install('.') - - session.run( - 'lower-bound-checker', - 'update', - '--package-name', - PACKAGE_NAME, - '--constraints-file', - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - - -@nox.session -def check_lower_bounds(session): - """Check lower bounds in setup.py are reflected in constraints file""" - session.install('google-cloud-testutils') - session.install('.') - - session.run( - 'lower-bound-checker', - 'check', - '--package-name', - PACKAGE_NAME, - '--constraints-file', - str(LOWER_BOUND_CONSTRAINTS_FILE), - ) - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def docs(session): - """Build the docs for this library.""" - - session.install("-e", ".") - session.install("sphinx==4.0.1", "alabaster", "recommonmark") - - shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) - session.run( - "sphinx-build", - "-W", # warnings as errors - "-T", # show full traceback on exception - "-N", # no colors - "-b", - "html", - "-d", - os.path.join("docs", "_build", "doctrees", ""), - os.path.join("docs", ""), - os.path.join("docs", "_build", "html", ""), - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def lint(session): - """Run linters. - - Returns a failure if the linters find linting errors or sufficiently - serious code quality issues. - """ - session.install("flake8", BLACK_VERSION) - session.run( - "black", - "--check", - *BLACK_PATHS, - ) - session.run("flake8", "google", "tests", "samples") - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def blacken(session): - """Run black. Format code to uniform standard.""" - session.install(BLACK_VERSION) - session.run( - "black", - *BLACK_PATHS, - ) - - -@nox.session(python=DEFAULT_PYTHON_VERSION) -def lint_setup_py(session): - """Verify that setup.py is valid (including RST check).""" - session.install("docutils", "pygments") - session.run("python", "setup.py", "check", "--restructuredtext", "--strict") diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.instance.v1.json b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.instance.v1.json deleted file mode 100644 index 9572d4d727..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/snippet_metadata_google.spanner.admin.instance.v1.json +++ /dev/null @@ -1,2313 +0,0 @@ -{ - "clientLibrary": { - "apis": [ - { - "id": "google.spanner.admin.instance.v1", - "version": "v1" - } - ], - "language": "PYTHON", - "name": "google-cloud-spanner-admin-instance", - "version": "0.1.0" - }, - "snippets": [ - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", - "shortName": "InstanceAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.create_instance_config", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "CreateInstanceConfig" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.CreateInstanceConfigRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "instance_config", - "type": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig" - }, - { - "name": "instance_config_id", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "create_instance_config" - }, - "description": "Sample for CreateInstanceConfig", - "file": "spanner_v1_generated_instance_admin_create_instance_config_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_async", - "segments": [ - { - "end": 56, - "start": 27, - "type": "FULL" - }, - { - "end": 56, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 53, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 57, - "start": 54, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_create_instance_config_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", - "shortName": "InstanceAdminClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.create_instance_config", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "CreateInstanceConfig" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.CreateInstanceConfigRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "instance_config", - "type": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig" - }, - { - "name": "instance_config_id", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation.Operation", - "shortName": "create_instance_config" - }, - "description": "Sample for CreateInstanceConfig", - "file": "spanner_v1_generated_instance_admin_create_instance_config_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_sync", - "segments": [ - { - "end": 56, - "start": 27, - "type": "FULL" - }, - { - "end": 56, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 53, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 57, - "start": 54, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_create_instance_config_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", - "shortName": "InstanceAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.create_instance", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "CreateInstance" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.CreateInstanceRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "instance_id", - "type": "str" - }, - { - "name": "instance", - "type": "google.cloud.spanner_admin_instance_v1.types.Instance" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "create_instance" - }, - "description": "Sample for CreateInstance", - "file": "spanner_v1_generated_instance_admin_create_instance_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_CreateInstance_async", - "segments": [ - { - "end": 62, - "start": 27, - "type": "FULL" - }, - { - "end": 62, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 52, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 59, - "start": 53, - "type": "REQUEST_EXECUTION" - }, - { - "end": 63, - "start": 60, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_create_instance_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", - "shortName": "InstanceAdminClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.create_instance", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "CreateInstance" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.CreateInstanceRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "instance_id", - "type": "str" - }, - { - "name": "instance", - "type": "google.cloud.spanner_admin_instance_v1.types.Instance" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation.Operation", - "shortName": "create_instance" - }, - "description": "Sample for CreateInstance", - "file": "spanner_v1_generated_instance_admin_create_instance_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_CreateInstance_sync", - "segments": [ - { - "end": 62, - "start": 27, - "type": "FULL" - }, - { - "end": 62, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 52, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 59, - "start": 53, - "type": "REQUEST_EXECUTION" - }, - { - "end": 63, - "start": 60, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_create_instance_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", - "shortName": "InstanceAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.delete_instance_config", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstanceConfig", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "DeleteInstanceConfig" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.DeleteInstanceConfigRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "shortName": "delete_instance_config" - }, - "description": "Sample for DeleteInstanceConfig", - "file": "spanner_v1_generated_instance_admin_delete_instance_config_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_async", - "segments": [ - { - "end": 49, - "start": 27, - "type": "FULL" - }, - { - "end": 49, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_delete_instance_config_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", - "shortName": "InstanceAdminClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.delete_instance_config", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstanceConfig", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "DeleteInstanceConfig" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.DeleteInstanceConfigRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "shortName": "delete_instance_config" - }, - "description": "Sample for DeleteInstanceConfig", - "file": "spanner_v1_generated_instance_admin_delete_instance_config_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_sync", - "segments": [ - { - "end": 49, - "start": 27, - "type": "FULL" - }, - { - "end": 49, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_delete_instance_config_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", - "shortName": "InstanceAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.delete_instance", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "DeleteInstance" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.DeleteInstanceRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "shortName": "delete_instance" - }, - "description": "Sample for DeleteInstance", - "file": "spanner_v1_generated_instance_admin_delete_instance_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_DeleteInstance_async", - "segments": [ - { - "end": 49, - "start": 27, - "type": "FULL" - }, - { - "end": 49, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_delete_instance_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", - "shortName": "InstanceAdminClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.delete_instance", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstance", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "DeleteInstance" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.DeleteInstanceRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "shortName": "delete_instance" - }, - "description": "Sample for DeleteInstance", - "file": "spanner_v1_generated_instance_admin_delete_instance_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_DeleteInstance_sync", - "segments": [ - { - "end": 49, - "start": 27, - "type": "FULL" - }, - { - "end": 49, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_delete_instance_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", - "shortName": "InstanceAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.get_iam_policy", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetIamPolicy", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "GetIamPolicy" - }, - "parameters": [ - { - "name": "request", - "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" - }, - { - "name": "resource", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.iam.v1.policy_pb2.Policy", - "shortName": "get_iam_policy" - }, - "description": "Sample for GetIamPolicy", - "file": "spanner_v1_generated_instance_admin_get_iam_policy_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_GetIamPolicy_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 41, - "start": 39, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 42, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_get_iam_policy_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", - "shortName": "InstanceAdminClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_iam_policy", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetIamPolicy", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "GetIamPolicy" - }, - "parameters": [ - { - "name": "request", - "type": "google.iam.v1.iam_policy_pb2.GetIamPolicyRequest" - }, - { - "name": "resource", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.iam.v1.policy_pb2.Policy", - "shortName": "get_iam_policy" - }, - "description": "Sample for GetIamPolicy", - "file": "spanner_v1_generated_instance_admin_get_iam_policy_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_GetIamPolicy_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 41, - "start": 39, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 42, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_get_iam_policy_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", - "shortName": "InstanceAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.get_instance_config", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "GetInstanceConfig" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig", - "shortName": "get_instance_config" - }, - "description": "Sample for GetInstanceConfig", - "file": "spanner_v1_generated_instance_admin_get_instance_config_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstanceConfig_async", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_get_instance_config_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", - "shortName": "InstanceAdminClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_instance_config", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "GetInstanceConfig" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceConfigRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig", - "shortName": "get_instance_config" - }, - "description": "Sample for GetInstanceConfig", - "file": "spanner_v1_generated_instance_admin_get_instance_config_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstanceConfig_sync", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_get_instance_config_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", - "shortName": "InstanceAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.get_instance", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstance", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "GetInstance" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_instance_v1.types.Instance", - "shortName": "get_instance" - }, - "description": "Sample for GetInstance", - "file": "spanner_v1_generated_instance_admin_get_instance_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstance_async", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_get_instance_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", - "shortName": "InstanceAdminClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.get_instance", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.GetInstance", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "GetInstance" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.GetInstanceRequest" - }, - { - "name": "name", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_instance_v1.types.Instance", - "shortName": "get_instance" - }, - "description": "Sample for GetInstance", - "file": "spanner_v1_generated_instance_admin_get_instance_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_GetInstance_sync", - "segments": [ - { - "end": 51, - "start": 27, - "type": "FULL" - }, - { - "end": 51, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 52, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_get_instance_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", - "shortName": "InstanceAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.list_instance_config_operations", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "ListInstanceConfigOperations" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigOperationsAsyncPager", - "shortName": "list_instance_config_operations" - }, - "description": "Sample for ListInstanceConfigOperations", - "file": "spanner_v1_generated_instance_admin_list_instance_config_operations_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_list_instance_config_operations_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", - "shortName": "InstanceAdminClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.list_instance_config_operations", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigOperations", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "ListInstanceConfigOperations" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigOperationsRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigOperationsPager", - "shortName": "list_instance_config_operations" - }, - "description": "Sample for ListInstanceConfigOperations", - "file": "spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", - "shortName": "InstanceAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.list_instance_configs", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "ListInstanceConfigs" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigsAsyncPager", - "shortName": "list_instance_configs" - }, - "description": "Sample for ListInstanceConfigs", - "file": "spanner_v1_generated_instance_admin_list_instance_configs_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_list_instance_configs_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", - "shortName": "InstanceAdminClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.list_instance_configs", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "ListInstanceConfigs" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.ListInstanceConfigsRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstanceConfigsPager", - "shortName": "list_instance_configs" - }, - "description": "Sample for ListInstanceConfigs", - "file": "spanner_v1_generated_instance_admin_list_instance_configs_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_list_instance_configs_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", - "shortName": "InstanceAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.list_instances", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstances", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "ListInstances" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancesAsyncPager", - "shortName": "list_instances" - }, - "description": "Sample for ListInstances", - "file": "spanner_v1_generated_instance_admin_list_instances_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstances_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_list_instances_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", - "shortName": "InstanceAdminClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.list_instances", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.ListInstances", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "ListInstances" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.ListInstancesRequest" - }, - { - "name": "parent", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.cloud.spanner_admin_instance_v1.services.instance_admin.pagers.ListInstancesPager", - "shortName": "list_instances" - }, - "description": "Sample for ListInstances", - "file": "spanner_v1_generated_instance_admin_list_instances_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_ListInstances_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 45, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 48, - "start": 46, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 49, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_list_instances_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", - "shortName": "InstanceAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.set_iam_policy", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.SetIamPolicy", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "SetIamPolicy" - }, - "parameters": [ - { - "name": "request", - "type": "google.iam.v1.iam_policy_pb2.SetIamPolicyRequest" - }, - { - "name": "resource", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.iam.v1.policy_pb2.Policy", - "shortName": "set_iam_policy" - }, - "description": "Sample for SetIamPolicy", - "file": "spanner_v1_generated_instance_admin_set_iam_policy_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_SetIamPolicy_async", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 41, - "start": 39, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 42, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_set_iam_policy_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", - "shortName": "InstanceAdminClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.set_iam_policy", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.SetIamPolicy", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "SetIamPolicy" - }, - "parameters": [ - { - "name": "request", - "type": "google.iam.v1.iam_policy_pb2.SetIamPolicyRequest" - }, - { - "name": "resource", - "type": "str" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.iam.v1.policy_pb2.Policy", - "shortName": "set_iam_policy" - }, - "description": "Sample for SetIamPolicy", - "file": "spanner_v1_generated_instance_admin_set_iam_policy_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_SetIamPolicy_sync", - "segments": [ - { - "end": 52, - "start": 27, - "type": "FULL" - }, - { - "end": 52, - "start": 27, - "type": "SHORT" - }, - { - "end": 41, - "start": 39, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 46, - "start": 42, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 49, - "start": 47, - "type": "REQUEST_EXECUTION" - }, - { - "end": 53, - "start": 50, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_set_iam_policy_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", - "shortName": "InstanceAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.test_iam_permissions", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.TestIamPermissions", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "TestIamPermissions" - }, - "parameters": [ - { - "name": "request", - "type": "google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest" - }, - { - "name": "resource", - "type": "str" - }, - { - "name": "permissions", - "type": "MutableSequence[str]" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", - "shortName": "test_iam_permissions" - }, - "description": "Sample for TestIamPermissions", - "file": "spanner_v1_generated_instance_admin_test_iam_permissions_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_TestIamPermissions_async", - "segments": [ - { - "end": 53, - "start": 27, - "type": "FULL" - }, - { - "end": 53, - "start": 27, - "type": "SHORT" - }, - { - "end": 41, - "start": 39, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 47, - "start": 42, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 50, - "start": 48, - "type": "REQUEST_EXECUTION" - }, - { - "end": 54, - "start": 51, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_test_iam_permissions_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", - "shortName": "InstanceAdminClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.test_iam_permissions", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.TestIamPermissions", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "TestIamPermissions" - }, - "parameters": [ - { - "name": "request", - "type": "google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest" - }, - { - "name": "resource", - "type": "str" - }, - { - "name": "permissions", - "type": "MutableSequence[str]" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse", - "shortName": "test_iam_permissions" - }, - "description": "Sample for TestIamPermissions", - "file": "spanner_v1_generated_instance_admin_test_iam_permissions_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_TestIamPermissions_sync", - "segments": [ - { - "end": 53, - "start": 27, - "type": "FULL" - }, - { - "end": 53, - "start": 27, - "type": "SHORT" - }, - { - "end": 41, - "start": 39, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 47, - "start": 42, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 50, - "start": 48, - "type": "REQUEST_EXECUTION" - }, - { - "end": 54, - "start": 51, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_test_iam_permissions_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", - "shortName": "InstanceAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.update_instance_config", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstanceConfig", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "UpdateInstanceConfig" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.UpdateInstanceConfigRequest" - }, - { - "name": "instance_config", - "type": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig" - }, - { - "name": "update_mask", - "type": "google.protobuf.field_mask_pb2.FieldMask" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "update_instance_config" - }, - "description": "Sample for UpdateInstanceConfig", - "file": "spanner_v1_generated_instance_admin_update_instance_config_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_async", - "segments": [ - { - "end": 54, - "start": 27, - "type": "FULL" - }, - { - "end": 54, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 44, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 51, - "start": 45, - "type": "REQUEST_EXECUTION" - }, - { - "end": 55, - "start": 52, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_update_instance_config_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", - "shortName": "InstanceAdminClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.update_instance_config", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstanceConfig", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "UpdateInstanceConfig" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.UpdateInstanceConfigRequest" - }, - { - "name": "instance_config", - "type": "google.cloud.spanner_admin_instance_v1.types.InstanceConfig" - }, - { - "name": "update_mask", - "type": "google.protobuf.field_mask_pb2.FieldMask" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation.Operation", - "shortName": "update_instance_config" - }, - "description": "Sample for UpdateInstanceConfig", - "file": "spanner_v1_generated_instance_admin_update_instance_config_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_sync", - "segments": [ - { - "end": 54, - "start": 27, - "type": "FULL" - }, - { - "end": 54, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 44, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 51, - "start": 45, - "type": "REQUEST_EXECUTION" - }, - { - "end": 55, - "start": 52, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_update_instance_config_sync.py" - }, - { - "canonical": true, - "clientMethod": { - "async": true, - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient", - "shortName": "InstanceAdminAsyncClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminAsyncClient.update_instance", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "UpdateInstance" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.UpdateInstanceRequest" - }, - { - "name": "instance", - "type": "google.cloud.spanner_admin_instance_v1.types.Instance" - }, - { - "name": "field_mask", - "type": "google.protobuf.field_mask_pb2.FieldMask" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation_async.AsyncOperation", - "shortName": "update_instance" - }, - "description": "Sample for UpdateInstance", - "file": "spanner_v1_generated_instance_admin_update_instance_async.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_UpdateInstance_async", - "segments": [ - { - "end": 60, - "start": 27, - "type": "FULL" - }, - { - "end": 60, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 50, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 57, - "start": 51, - "type": "REQUEST_EXECUTION" - }, - { - "end": 61, - "start": 58, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_update_instance_async.py" - }, - { - "canonical": true, - "clientMethod": { - "client": { - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient", - "shortName": "InstanceAdminClient" - }, - "fullName": "google.cloud.spanner_admin_instance_v1.InstanceAdminClient.update_instance", - "method": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstance", - "service": { - "fullName": "google.spanner.admin.instance.v1.InstanceAdmin", - "shortName": "InstanceAdmin" - }, - "shortName": "UpdateInstance" - }, - "parameters": [ - { - "name": "request", - "type": "google.cloud.spanner_admin_instance_v1.types.UpdateInstanceRequest" - }, - { - "name": "instance", - "type": "google.cloud.spanner_admin_instance_v1.types.Instance" - }, - { - "name": "field_mask", - "type": "google.protobuf.field_mask_pb2.FieldMask" - }, - { - "name": "retry", - "type": "google.api_core.retry.Retry" - }, - { - "name": "timeout", - "type": "float" - }, - { - "name": "metadata", - "type": "Sequence[Tuple[str, str]" - } - ], - "resultType": "google.api_core.operation.Operation", - "shortName": "update_instance" - }, - "description": "Sample for UpdateInstance", - "file": "spanner_v1_generated_instance_admin_update_instance_sync.py", - "language": "PYTHON", - "origin": "API_DEFINITION", - "regionTag": "spanner_v1_generated_InstanceAdmin_UpdateInstance_sync", - "segments": [ - { - "end": 60, - "start": 27, - "type": "FULL" - }, - { - "end": 60, - "start": 27, - "type": "SHORT" - }, - { - "end": 40, - "start": 38, - "type": "CLIENT_INITIALIZATION" - }, - { - "end": 50, - "start": 41, - "type": "REQUEST_INITIALIZATION" - }, - { - "end": 57, - "start": 51, - "type": "REQUEST_EXECUTION" - }, - { - "end": 61, - "start": 58, - "type": "RESPONSE_HANDLING" - } - ], - "title": "spanner_v1_generated_instance_admin_update_instance_sync.py" - } - ] -} diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_async.py deleted file mode 100644 index baf18d92d1..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_async.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for CreateInstance -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_CreateInstance_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -async def sample_create_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - instance = spanner_admin_instance_v1.Instance() - instance.name = "name_value" - instance.config = "config_value" - instance.display_name = "display_name_value" - - request = spanner_admin_instance_v1.CreateInstanceRequest( - parent="parent_value", - instance_id="instance_id_value", - instance=instance, - ) - - # Make the request - operation = client.create_instance(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_CreateInstance_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_async.py deleted file mode 100644 index 804a0b94f7..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_async.py +++ /dev/null @@ -1,57 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for CreateInstanceConfig -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -async def sample_create_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.CreateInstanceConfigRequest( - parent="parent_value", - instance_config_id="instance_config_id_value", - ) - - # Make the request - operation = client.create_instance_config(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_sync.py deleted file mode 100644 index fcd79a04ff..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_config_sync.py +++ /dev/null @@ -1,57 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for CreateInstanceConfig -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -def sample_create_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.CreateInstanceConfigRequest( - parent="parent_value", - instance_config_id="instance_config_id_value", - ) - - # Make the request - operation = client.create_instance_config(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_CreateInstanceConfig_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_sync.py deleted file mode 100644 index 053c083191..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_create_instance_sync.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for CreateInstance -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_CreateInstance_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -def sample_create_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - instance = spanner_admin_instance_v1.Instance() - instance.name = "name_value" - instance.config = "config_value" - instance.display_name = "display_name_value" - - request = spanner_admin_instance_v1.CreateInstanceRequest( - parent="parent_value", - instance_id="instance_id_value", - instance=instance, - ) - - # Make the request - operation = client.create_instance(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_CreateInstance_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_async.py deleted file mode 100644 index e455506517..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_async.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for DeleteInstance -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_DeleteInstance_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -async def sample_delete_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.DeleteInstanceRequest( - name="name_value", - ) - - # Make the request - await client.delete_instance(request=request) - - -# [END spanner_v1_generated_InstanceAdmin_DeleteInstance_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_async.py deleted file mode 100644 index 0234dd31be..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_async.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for DeleteInstanceConfig -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -async def sample_delete_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.DeleteInstanceConfigRequest( - name="name_value", - ) - - # Make the request - await client.delete_instance_config(request=request) - - -# [END spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_sync.py deleted file mode 100644 index 7e7ef31843..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_config_sync.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for DeleteInstanceConfig -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -def sample_delete_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.DeleteInstanceConfigRequest( - name="name_value", - ) - - # Make the request - client.delete_instance_config(request=request) - - -# [END spanner_v1_generated_InstanceAdmin_DeleteInstanceConfig_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_sync.py deleted file mode 100644 index 0b74e53652..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_delete_instance_sync.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for DeleteInstance -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_DeleteInstance_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -def sample_delete_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.DeleteInstanceRequest( - name="name_value", - ) - - # Make the request - client.delete_instance(request=request) - - -# [END spanner_v1_generated_InstanceAdmin_DeleteInstance_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_async.py deleted file mode 100644 index 9fd51bcd8d..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetIamPolicy -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_GetIamPolicy_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 -from google.iam.v1 import iam_policy_pb2 # type: ignore - - -async def sample_get_iam_policy(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = iam_policy_pb2.GetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = await client.get_iam_policy(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_GetIamPolicy_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_sync.py deleted file mode 100644 index cad72ee137..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_iam_policy_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetIamPolicy -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_GetIamPolicy_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 -from google.iam.v1 import iam_policy_pb2 # type: ignore - - -def sample_get_iam_policy(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = iam_policy_pb2.GetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = client.get_iam_policy(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_GetIamPolicy_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_async.py deleted file mode 100644 index f26919b4c5..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_async.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetInstance -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_GetInstance_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -async def sample_get_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.GetInstanceRequest( - name="name_value", - ) - - # Make the request - response = await client.get_instance(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_GetInstance_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_async.py deleted file mode 100644 index 069fa1a4f3..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_async.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetInstanceConfig -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_GetInstanceConfig_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -async def sample_get_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.GetInstanceConfigRequest( - name="name_value", - ) - - # Make the request - response = await client.get_instance_config(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_GetInstanceConfig_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_sync.py deleted file mode 100644 index 59c31e2931..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_config_sync.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetInstanceConfig -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_GetInstanceConfig_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -def sample_get_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.GetInstanceConfigRequest( - name="name_value", - ) - - # Make the request - response = client.get_instance_config(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_GetInstanceConfig_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_sync.py deleted file mode 100644 index 7cb95b3256..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_get_instance_sync.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for GetInstance -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_GetInstance_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -def sample_get_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.GetInstanceRequest( - name="name_value", - ) - - # Make the request - response = client.get_instance(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_GetInstance_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_async.py deleted file mode 100644 index ba5baa65d4..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListInstanceConfigOperations -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -async def sample_list_instance_config_operations(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.ListInstanceConfigOperationsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_instance_config_operations(request=request) - - # Handle the response - async for response in page_result: - print(response) - -# [END spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py deleted file mode 100644 index b7e113488b..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_config_operations_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListInstanceConfigOperations -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -def sample_list_instance_config_operations(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.ListInstanceConfigOperationsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_instance_config_operations(request=request) - - # Handle the response - for response in page_result: - print(response) - -# [END spanner_v1_generated_InstanceAdmin_ListInstanceConfigOperations_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_async.py deleted file mode 100644 index 531e22516f..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListInstanceConfigs -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -async def sample_list_instance_configs(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.ListInstanceConfigsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_instance_configs(request=request) - - # Handle the response - async for response in page_result: - print(response) - -# [END spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_sync.py deleted file mode 100644 index 297fa5bee2..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instance_configs_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListInstanceConfigs -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -def sample_list_instance_configs(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.ListInstanceConfigsRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_instance_configs(request=request) - - # Handle the response - for response in page_result: - print(response) - -# [END spanner_v1_generated_InstanceAdmin_ListInstanceConfigs_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_async.py deleted file mode 100644 index 9769963f45..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListInstances -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_ListInstances_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -async def sample_list_instances(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.ListInstancesRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_instances(request=request) - - # Handle the response - async for response in page_result: - print(response) - -# [END spanner_v1_generated_InstanceAdmin_ListInstances_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_sync.py deleted file mode 100644 index 6ce1c4089c..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_list_instances_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for ListInstances -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_ListInstances_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -def sample_list_instances(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.ListInstancesRequest( - parent="parent_value", - ) - - # Make the request - page_result = client.list_instances(request=request) - - # Handle the response - for response in page_result: - print(response) - -# [END spanner_v1_generated_InstanceAdmin_ListInstances_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_async.py deleted file mode 100644 index 6ffa4e1f51..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_async.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for SetIamPolicy -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_SetIamPolicy_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 -from google.iam.v1 import iam_policy_pb2 # type: ignore - - -async def sample_set_iam_policy(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = iam_policy_pb2.SetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = await client.set_iam_policy(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_SetIamPolicy_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_sync.py deleted file mode 100644 index 46646279e7..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_set_iam_policy_sync.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for SetIamPolicy -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_SetIamPolicy_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 -from google.iam.v1 import iam_policy_pb2 # type: ignore - - -def sample_set_iam_policy(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = iam_policy_pb2.SetIamPolicyRequest( - resource="resource_value", - ) - - # Make the request - response = client.set_iam_policy(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_SetIamPolicy_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_async.py deleted file mode 100644 index 7014b6ed4a..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_async.py +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for TestIamPermissions -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_TestIamPermissions_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 -from google.iam.v1 import iam_policy_pb2 # type: ignore - - -async def sample_test_iam_permissions(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = iam_policy_pb2.TestIamPermissionsRequest( - resource="resource_value", - permissions=['permissions_value1', 'permissions_value2'], - ) - - # Make the request - response = await client.test_iam_permissions(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_TestIamPermissions_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_sync.py deleted file mode 100644 index 92037b5780..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_test_iam_permissions_sync.py +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for TestIamPermissions -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_TestIamPermissions_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 -from google.iam.v1 import iam_policy_pb2 # type: ignore - - -def sample_test_iam_permissions(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = iam_policy_pb2.TestIamPermissionsRequest( - resource="resource_value", - permissions=['permissions_value1', 'permissions_value2'], - ) - - # Make the request - response = client.test_iam_permissions(request=request) - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_TestIamPermissions_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_async.py deleted file mode 100644 index 214b138ea4..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_async.py +++ /dev/null @@ -1,61 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for UpdateInstance -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_UpdateInstance_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -async def sample_update_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - instance = spanner_admin_instance_v1.Instance() - instance.name = "name_value" - instance.config = "config_value" - instance.display_name = "display_name_value" - - request = spanner_admin_instance_v1.UpdateInstanceRequest( - instance=instance, - ) - - # Make the request - operation = client.update_instance(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_UpdateInstance_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_async.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_async.py deleted file mode 100644 index 6f33a85a25..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_async.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for UpdateInstanceConfig -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_async] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -async def sample_update_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminAsyncClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.UpdateInstanceConfigRequest( - ) - - # Make the request - operation = client.update_instance_config(request=request) - - print("Waiting for operation to complete...") - - response = (await operation).result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_async] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_sync.py deleted file mode 100644 index bdcb9a8dbd..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_config_sync.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for UpdateInstanceConfig -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -def sample_update_instance_config(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - request = spanner_admin_instance_v1.UpdateInstanceConfigRequest( - ) - - # Make the request - operation = client.update_instance_config(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_UpdateInstanceConfig_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_sync.py b/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_sync.py deleted file mode 100644 index c614d8a6b0..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/samples/generated_samples/spanner_v1_generated_instance_admin_update_instance_sync.py +++ /dev/null @@ -1,61 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Generated code. DO NOT EDIT! -# -# Snippet for UpdateInstance -# NOTE: This snippet has been automatically generated for illustrative purposes only. -# It may require modifications to work in your environment. - -# To install the latest published package dependency, execute the following: -# python3 -m pip install google-cloud-spanner-admin-instance - - -# [START spanner_v1_generated_InstanceAdmin_UpdateInstance_sync] -# This snippet has been automatically generated and should be regarded as a -# code template only. -# It will require modifications to work: -# - It may require correct/in-range values for request initialization. -# - It may require specifying regional endpoints when creating the service -# client as shown in: -# https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.cloud import spanner_admin_instance_v1 - - -def sample_update_instance(): - # Create a client - client = spanner_admin_instance_v1.InstanceAdminClient() - - # Initialize request argument(s) - instance = spanner_admin_instance_v1.Instance() - instance.name = "name_value" - instance.config = "config_value" - instance.display_name = "display_name_value" - - request = spanner_admin_instance_v1.UpdateInstanceRequest( - instance=instance, - ) - - # Make the request - operation = client.update_instance(request=request) - - print("Waiting for operation to complete...") - - response = operation.result() - - # Handle the response - print(response) - -# [END spanner_v1_generated_InstanceAdmin_UpdateInstance_sync] diff --git a/owl-bot-staging/spanner_admin_instance/v1/scripts/fixup_spanner_admin_instance_v1_keywords.py b/owl-bot-staging/spanner_admin_instance/v1/scripts/fixup_spanner_admin_instance_v1_keywords.py deleted file mode 100644 index c5d08e6b51..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/scripts/fixup_spanner_admin_instance_v1_keywords.py +++ /dev/null @@ -1,189 +0,0 @@ -#! /usr/bin/env python3 -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import argparse -import os -import libcst as cst -import pathlib -import sys -from typing import (Any, Callable, Dict, List, Sequence, Tuple) - - -def partition( - predicate: Callable[[Any], bool], - iterator: Sequence[Any] -) -> Tuple[List[Any], List[Any]]: - """A stable, out-of-place partition.""" - results = ([], []) - - for i in iterator: - results[int(predicate(i))].append(i) - - # Returns trueList, falseList - return results[1], results[0] - - -class spanner_admin_instanceCallTransformer(cst.CSTTransformer): - CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') - METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - 'create_instance': ('parent', 'instance_id', 'instance', ), - 'create_instance_config': ('parent', 'instance_config_id', 'instance_config', 'validate_only', ), - 'delete_instance': ('name', ), - 'delete_instance_config': ('name', 'etag', 'validate_only', ), - 'get_iam_policy': ('resource', 'options', ), - 'get_instance': ('name', 'field_mask', ), - 'get_instance_config': ('name', ), - 'list_instance_config_operations': ('parent', 'filter', 'page_size', 'page_token', ), - 'list_instance_configs': ('parent', 'page_size', 'page_token', ), - 'list_instances': ('parent', 'page_size', 'page_token', 'filter', ), - 'set_iam_policy': ('resource', 'policy', 'update_mask', ), - 'test_iam_permissions': ('resource', 'permissions', ), - 'update_instance': ('instance', 'field_mask', ), - 'update_instance_config': ('instance_config', 'update_mask', 'validate_only', ), - } - - def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: - try: - key = original.func.attr.value - kword_params = self.METHOD_TO_PARAMS[key] - except (AttributeError, KeyError): - # Either not a method from the API or too convoluted to be sure. - return updated - - # If the existing code is valid, keyword args come after positional args. - # Therefore, all positional args must map to the first parameters. - args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) - if any(k.keyword.value == "request" for k in kwargs): - # We've already fixed this file, don't fix it again. - return updated - - kwargs, ctrl_kwargs = partition( - lambda a: a.keyword.value not in self.CTRL_PARAMS, - kwargs - ) - - args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] - ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) - for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) - - request_arg = cst.Arg( - value=cst.Dict([ - cst.DictElement( - cst.SimpleString("'{}'".format(name)), -cst.Element(value=arg.value) - ) - # Note: the args + kwargs looks silly, but keep in mind that - # the control parameters had to be stripped out, and that - # those could have been passed positionally or by keyword. - for name, arg in zip(kword_params, args + kwargs)]), - keyword=cst.Name("request") - ) - - return updated.with_changes( - args=[request_arg] + ctrl_kwargs - ) - - -def fix_files( - in_dir: pathlib.Path, - out_dir: pathlib.Path, - *, - transformer=spanner_admin_instanceCallTransformer(), -): - """Duplicate the input dir to the output dir, fixing file method calls. - - Preconditions: - * in_dir is a real directory - * out_dir is a real, empty directory - """ - pyfile_gen = ( - pathlib.Path(os.path.join(root, f)) - for root, _, files in os.walk(in_dir) - for f in files if os.path.splitext(f)[1] == ".py" - ) - - for fpath in pyfile_gen: - with open(fpath, 'r') as f: - src = f.read() - - # Parse the code and insert method call fixes. - tree = cst.parse_module(src) - updated = tree.visit(transformer) - - # Create the path and directory structure for the new file. - updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) - updated_path.parent.mkdir(parents=True, exist_ok=True) - - # Generate the updated source file at the corresponding path. - with open(updated_path, 'w') as f: - f.write(updated.code) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description="""Fix up source that uses the spanner_admin_instance client library. - -The existing sources are NOT overwritten but are copied to output_dir with changes made. - -Note: This tool operates at a best-effort level at converting positional - parameters in client method calls to keyword based parameters. - Cases where it WILL FAIL include - A) * or ** expansion in a method call. - B) Calls via function or method alias (includes free function calls) - C) Indirect or dispatched calls (e.g. the method is looked up dynamically) - - These all constitute false negatives. The tool will also detect false - positives when an API method shares a name with another method. -""") - parser.add_argument( - '-d', - '--input-directory', - required=True, - dest='input_dir', - help='the input directory to walk for python files to fix up', - ) - parser.add_argument( - '-o', - '--output-directory', - required=True, - dest='output_dir', - help='the directory to output files fixed via un-flattening', - ) - args = parser.parse_args() - input_dir = pathlib.Path(args.input_dir) - output_dir = pathlib.Path(args.output_dir) - if not input_dir.is_dir(): - print( - f"input directory '{input_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if not output_dir.is_dir(): - print( - f"output directory '{output_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if os.listdir(output_dir): - print( - f"output directory '{output_dir}' is not empty", - file=sys.stderr, - ) - sys.exit(-1) - - fix_files(input_dir, output_dir) diff --git a/owl-bot-staging/spanner_admin_instance/v1/setup.py b/owl-bot-staging/spanner_admin_instance/v1/setup.py deleted file mode 100644 index 4d627f7a23..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/setup.py +++ /dev/null @@ -1,91 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import io -import os - -import setuptools # type: ignore - -package_root = os.path.abspath(os.path.dirname(__file__)) - -name = 'google-cloud-spanner-admin-instance' - - -description = "Google Cloud Spanner Admin Instance API client library" - -version = {} -with open(os.path.join(package_root, 'google/cloud/spanner_admin_instance/gapic_version.py')) as fp: - exec(fp.read(), version) -version = version["__version__"] - -if version[0] == "0": - release_status = "Development Status :: 4 - Beta" -else: - release_status = "Development Status :: 5 - Production/Stable" - -dependencies = [ - "google-api-core[grpc] >= 1.34.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*", - "proto-plus >= 1.22.0, <2.0.0dev", - "proto-plus >= 1.22.2, <2.0.0dev; python_version>='3.11'", - "protobuf>=3.19.5,<5.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", - "grpc-google-iam-v1 >= 0.12.4, <1.0.0dev", -] -url = "https://github.com/googleapis/python-spanner-admin-instance" - -package_root = os.path.abspath(os.path.dirname(__file__)) - -readme_filename = os.path.join(package_root, "README.rst") -with io.open(readme_filename, encoding="utf-8") as readme_file: - readme = readme_file.read() - -packages = [ - package - for package in setuptools.PEP420PackageFinder.find() - if package.startswith("google") -] - -namespaces = ["google", "google.cloud"] - -setuptools.setup( - name=name, - version=version, - description=description, - long_description=readme, - author="Google LLC", - author_email="googleapis-packages@google.com", - license="Apache 2.0", - url=url, - classifiers=[ - release_status, - "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Operating System :: OS Independent", - "Topic :: Internet", - ], - platforms="Posix; MacOS X; Windows", - packages=packages, - python_requires=">=3.7", - namespace_packages=namespaces, - install_requires=dependencies, - include_package_data=True, - zip_safe=False, -) diff --git a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.10.txt b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.10.txt deleted file mode 100644 index ad3f0fa58e..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.10.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.11.txt b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.11.txt deleted file mode 100644 index ad3f0fa58e..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.11.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.12.txt b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.12.txt deleted file mode 100644 index ad3f0fa58e..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.12.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.7.txt b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.7.txt deleted file mode 100644 index 2beecf99e0..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.7.txt +++ /dev/null @@ -1,10 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List all library dependencies and extras in this file. -# Pin the version to the lower bound. -# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", -# Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.34.0 -proto-plus==1.22.0 -protobuf==3.19.5 -grpc-google-iam-v1==0.12.4 diff --git a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.8.txt b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.8.txt deleted file mode 100644 index ad3f0fa58e..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.8.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.9.txt b/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.9.txt deleted file mode 100644 index ad3f0fa58e..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/testing/constraints-3.9.txt +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# This constraints file is required for unit tests. -# List all library dependencies and extras in this file. -google-api-core -proto-plus -protobuf -grpc-google-iam-v1 diff --git a/owl-bot-staging/spanner_admin_instance/v1/tests/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/tests/__init__.py deleted file mode 100644 index 231bc12501..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/tests/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner_admin_instance/v1/tests/unit/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/tests/unit/__init__.py deleted file mode 100644 index 231bc12501..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/tests/unit/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/__init__.py deleted file mode 100644 index 231bc12501..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/__init__.py b/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/__init__.py deleted file mode 100644 index 231bc12501..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ - -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# diff --git a/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py b/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py deleted file mode 100644 index 24efc63392..0000000000 --- a/owl-bot-staging/spanner_admin_instance/v1/tests/unit/gapic/spanner_admin_instance_v1/test_instance_admin.py +++ /dev/null @@ -1,8775 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -import os -# try/except added for compatibility with python < 3.8 -try: - from unittest import mock - from unittest.mock import AsyncMock # pragma: NO COVER -except ImportError: # pragma: NO COVER - import mock - -import grpc -from grpc.experimental import aio -from collections.abc import Iterable -from google.protobuf import json_format -import json -import math -import pytest -from proto.marshal.rules.dates import DurationRule, TimestampRule -from proto.marshal.rules import wrappers -from requests import Response -from requests import Request, PreparedRequest -from requests.sessions import Session -from google.protobuf import json_format - -from google.api_core import client_options -from google.api_core import exceptions as core_exceptions -from google.api_core import future -from google.api_core import gapic_v1 -from google.api_core import grpc_helpers -from google.api_core import grpc_helpers_async -from google.api_core import operation -from google.api_core import operation_async # type: ignore -from google.api_core import operations_v1 -from google.api_core import path_template -from google.auth import credentials as ga_credentials -from google.auth.exceptions import MutualTLSChannelError -from google.cloud.spanner_admin_instance_v1.services.instance_admin import InstanceAdminAsyncClient -from google.cloud.spanner_admin_instance_v1.services.instance_admin import InstanceAdminClient -from google.cloud.spanner_admin_instance_v1.services.instance_admin import pagers -from google.cloud.spanner_admin_instance_v1.services.instance_admin import transports -from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin -from google.iam.v1 import iam_policy_pb2 # type: ignore -from google.iam.v1 import options_pb2 # type: ignore -from google.iam.v1 import policy_pb2 # type: ignore -from google.longrunning import operations_pb2 -from google.longrunning import operations_pb2 # type: ignore -from google.oauth2 import service_account -from google.protobuf import field_mask_pb2 # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.type import expr_pb2 # type: ignore -import google.auth - - -def client_cert_source_callback(): - return b"cert bytes", b"key bytes" - - -# If default endpoint is localhost, then default mtls endpoint will be the same. -# This method modifies the default endpoint so the client can produce a different -# mtls endpoint for endpoint testing purposes. -def modify_default_endpoint(client): - return "foo.googleapis.com" if ("localhost" in client.DEFAULT_ENDPOINT) else client.DEFAULT_ENDPOINT - - -def test__get_default_mtls_endpoint(): - api_endpoint = "example.googleapis.com" - api_mtls_endpoint = "example.mtls.googleapis.com" - sandbox_endpoint = "example.sandbox.googleapis.com" - sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" - non_googleapi = "api.example.com" - - assert InstanceAdminClient._get_default_mtls_endpoint(None) is None - assert InstanceAdminClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint - assert InstanceAdminClient._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint - assert InstanceAdminClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint - assert InstanceAdminClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint - assert InstanceAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi - - -@pytest.mark.parametrize("client_class,transport_name", [ - (InstanceAdminClient, "grpc"), - (InstanceAdminAsyncClient, "grpc_asyncio"), - (InstanceAdminClient, "rest"), -]) -def test_instance_admin_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: - factory.return_value = creds - info = {"valid": True} - client = client_class.from_service_account_info(info, transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == ( - 'spanner.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else - 'https://spanner.googleapis.com' - ) - - -@pytest.mark.parametrize("transport_class,transport_name", [ - (transports.InstanceAdminGrpcTransport, "grpc"), - (transports.InstanceAdminGrpcAsyncIOTransport, "grpc_asyncio"), - (transports.InstanceAdminRestTransport, "rest"), -]) -def test_instance_admin_client_service_account_always_use_jwt(transport_class, transport_name): - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - transport = transport_class(credentials=creds, always_use_jwt_access=True) - use_jwt.assert_called_once_with(True) - - with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt: - creds = service_account.Credentials(None, None, None) - transport = transport_class(credentials=creds, always_use_jwt_access=False) - use_jwt.assert_not_called() - - -@pytest.mark.parametrize("client_class,transport_name", [ - (InstanceAdminClient, "grpc"), - (InstanceAdminAsyncClient, "grpc_asyncio"), - (InstanceAdminClient, "rest"), -]) -def test_instance_admin_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() - with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: - factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) - assert client.transport._credentials == creds - assert isinstance(client, client_class) - - assert client.transport._host == ( - 'spanner.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else - 'https://spanner.googleapis.com' - ) - - -def test_instance_admin_client_get_transport_class(): - transport = InstanceAdminClient.get_transport_class() - available_transports = [ - transports.InstanceAdminGrpcTransport, - transports.InstanceAdminRestTransport, - ] - assert transport in available_transports - - transport = InstanceAdminClient.get_transport_class("grpc") - assert transport == transports.InstanceAdminGrpcTransport - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (InstanceAdminClient, transports.InstanceAdminGrpcTransport, "grpc"), - (InstanceAdminAsyncClient, transports.InstanceAdminGrpcAsyncIOTransport, "grpc_asyncio"), - (InstanceAdminClient, transports.InstanceAdminRestTransport, "rest"), -]) -@mock.patch.object(InstanceAdminClient, "DEFAULT_ENDPOINT", modify_default_endpoint(InstanceAdminClient)) -@mock.patch.object(InstanceAdminAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(InstanceAdminAsyncClient)) -def test_instance_admin_client_client_options(client_class, transport_class, transport_name): - # Check that if channel is provided we won't create a new one. - with mock.patch.object(InstanceAdminClient, 'get_transport_class') as gtc: - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials() - ) - client = client_class(transport=transport) - gtc.assert_not_called() - - # Check that if channel is provided via str we will create a new one. - with mock.patch.object(InstanceAdminClient, 'get_transport_class') as gtc: - client = client_class(transport=transport_name) - gtc.assert_called() - - # Check the case api_endpoint is provided. - options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name, client_options=options) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is - # "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_MTLS_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has - # unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): - with pytest.raises(MutualTLSChannelError): - client = client_class(transport=transport_name) - - # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}): - with pytest.raises(ValueError): - client = client_class(transport=transport_name) - - # Check the case quota_project_id is provided - options = client_options.ClientOptions(quota_project_id="octopus") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id="octopus", - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - # Check the case api_endpoint is provided - options = client_options.ClientOptions(api_audience="https://language.googleapis.com") - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience="https://language.googleapis.com" - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,use_client_cert_env", [ - (InstanceAdminClient, transports.InstanceAdminGrpcTransport, "grpc", "true"), - (InstanceAdminAsyncClient, transports.InstanceAdminGrpcAsyncIOTransport, "grpc_asyncio", "true"), - (InstanceAdminClient, transports.InstanceAdminGrpcTransport, "grpc", "false"), - (InstanceAdminAsyncClient, transports.InstanceAdminGrpcAsyncIOTransport, "grpc_asyncio", "false"), - (InstanceAdminClient, transports.InstanceAdminRestTransport, "rest", "true"), - (InstanceAdminClient, transports.InstanceAdminRestTransport, "rest", "false"), -]) -@mock.patch.object(InstanceAdminClient, "DEFAULT_ENDPOINT", modify_default_endpoint(InstanceAdminClient)) -@mock.patch.object(InstanceAdminAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(InstanceAdminAsyncClient)) -@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) -def test_instance_admin_client_mtls_env_auto(client_class, transport_class, transport_name, use_client_cert_env): - # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default - # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. - - # Check the case client_cert_source is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - - if use_client_cert_env == "false": - expected_client_cert_source = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_client_cert_source = client_cert_source_callback - expected_host = client.DEFAULT_MTLS_ENDPOINT - - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case ADC client cert is provided. Whether client cert is used depends on - # GOOGLE_API_USE_CLIENT_CERTIFICATE value. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=client_cert_source_callback): - if use_client_cert_env == "false": - expected_host = client.DEFAULT_ENDPOINT - expected_client_cert_source = None - else: - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_client_cert_source = client_cert_source_callback - - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - client_cert_source_for_mtls=expected_client_cert_source, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}): - with mock.patch.object(transport_class, '__init__') as patched: - with mock.patch("google.auth.transport.mtls.has_default_client_cert_source", return_value=False): - patched.return_value = None - client = client_class(transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - -@pytest.mark.parametrize("client_class", [ - InstanceAdminClient, InstanceAdminAsyncClient -]) -@mock.patch.object(InstanceAdminClient, "DEFAULT_ENDPOINT", modify_default_endpoint(InstanceAdminClient)) -@mock.patch.object(InstanceAdminAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(InstanceAdminAsyncClient)) -def test_instance_admin_client_get_mtls_endpoint_and_cert_source(client_class): - mock_client_cert_source = mock.Mock() - - # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - mock_api_endpoint = "foo" - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) - assert api_endpoint == mock_api_endpoint - assert cert_source == mock_client_cert_source - - # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): - mock_client_cert_source = mock.Mock() - mock_api_endpoint = "foo" - options = client_options.ClientOptions(client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint) - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(options) - assert api_endpoint == mock_api_endpoint - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_ENDPOINT - assert cert_source is None - - # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. - with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): - with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): - with mock.patch('google.auth.transport.mtls.default_client_cert_source', return_value=mock_client_cert_source): - api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() - assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT - assert cert_source == mock_client_cert_source - - -@pytest.mark.parametrize("client_class,transport_class,transport_name", [ - (InstanceAdminClient, transports.InstanceAdminGrpcTransport, "grpc"), - (InstanceAdminAsyncClient, transports.InstanceAdminGrpcAsyncIOTransport, "grpc_asyncio"), - (InstanceAdminClient, transports.InstanceAdminRestTransport, "rest"), -]) -def test_instance_admin_client_client_options_scopes(client_class, transport_class, transport_name): - # Check the case scopes are provided. - options = client_options.ClientOptions( - scopes=["1", "2"], - ) - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=["1", "2"], - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - -@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ - (InstanceAdminClient, transports.InstanceAdminGrpcTransport, "grpc", grpc_helpers), - (InstanceAdminAsyncClient, transports.InstanceAdminGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), - (InstanceAdminClient, transports.InstanceAdminRestTransport, "rest", None), -]) -def test_instance_admin_client_client_options_credentials_file(client_class, transport_class, transport_name, grpc_helpers): - # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) - - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file="credentials.json", - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - -def test_instance_admin_client_client_options_from_dict(): - with mock.patch('google.cloud.spanner_admin_instance_v1.services.instance_admin.transports.InstanceAdminGrpcTransport.__init__') as grpc_transport: - grpc_transport.return_value = None - client = InstanceAdminClient( - client_options={'api_endpoint': 'squid.clam.whelk'} - ) - grpc_transport.assert_called_once_with( - credentials=None, - credentials_file=None, - host="squid.clam.whelk", - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - -@pytest.mark.parametrize("client_class,transport_class,transport_name,grpc_helpers", [ - (InstanceAdminClient, transports.InstanceAdminGrpcTransport, "grpc", grpc_helpers), - (InstanceAdminAsyncClient, transports.InstanceAdminGrpcAsyncIOTransport, "grpc_asyncio", grpc_helpers_async), -]) -def test_instance_admin_client_create_channel_credentials_file(client_class, transport_class, transport_name, grpc_helpers): - # Check the case credentials file is provided. - options = client_options.ClientOptions( - credentials_file="credentials.json" - ) - - with mock.patch.object(transport_class, '__init__') as patched: - patched.return_value = None - client = client_class(client_options=options, transport=transport_name) - patched.assert_called_once_with( - credentials=None, - credentials_file="credentials.json", - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) - - # test that the credentials from file are saved and used as the credentials. - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel" - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() - load_creds.return_value = (file_creds, None) - adc.return_value = (creds, None) - client = client_class(client_options=options, transport=transport_name) - create_channel.assert_called_with( - "spanner.googleapis.com:443", - credentials=file_creds, - credentials_file=None, - quota_project_id=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.admin', -), - scopes=None, - default_host="spanner.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.ListInstanceConfigsRequest, - dict, -]) -def test_list_instance_configs(request_type, transport: str = 'grpc'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_configs), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.ListInstanceConfigsResponse( - next_page_token='next_page_token_value', - ) - response = client.list_instance_configs(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.ListInstanceConfigsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListInstanceConfigsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_instance_configs_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_configs), - '__call__') as call: - client.list_instance_configs() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.ListInstanceConfigsRequest() - -@pytest.mark.asyncio -async def test_list_instance_configs_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.ListInstanceConfigsRequest): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_configs), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstanceConfigsResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_instance_configs(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.ListInstanceConfigsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListInstanceConfigsAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_instance_configs_async_from_dict(): - await test_list_instance_configs_async(request_type=dict) - - -def test_list_instance_configs_field_headers(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.ListInstanceConfigsRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_configs), - '__call__') as call: - call.return_value = spanner_instance_admin.ListInstanceConfigsResponse() - client.list_instance_configs(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_list_instance_configs_field_headers_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.ListInstanceConfigsRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_configs), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstanceConfigsResponse()) - await client.list_instance_configs(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_list_instance_configs_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_configs), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.ListInstanceConfigsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_instance_configs( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - - -def test_list_instance_configs_flattened_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_instance_configs( - spanner_instance_admin.ListInstanceConfigsRequest(), - parent='parent_value', - ) - -@pytest.mark.asyncio -async def test_list_instance_configs_flattened_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_configs), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.ListInstanceConfigsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstanceConfigsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_instance_configs( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_list_instance_configs_flattened_error_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.list_instance_configs( - spanner_instance_admin.ListInstanceConfigsRequest(), - parent='parent_value', - ) - - -def test_list_instance_configs_pager(transport_name: str = "grpc"): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_configs), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_instance_configs(request={}) - - assert pager._metadata == metadata - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, spanner_instance_admin.InstanceConfig) - for i in results) -def test_list_instance_configs_pages(transport_name: str = "grpc"): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_configs), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - ], - ), - RuntimeError, - ) - pages = list(client.list_instance_configs(request={}).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.asyncio -async def test_list_instance_configs_async_pager(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_configs), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_instance_configs(request={},) - assert async_pager.next_page_token == 'abc' - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, spanner_instance_admin.InstanceConfig) - for i in responses) - - -@pytest.mark.asyncio -async def test_list_instance_configs_async_pages(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_configs), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_instance_configs(request={})).pages: # pragma: no branch - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.GetInstanceConfigRequest, - dict, -]) -def test_get_instance_config(request_type, transport: str = 'grpc'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.InstanceConfig( - name='name_value', - display_name='display_name_value', - config_type=spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED, - base_config='base_config_value', - etag='etag_value', - leader_options=['leader_options_value'], - reconciling=True, - state=spanner_instance_admin.InstanceConfig.State.CREATING, - ) - response = client.get_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.GetInstanceConfigRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner_instance_admin.InstanceConfig) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.config_type == spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED - assert response.base_config == 'base_config_value' - assert response.etag == 'etag_value' - assert response.leader_options == ['leader_options_value'] - assert response.reconciling is True - assert response.state == spanner_instance_admin.InstanceConfig.State.CREATING - - -def test_get_instance_config_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_instance_config), - '__call__') as call: - client.get_instance_config() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.GetInstanceConfigRequest() - -@pytest.mark.asyncio -async def test_get_instance_config_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.GetInstanceConfigRequest): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.InstanceConfig( - name='name_value', - display_name='display_name_value', - config_type=spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED, - base_config='base_config_value', - etag='etag_value', - leader_options=['leader_options_value'], - reconciling=True, - state=spanner_instance_admin.InstanceConfig.State.CREATING, - )) - response = await client.get_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.GetInstanceConfigRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner_instance_admin.InstanceConfig) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.config_type == spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED - assert response.base_config == 'base_config_value' - assert response.etag == 'etag_value' - assert response.leader_options == ['leader_options_value'] - assert response.reconciling is True - assert response.state == spanner_instance_admin.InstanceConfig.State.CREATING - - -@pytest.mark.asyncio -async def test_get_instance_config_async_from_dict(): - await test_get_instance_config_async(request_type=dict) - - -def test_get_instance_config_field_headers(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.GetInstanceConfigRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_instance_config), - '__call__') as call: - call.return_value = spanner_instance_admin.InstanceConfig() - client.get_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_get_instance_config_field_headers_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.GetInstanceConfigRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_instance_config), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.InstanceConfig()) - await client.get_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -def test_get_instance_config_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.InstanceConfig() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_instance_config( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - - -def test_get_instance_config_flattened_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_instance_config( - spanner_instance_admin.GetInstanceConfigRequest(), - name='name_value', - ) - -@pytest.mark.asyncio -async def test_get_instance_config_flattened_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.InstanceConfig() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.InstanceConfig()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_instance_config( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_get_instance_config_flattened_error_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.get_instance_config( - spanner_instance_admin.GetInstanceConfigRequest(), - name='name_value', - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.CreateInstanceConfigRequest, - dict, -]) -def test_create_instance_config(request_type, transport: str = 'grpc'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.create_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.CreateInstanceConfigRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_create_instance_config_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_instance_config), - '__call__') as call: - client.create_instance_config() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.CreateInstanceConfigRequest() - -@pytest.mark.asyncio -async def test_create_instance_config_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.CreateInstanceConfigRequest): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.create_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.CreateInstanceConfigRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_create_instance_config_async_from_dict(): - await test_create_instance_config_async(request_type=dict) - - -def test_create_instance_config_field_headers(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.CreateInstanceConfigRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_instance_config), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.create_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_create_instance_config_field_headers_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.CreateInstanceConfigRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_instance_config), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.create_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_create_instance_config_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_instance_config( - parent='parent_value', - instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), - instance_config_id='instance_config_id_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - arg = args[0].instance_config - mock_val = spanner_instance_admin.InstanceConfig(name='name_value') - assert arg == mock_val - arg = args[0].instance_config_id - mock_val = 'instance_config_id_value' - assert arg == mock_val - - -def test_create_instance_config_flattened_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_instance_config( - spanner_instance_admin.CreateInstanceConfigRequest(), - parent='parent_value', - instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), - instance_config_id='instance_config_id_value', - ) - -@pytest.mark.asyncio -async def test_create_instance_config_flattened_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_instance_config( - parent='parent_value', - instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), - instance_config_id='instance_config_id_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - arg = args[0].instance_config - mock_val = spanner_instance_admin.InstanceConfig(name='name_value') - assert arg == mock_val - arg = args[0].instance_config_id - mock_val = 'instance_config_id_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_create_instance_config_flattened_error_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.create_instance_config( - spanner_instance_admin.CreateInstanceConfigRequest(), - parent='parent_value', - instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), - instance_config_id='instance_config_id_value', - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.UpdateInstanceConfigRequest, - dict, -]) -def test_update_instance_config(request_type, transport: str = 'grpc'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.update_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.UpdateInstanceConfigRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_update_instance_config_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_instance_config), - '__call__') as call: - client.update_instance_config() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.UpdateInstanceConfigRequest() - -@pytest.mark.asyncio -async def test_update_instance_config_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.UpdateInstanceConfigRequest): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.update_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.UpdateInstanceConfigRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_update_instance_config_async_from_dict(): - await test_update_instance_config_async(request_type=dict) - - -def test_update_instance_config_field_headers(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.UpdateInstanceConfigRequest() - - request.instance_config.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_instance_config), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.update_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'instance_config.name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_update_instance_config_field_headers_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.UpdateInstanceConfigRequest() - - request.instance_config.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_instance_config), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.update_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'instance_config.name=name_value', - ) in kw['metadata'] - - -def test_update_instance_config_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.update_instance_config( - instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].instance_config - mock_val = spanner_instance_admin.InstanceConfig(name='name_value') - assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) - assert arg == mock_val - - -def test_update_instance_config_flattened_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_instance_config( - spanner_instance_admin.UpdateInstanceConfigRequest(), - instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - -@pytest.mark.asyncio -async def test_update_instance_config_flattened_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.update_instance_config( - instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].instance_config - mock_val = spanner_instance_admin.InstanceConfig(name='name_value') - assert arg == mock_val - arg = args[0].update_mask - mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) - assert arg == mock_val - -@pytest.mark.asyncio -async def test_update_instance_config_flattened_error_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.update_instance_config( - spanner_instance_admin.UpdateInstanceConfigRequest(), - instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.DeleteInstanceConfigRequest, - dict, -]) -def test_delete_instance_config(request_type, transport: str = 'grpc'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.DeleteInstanceConfigRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_instance_config_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_instance_config), - '__call__') as call: - client.delete_instance_config() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.DeleteInstanceConfigRequest() - -@pytest.mark.asyncio -async def test_delete_instance_config_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.DeleteInstanceConfigRequest): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.DeleteInstanceConfigRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_instance_config_async_from_dict(): - await test_delete_instance_config_async(request_type=dict) - - -def test_delete_instance_config_field_headers(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.DeleteInstanceConfigRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_instance_config), - '__call__') as call: - call.return_value = None - client.delete_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_delete_instance_config_field_headers_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.DeleteInstanceConfigRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_instance_config), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_instance_config(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -def test_delete_instance_config_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_instance_config( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - - -def test_delete_instance_config_flattened_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_instance_config( - spanner_instance_admin.DeleteInstanceConfigRequest(), - name='name_value', - ) - -@pytest.mark.asyncio -async def test_delete_instance_config_flattened_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_instance_config), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_instance_config( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_delete_instance_config_flattened_error_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.delete_instance_config( - spanner_instance_admin.DeleteInstanceConfigRequest(), - name='name_value', - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.ListInstanceConfigOperationsRequest, - dict, -]) -def test_list_instance_config_operations(request_type, transport: str = 'grpc'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_config_operations), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse( - next_page_token='next_page_token_value', - ) - response = client.list_instance_config_operations(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.ListInstanceConfigOperationsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListInstanceConfigOperationsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_instance_config_operations_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_config_operations), - '__call__') as call: - client.list_instance_config_operations() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.ListInstanceConfigOperationsRequest() - -@pytest.mark.asyncio -async def test_list_instance_config_operations_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.ListInstanceConfigOperationsRequest): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_config_operations), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstanceConfigOperationsResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_instance_config_operations(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.ListInstanceConfigOperationsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListInstanceConfigOperationsAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_instance_config_operations_async_from_dict(): - await test_list_instance_config_operations_async(request_type=dict) - - -def test_list_instance_config_operations_field_headers(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.ListInstanceConfigOperationsRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_config_operations), - '__call__') as call: - call.return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse() - client.list_instance_config_operations(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_list_instance_config_operations_field_headers_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.ListInstanceConfigOperationsRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_config_operations), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstanceConfigOperationsResponse()) - await client.list_instance_config_operations(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_list_instance_config_operations_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_config_operations), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_instance_config_operations( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - - -def test_list_instance_config_operations_flattened_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_instance_config_operations( - spanner_instance_admin.ListInstanceConfigOperationsRequest(), - parent='parent_value', - ) - -@pytest.mark.asyncio -async def test_list_instance_config_operations_flattened_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_config_operations), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstanceConfigOperationsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_instance_config_operations( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_list_instance_config_operations_flattened_error_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.list_instance_config_operations( - spanner_instance_admin.ListInstanceConfigOperationsRequest(), - parent='parent_value', - ) - - -def test_list_instance_config_operations_pager(transport_name: str = "grpc"): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_config_operations), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_instance_config_operations(request={}) - - assert pager._metadata == metadata - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, operations_pb2.Operation) - for i in results) -def test_list_instance_config_operations_pages(transport_name: str = "grpc"): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_config_operations), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - RuntimeError, - ) - pages = list(client.list_instance_config_operations(request={}).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.asyncio -async def test_list_instance_config_operations_async_pager(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_config_operations), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_instance_config_operations(request={},) - assert async_pager.next_page_token == 'abc' - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, operations_pb2.Operation) - for i in responses) - - -@pytest.mark.asyncio -async def test_list_instance_config_operations_async_pages(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instance_config_operations), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_instance_config_operations(request={})).pages: # pragma: no branch - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.ListInstancesRequest, - dict, -]) -def test_list_instances(request_type, transport: str = 'grpc'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instances), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.ListInstancesResponse( - next_page_token='next_page_token_value', - ) - response = client.list_instances(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.ListInstancesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListInstancesPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_instances_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instances), - '__call__') as call: - client.list_instances() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.ListInstancesRequest() - -@pytest.mark.asyncio -async def test_list_instances_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.ListInstancesRequest): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instances), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstancesResponse( - next_page_token='next_page_token_value', - )) - response = await client.list_instances(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.ListInstancesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListInstancesAsyncPager) - assert response.next_page_token == 'next_page_token_value' - - -@pytest.mark.asyncio -async def test_list_instances_async_from_dict(): - await test_list_instances_async(request_type=dict) - - -def test_list_instances_field_headers(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.ListInstancesRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instances), - '__call__') as call: - call.return_value = spanner_instance_admin.ListInstancesResponse() - client.list_instances(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_list_instances_field_headers_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.ListInstancesRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instances), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstancesResponse()) - await client.list_instances(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_list_instances_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instances), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.ListInstancesResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.list_instances( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - - -def test_list_instances_flattened_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_instances( - spanner_instance_admin.ListInstancesRequest(), - parent='parent_value', - ) - -@pytest.mark.asyncio -async def test_list_instances_flattened_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instances), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.ListInstancesResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.ListInstancesResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.list_instances( - parent='parent_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_list_instances_flattened_error_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.list_instances( - spanner_instance_admin.ListInstancesRequest(), - parent='parent_value', - ) - - -def test_list_instances_pager(transport_name: str = "grpc"): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instances), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata(( - ('parent', ''), - )), - ) - pager = client.list_instances(request={}) - - assert pager._metadata == metadata - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, spanner_instance_admin.Instance) - for i in results) -def test_list_instances_pages(transport_name: str = "grpc"): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials, - transport=transport_name, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instances), - '__call__') as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - ], - ), - RuntimeError, - ) - pages = list(client.list_instances(request={}).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.asyncio -async def test_list_instances_async_pager(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instances), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_instances(request={},) - assert async_pager.next_page_token == 'abc' - responses = [] - async for response in async_pager: # pragma: no branch - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, spanner_instance_admin.Instance) - for i in responses) - - -@pytest.mark.asyncio -async def test_list_instances_async_pages(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_instances), - '__call__', new_callable=mock.AsyncMock) as call: - # Set the response to a series of pages. - call.side_effect = ( - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_instances(request={})).pages: # pragma: no branch - pages.append(page_) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.GetInstanceRequest, - dict, -]) -def test_get_instance(request_type, transport: str = 'grpc'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.Instance( - name='name_value', - config='config_value', - display_name='display_name_value', - node_count=1070, - processing_units=1743, - state=spanner_instance_admin.Instance.State.CREATING, - endpoint_uris=['endpoint_uris_value'], - ) - response = client.get_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.GetInstanceRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner_instance_admin.Instance) - assert response.name == 'name_value' - assert response.config == 'config_value' - assert response.display_name == 'display_name_value' - assert response.node_count == 1070 - assert response.processing_units == 1743 - assert response.state == spanner_instance_admin.Instance.State.CREATING - assert response.endpoint_uris == ['endpoint_uris_value'] - - -def test_get_instance_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_instance), - '__call__') as call: - client.get_instance() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.GetInstanceRequest() - -@pytest.mark.asyncio -async def test_get_instance_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.GetInstanceRequest): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.Instance( - name='name_value', - config='config_value', - display_name='display_name_value', - node_count=1070, - processing_units=1743, - state=spanner_instance_admin.Instance.State.CREATING, - endpoint_uris=['endpoint_uris_value'], - )) - response = await client.get_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.GetInstanceRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner_instance_admin.Instance) - assert response.name == 'name_value' - assert response.config == 'config_value' - assert response.display_name == 'display_name_value' - assert response.node_count == 1070 - assert response.processing_units == 1743 - assert response.state == spanner_instance_admin.Instance.State.CREATING - assert response.endpoint_uris == ['endpoint_uris_value'] - - -@pytest.mark.asyncio -async def test_get_instance_async_from_dict(): - await test_get_instance_async(request_type=dict) - - -def test_get_instance_field_headers(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.GetInstanceRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_instance), - '__call__') as call: - call.return_value = spanner_instance_admin.Instance() - client.get_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_get_instance_field_headers_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.GetInstanceRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_instance), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.Instance()) - await client.get_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -def test_get_instance_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.Instance() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_instance( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - - -def test_get_instance_flattened_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_instance( - spanner_instance_admin.GetInstanceRequest(), - name='name_value', - ) - -@pytest.mark.asyncio -async def test_get_instance_flattened_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = spanner_instance_admin.Instance() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(spanner_instance_admin.Instance()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_instance( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_get_instance_flattened_error_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.get_instance( - spanner_instance_admin.GetInstanceRequest(), - name='name_value', - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.CreateInstanceRequest, - dict, -]) -def test_create_instance(request_type, transport: str = 'grpc'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.create_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.CreateInstanceRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_create_instance_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_instance), - '__call__') as call: - client.create_instance() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.CreateInstanceRequest() - -@pytest.mark.asyncio -async def test_create_instance_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.CreateInstanceRequest): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.create_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.CreateInstanceRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_create_instance_async_from_dict(): - await test_create_instance_async(request_type=dict) - - -def test_create_instance_field_headers(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.CreateInstanceRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_instance), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.create_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_create_instance_field_headers_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.CreateInstanceRequest() - - request.parent = 'parent_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_instance), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.create_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'parent=parent_value', - ) in kw['metadata'] - - -def test_create_instance_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.create_instance( - parent='parent_value', - instance_id='instance_id_value', - instance=spanner_instance_admin.Instance(name='name_value'), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - arg = args[0].instance_id - mock_val = 'instance_id_value' - assert arg == mock_val - arg = args[0].instance - mock_val = spanner_instance_admin.Instance(name='name_value') - assert arg == mock_val - - -def test_create_instance_flattened_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_instance( - spanner_instance_admin.CreateInstanceRequest(), - parent='parent_value', - instance_id='instance_id_value', - instance=spanner_instance_admin.Instance(name='name_value'), - ) - -@pytest.mark.asyncio -async def test_create_instance_flattened_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.create_instance( - parent='parent_value', - instance_id='instance_id_value', - instance=spanner_instance_admin.Instance(name='name_value'), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].parent - mock_val = 'parent_value' - assert arg == mock_val - arg = args[0].instance_id - mock_val = 'instance_id_value' - assert arg == mock_val - arg = args[0].instance - mock_val = spanner_instance_admin.Instance(name='name_value') - assert arg == mock_val - -@pytest.mark.asyncio -async def test_create_instance_flattened_error_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.create_instance( - spanner_instance_admin.CreateInstanceRequest(), - parent='parent_value', - instance_id='instance_id_value', - instance=spanner_instance_admin.Instance(name='name_value'), - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.UpdateInstanceRequest, - dict, -]) -def test_update_instance(request_type, transport: str = 'grpc'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/spam') - response = client.update_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.UpdateInstanceRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_update_instance_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_instance), - '__call__') as call: - client.update_instance() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.UpdateInstanceRequest() - -@pytest.mark.asyncio -async def test_update_instance_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.UpdateInstanceRequest): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - response = await client.update_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.UpdateInstanceRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -@pytest.mark.asyncio -async def test_update_instance_async_from_dict(): - await test_update_instance_async(request_type=dict) - - -def test_update_instance_field_headers(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.UpdateInstanceRequest() - - request.instance.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_instance), - '__call__') as call: - call.return_value = operations_pb2.Operation(name='operations/op') - client.update_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'instance.name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_update_instance_field_headers_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.UpdateInstanceRequest() - - request.instance.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_instance), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(operations_pb2.Operation(name='operations/op')) - await client.update_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'instance.name=name_value', - ) in kw['metadata'] - - -def test_update_instance_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.update_instance( - instance=spanner_instance_admin.Instance(name='name_value'), - field_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].instance - mock_val = spanner_instance_admin.Instance(name='name_value') - assert arg == mock_val - arg = args[0].field_mask - mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) - assert arg == mock_val - - -def test_update_instance_flattened_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_instance( - spanner_instance_admin.UpdateInstanceRequest(), - instance=spanner_instance_admin.Instance(name='name_value'), - field_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - -@pytest.mark.asyncio -async def test_update_instance_flattened_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.update_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name='operations/op') - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name='operations/spam') - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.update_instance( - instance=spanner_instance_admin.Instance(name='name_value'), - field_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].instance - mock_val = spanner_instance_admin.Instance(name='name_value') - assert arg == mock_val - arg = args[0].field_mask - mock_val = field_mask_pb2.FieldMask(paths=['paths_value']) - assert arg == mock_val - -@pytest.mark.asyncio -async def test_update_instance_flattened_error_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.update_instance( - spanner_instance_admin.UpdateInstanceRequest(), - instance=spanner_instance_admin.Instance(name='name_value'), - field_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.DeleteInstanceRequest, - dict, -]) -def test_delete_instance(request_type, transport: str = 'grpc'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - response = client.delete_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.DeleteInstanceRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_instance_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_instance), - '__call__') as call: - client.delete_instance() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.DeleteInstanceRequest() - -@pytest.mark.asyncio -async def test_delete_instance_async(transport: str = 'grpc_asyncio', request_type=spanner_instance_admin.DeleteInstanceRequest): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - response = await client.delete_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == spanner_instance_admin.DeleteInstanceRequest() - - # Establish that the response is the type that we expect. - assert response is None - - -@pytest.mark.asyncio -async def test_delete_instance_async_from_dict(): - await test_delete_instance_async(request_type=dict) - - -def test_delete_instance_field_headers(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.DeleteInstanceRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_instance), - '__call__') as call: - call.return_value = None - client.delete_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_delete_instance_field_headers_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = spanner_instance_admin.DeleteInstanceRequest() - - request.name = 'name_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_instance), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - await client.delete_instance(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'name=name_value', - ) in kw['metadata'] - - -def test_delete_instance_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.delete_instance( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - - -def test_delete_instance_flattened_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_instance( - spanner_instance_admin.DeleteInstanceRequest(), - name='name_value', - ) - -@pytest.mark.asyncio -async def test_delete_instance_flattened_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_instance), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = None - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.delete_instance( - name='name_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].name - mock_val = 'name_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_delete_instance_flattened_error_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.delete_instance( - spanner_instance_admin.DeleteInstanceRequest(), - name='name_value', - ) - - -@pytest.mark.parametrize("request_type", [ - iam_policy_pb2.SetIamPolicyRequest, - dict, -]) -def test_set_iam_policy(request_type, transport: str = 'grpc'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy( - version=774, - etag=b'etag_blob', - ) - response = client.set_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.SetIamPolicyRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, policy_pb2.Policy) - assert response.version == 774 - assert response.etag == b'etag_blob' - - -def test_set_iam_policy_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - client.set_iam_policy() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.SetIamPolicyRequest() - -@pytest.mark.asyncio -async def test_set_iam_policy_async(transport: str = 'grpc_asyncio', request_type=iam_policy_pb2.SetIamPolicyRequest): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy( - version=774, - etag=b'etag_blob', - )) - response = await client.set_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.SetIamPolicyRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, policy_pb2.Policy) - assert response.version == 774 - assert response.etag == b'etag_blob' - - -@pytest.mark.asyncio -async def test_set_iam_policy_async_from_dict(): - await test_set_iam_policy_async(request_type=dict) - - -def test_set_iam_policy_field_headers(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = iam_policy_pb2.SetIamPolicyRequest() - - request.resource = 'resource_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - call.return_value = policy_pb2.Policy() - client.set_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'resource=resource_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_set_iam_policy_field_headers_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = iam_policy_pb2.SetIamPolicyRequest() - - request.resource = 'resource_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - await client.set_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'resource=resource_value', - ) in kw['metadata'] - -def test_set_iam_policy_from_dict_foreign(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() - response = client.set_iam_policy(request={ - 'resource': 'resource_value', - 'policy': policy_pb2.Policy(version=774), - 'update_mask': field_mask_pb2.FieldMask(paths=['paths_value']), - } - ) - call.assert_called() - - -def test_set_iam_policy_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.set_iam_policy( - resource='resource_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].resource - mock_val = 'resource_value' - assert arg == mock_val - - -def test_set_iam_policy_flattened_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.set_iam_policy( - iam_policy_pb2.SetIamPolicyRequest(), - resource='resource_value', - ) - -@pytest.mark.asyncio -async def test_set_iam_policy_flattened_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.set_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.set_iam_policy( - resource='resource_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].resource - mock_val = 'resource_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_set_iam_policy_flattened_error_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.set_iam_policy( - iam_policy_pb2.SetIamPolicyRequest(), - resource='resource_value', - ) - - -@pytest.mark.parametrize("request_type", [ - iam_policy_pb2.GetIamPolicyRequest, - dict, -]) -def test_get_iam_policy(request_type, transport: str = 'grpc'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy( - version=774, - etag=b'etag_blob', - ) - response = client.get_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.GetIamPolicyRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, policy_pb2.Policy) - assert response.version == 774 - assert response.etag == b'etag_blob' - - -def test_get_iam_policy_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - client.get_iam_policy() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.GetIamPolicyRequest() - -@pytest.mark.asyncio -async def test_get_iam_policy_async(transport: str = 'grpc_asyncio', request_type=iam_policy_pb2.GetIamPolicyRequest): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy( - version=774, - etag=b'etag_blob', - )) - response = await client.get_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.GetIamPolicyRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, policy_pb2.Policy) - assert response.version == 774 - assert response.etag == b'etag_blob' - - -@pytest.mark.asyncio -async def test_get_iam_policy_async_from_dict(): - await test_get_iam_policy_async(request_type=dict) - - -def test_get_iam_policy_field_headers(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = iam_policy_pb2.GetIamPolicyRequest() - - request.resource = 'resource_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - call.return_value = policy_pb2.Policy() - client.get_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'resource=resource_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_get_iam_policy_field_headers_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = iam_policy_pb2.GetIamPolicyRequest() - - request.resource = 'resource_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - await client.get_iam_policy(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'resource=resource_value', - ) in kw['metadata'] - -def test_get_iam_policy_from_dict_foreign(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() - response = client.get_iam_policy(request={ - 'resource': 'resource_value', - 'options': options_pb2.GetPolicyOptions(requested_policy_version=2598), - } - ) - call.assert_called() - - -def test_get_iam_policy_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.get_iam_policy( - resource='resource_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].resource - mock_val = 'resource_value' - assert arg == mock_val - - -def test_get_iam_policy_flattened_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_iam_policy( - iam_policy_pb2.GetIamPolicyRequest(), - resource='resource_value', - ) - -@pytest.mark.asyncio -async def test_get_iam_policy_flattened_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_iam_policy), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = policy_pb2.Policy() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.get_iam_policy( - resource='resource_value', - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].resource - mock_val = 'resource_value' - assert arg == mock_val - -@pytest.mark.asyncio -async def test_get_iam_policy_flattened_error_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.get_iam_policy( - iam_policy_pb2.GetIamPolicyRequest(), - resource='resource_value', - ) - - -@pytest.mark.parametrize("request_type", [ - iam_policy_pb2.TestIamPermissionsRequest, - dict, -]) -def test_test_iam_permissions(request_type, transport: str = 'grpc'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = iam_policy_pb2.TestIamPermissionsResponse( - permissions=['permissions_value'], - ) - response = client.test_iam_permissions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) - assert response.permissions == ['permissions_value'] - - -def test_test_iam_permissions_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - client.test_iam_permissions() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() - -@pytest.mark.asyncio -async def test_test_iam_permissions_async(transport: str = 'grpc_asyncio', request_type=iam_policy_pb2.TestIamPermissionsRequest): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value =grpc_helpers_async.FakeUnaryUnaryCall(iam_policy_pb2.TestIamPermissionsResponse( - permissions=['permissions_value'], - )) - response = await client.test_iam_permissions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) - assert response.permissions == ['permissions_value'] - - -@pytest.mark.asyncio -async def test_test_iam_permissions_async_from_dict(): - await test_test_iam_permissions_async(request_type=dict) - - -def test_test_iam_permissions_field_headers(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = iam_policy_pb2.TestIamPermissionsRequest() - - request.resource = 'resource_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - call.return_value = iam_policy_pb2.TestIamPermissionsResponse() - client.test_iam_permissions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'resource=resource_value', - ) in kw['metadata'] - - -@pytest.mark.asyncio -async def test_test_iam_permissions_field_headers_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = iam_policy_pb2.TestIamPermissionsRequest() - - request.resource = 'resource_value' - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(iam_policy_pb2.TestIamPermissionsResponse()) - await client.test_iam_permissions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ( - 'x-goog-request-params', - 'resource=resource_value', - ) in kw['metadata'] - -def test_test_iam_permissions_from_dict_foreign(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = iam_policy_pb2.TestIamPermissionsResponse() - response = client.test_iam_permissions(request={ - 'resource': 'resource_value', - 'permissions': ['permissions_value'], - } - ) - call.assert_called() - - -def test_test_iam_permissions_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = iam_policy_pb2.TestIamPermissionsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.test_iam_permissions( - resource='resource_value', - permissions=['permissions_value'], - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - arg = args[0].resource - mock_val = 'resource_value' - assert arg == mock_val - arg = args[0].permissions - mock_val = ['permissions_value'] - assert arg == mock_val - - -def test_test_iam_permissions_flattened_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.test_iam_permissions( - iam_policy_pb2.TestIamPermissionsRequest(), - resource='resource_value', - permissions=['permissions_value'], - ) - -@pytest.mark.asyncio -async def test_test_iam_permissions_flattened_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.test_iam_permissions), - '__call__') as call: - # Designate an appropriate return value for the call. - call.return_value = iam_policy_pb2.TestIamPermissionsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(iam_policy_pb2.TestIamPermissionsResponse()) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.test_iam_permissions( - resource='resource_value', - permissions=['permissions_value'], - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - arg = args[0].resource - mock_val = 'resource_value' - assert arg == mock_val - arg = args[0].permissions - mock_val = ['permissions_value'] - assert arg == mock_val - -@pytest.mark.asyncio -async def test_test_iam_permissions_flattened_error_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.test_iam_permissions( - iam_policy_pb2.TestIamPermissionsRequest(), - resource='resource_value', - permissions=['permissions_value'], - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.ListInstanceConfigsRequest, - dict, -]) -def test_list_instance_configs_rest(request_type): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.ListInstanceConfigsResponse( - next_page_token='next_page_token_value', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_instance_admin.ListInstanceConfigsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.list_instance_configs(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListInstanceConfigsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_instance_configs_rest_required_fields(request_type=spanner_instance_admin.ListInstanceConfigsRequest): - transport_class = transports.InstanceAdminRestTransport - - request_init = {} - request_init["parent"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_instance_configs._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["parent"] = 'parent_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_instance_configs._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("page_size", "page_token", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.ListInstanceConfigsResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner_instance_admin.ListInstanceConfigsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.list_instance_configs(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_list_instance_configs_rest_unset_required_fields(): - transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.list_instance_configs._get_unset_required_fields({}) - assert set(unset_fields) == (set(("pageSize", "pageToken", )) & set(("parent", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_instance_configs_rest_interceptors(null_interceptor): - transport = transports.InstanceAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), - ) - client = InstanceAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "post_list_instance_configs") as post, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_list_instance_configs") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_instance_admin.ListInstanceConfigsRequest.pb(spanner_instance_admin.ListInstanceConfigsRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner_instance_admin.ListInstanceConfigsResponse.to_json(spanner_instance_admin.ListInstanceConfigsResponse()) - - request = spanner_instance_admin.ListInstanceConfigsRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner_instance_admin.ListInstanceConfigsResponse() - - client.list_instance_configs(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_list_instance_configs_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.ListInstanceConfigsRequest): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.list_instance_configs(request) - - -def test_list_instance_configs_rest_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.ListInstanceConfigsResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'projects/sample1'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_instance_admin.ListInstanceConfigsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.list_instance_configs(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{parent=projects/*}/instanceConfigs" % client.transport._host, args[1]) - - -def test_list_instance_configs_rest_flattened_error(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_instance_configs( - spanner_instance_admin.ListInstanceConfigsRequest(), - parent='parent_value', - ) - - -def test_list_instance_configs_rest_pager(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - #with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstanceConfigsResponse( - instance_configs=[ - spanner_instance_admin.InstanceConfig(), - spanner_instance_admin.InstanceConfig(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(spanner_instance_admin.ListInstanceConfigsResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode('UTF-8') - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {'parent': 'projects/sample1'} - - pager = client.list_instance_configs(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, spanner_instance_admin.InstanceConfig) - for i in results) - - pages = list(client.list_instance_configs(request=sample_request).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.GetInstanceConfigRequest, - dict, -]) -def test_get_instance_config_rest(request_type): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instanceConfigs/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.InstanceConfig( - name='name_value', - display_name='display_name_value', - config_type=spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED, - base_config='base_config_value', - etag='etag_value', - leader_options=['leader_options_value'], - reconciling=True, - state=spanner_instance_admin.InstanceConfig.State.CREATING, - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_instance_admin.InstanceConfig.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.get_instance_config(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner_instance_admin.InstanceConfig) - assert response.name == 'name_value' - assert response.display_name == 'display_name_value' - assert response.config_type == spanner_instance_admin.InstanceConfig.Type.GOOGLE_MANAGED - assert response.base_config == 'base_config_value' - assert response.etag == 'etag_value' - assert response.leader_options == ['leader_options_value'] - assert response.reconciling is True - assert response.state == spanner_instance_admin.InstanceConfig.State.CREATING - - -def test_get_instance_config_rest_required_fields(request_type=spanner_instance_admin.GetInstanceConfigRequest): - transport_class = transports.InstanceAdminRestTransport - - request_init = {} - request_init["name"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_instance_config._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["name"] = 'name_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_instance_config._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == 'name_value' - - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.InstanceConfig() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner_instance_admin.InstanceConfig.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.get_instance_config(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_get_instance_config_rest_unset_required_fields(): - transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.get_instance_config._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_instance_config_rest_interceptors(null_interceptor): - transport = transports.InstanceAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), - ) - client = InstanceAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "post_get_instance_config") as post, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_get_instance_config") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_instance_admin.GetInstanceConfigRequest.pb(spanner_instance_admin.GetInstanceConfigRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner_instance_admin.InstanceConfig.to_json(spanner_instance_admin.InstanceConfig()) - - request = spanner_instance_admin.GetInstanceConfigRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner_instance_admin.InstanceConfig() - - client.get_instance_config(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_get_instance_config_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.GetInstanceConfigRequest): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instanceConfigs/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.get_instance_config(request) - - -def test_get_instance_config_rest_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.InstanceConfig() - - # get arguments that satisfy an http rule for this method - sample_request = {'name': 'projects/sample1/instanceConfigs/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - name='name_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_instance_admin.InstanceConfig.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.get_instance_config(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{name=projects/*/instanceConfigs/*}" % client.transport._host, args[1]) - - -def test_get_instance_config_rest_flattened_error(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_instance_config( - spanner_instance_admin.GetInstanceConfigRequest(), - name='name_value', - ) - - -def test_get_instance_config_rest_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.CreateInstanceConfigRequest, - dict, -]) -def test_create_instance_config_rest(request_type): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.create_instance_config(request) - - # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" - - -def test_create_instance_config_rest_required_fields(request_type=spanner_instance_admin.CreateInstanceConfigRequest): - transport_class = transports.InstanceAdminRestTransport - - request_init = {} - request_init["parent"] = "" - request_init["instance_config_id"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_instance_config._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["parent"] = 'parent_value' - jsonified_request["instanceConfigId"] = 'instance_config_id_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_instance_config._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - assert "instanceConfigId" in jsonified_request - assert jsonified_request["instanceConfigId"] == 'instance_config_id_value' - - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.create_instance_config(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_create_instance_config_rest_unset_required_fields(): - transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.create_instance_config._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("parent", "instanceConfigId", "instanceConfig", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_instance_config_rest_interceptors(null_interceptor): - transport = transports.InstanceAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), - ) - client = InstanceAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(operation.Operation, "_set_result_from_operation"), \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "post_create_instance_config") as post, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_create_instance_config") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_instance_admin.CreateInstanceConfigRequest.pb(spanner_instance_admin.CreateInstanceConfigRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) - - request = spanner_instance_admin.CreateInstanceConfigRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - - client.create_instance_config(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_create_instance_config_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.CreateInstanceConfigRequest): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.create_instance_config(request) - - -def test_create_instance_config_rest_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'projects/sample1'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), - instance_config_id='instance_config_id_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.create_instance_config(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{parent=projects/*}/instanceConfigs" % client.transport._host, args[1]) - - -def test_create_instance_config_rest_flattened_error(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_instance_config( - spanner_instance_admin.CreateInstanceConfigRequest(), - parent='parent_value', - instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), - instance_config_id='instance_config_id_value', - ) - - -def test_create_instance_config_rest_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.UpdateInstanceConfigRequest, - dict, -]) -def test_update_instance_config_rest(request_type): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'instance_config': {'name': 'projects/sample1/instanceConfigs/sample2'}} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.update_instance_config(request) - - # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" - - -def test_update_instance_config_rest_required_fields(request_type=spanner_instance_admin.UpdateInstanceConfigRequest): - transport_class = transports.InstanceAdminRestTransport - - request_init = {} - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_instance_config._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_instance_config._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "patch", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.update_instance_config(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_update_instance_config_rest_unset_required_fields(): - transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.update_instance_config._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("instanceConfig", "updateMask", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_instance_config_rest_interceptors(null_interceptor): - transport = transports.InstanceAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), - ) - client = InstanceAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(operation.Operation, "_set_result_from_operation"), \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "post_update_instance_config") as post, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_update_instance_config") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_instance_admin.UpdateInstanceConfigRequest.pb(spanner_instance_admin.UpdateInstanceConfigRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) - - request = spanner_instance_admin.UpdateInstanceConfigRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - - client.update_instance_config(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_update_instance_config_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.UpdateInstanceConfigRequest): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'instance_config': {'name': 'projects/sample1/instanceConfigs/sample2'}} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.update_instance_config(request) - - -def test_update_instance_config_rest_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # get arguments that satisfy an http rule for this method - sample_request = {'instance_config': {'name': 'projects/sample1/instanceConfigs/sample2'}} - - # get truthy value for each flattened field - mock_args = dict( - instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.update_instance_config(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{instance_config.name=projects/*/instanceConfigs/*}" % client.transport._host, args[1]) - - -def test_update_instance_config_rest_flattened_error(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_instance_config( - spanner_instance_admin.UpdateInstanceConfigRequest(), - instance_config=spanner_instance_admin.InstanceConfig(name='name_value'), - update_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -def test_update_instance_config_rest_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.DeleteInstanceConfigRequest, - dict, -]) -def test_delete_instance_config_rest(request_type): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instanceConfigs/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.delete_instance_config(request) - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_instance_config_rest_required_fields(request_type=spanner_instance_admin.DeleteInstanceConfigRequest): - transport_class = transports.InstanceAdminRestTransport - - request_init = {} - request_init["name"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_instance_config._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["name"] = 'name_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_instance_config._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("etag", "validate_only", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == 'name_value' - - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = None - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "delete", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.delete_instance_config(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_delete_instance_config_rest_unset_required_fields(): - transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.delete_instance_config._get_unset_required_fields({}) - assert set(unset_fields) == (set(("etag", "validateOnly", )) & set(("name", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_instance_config_rest_interceptors(null_interceptor): - transport = transports.InstanceAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), - ) - client = InstanceAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_delete_instance_config") as pre: - pre.assert_not_called() - pb_message = spanner_instance_admin.DeleteInstanceConfigRequest.pb(spanner_instance_admin.DeleteInstanceConfigRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - - request = spanner_instance_admin.DeleteInstanceConfigRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - - client.delete_instance_config(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - - -def test_delete_instance_config_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.DeleteInstanceConfigRequest): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instanceConfigs/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.delete_instance_config(request) - - -def test_delete_instance_config_rest_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # get arguments that satisfy an http rule for this method - sample_request = {'name': 'projects/sample1/instanceConfigs/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - name='name_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.delete_instance_config(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{name=projects/*/instanceConfigs/*}" % client.transport._host, args[1]) - - -def test_delete_instance_config_rest_flattened_error(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_instance_config( - spanner_instance_admin.DeleteInstanceConfigRequest(), - name='name_value', - ) - - -def test_delete_instance_config_rest_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.ListInstanceConfigOperationsRequest, - dict, -]) -def test_list_instance_config_operations_rest(request_type): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse( - next_page_token='next_page_token_value', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.list_instance_config_operations(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListInstanceConfigOperationsPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_instance_config_operations_rest_required_fields(request_type=spanner_instance_admin.ListInstanceConfigOperationsRequest): - transport_class = transports.InstanceAdminRestTransport - - request_init = {} - request_init["parent"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_instance_config_operations._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["parent"] = 'parent_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_instance_config_operations._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("filter", "page_size", "page_token", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.list_instance_config_operations(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_list_instance_config_operations_rest_unset_required_fields(): - transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.list_instance_config_operations._get_unset_required_fields({}) - assert set(unset_fields) == (set(("filter", "pageSize", "pageToken", )) & set(("parent", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_instance_config_operations_rest_interceptors(null_interceptor): - transport = transports.InstanceAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), - ) - client = InstanceAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "post_list_instance_config_operations") as post, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_list_instance_config_operations") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_instance_admin.ListInstanceConfigOperationsRequest.pb(spanner_instance_admin.ListInstanceConfigOperationsRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner_instance_admin.ListInstanceConfigOperationsResponse.to_json(spanner_instance_admin.ListInstanceConfigOperationsResponse()) - - request = spanner_instance_admin.ListInstanceConfigOperationsRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse() - - client.list_instance_config_operations(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_list_instance_config_operations_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.ListInstanceConfigOperationsRequest): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.list_instance_config_operations(request) - - -def test_list_instance_config_operations_rest_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'projects/sample1'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_instance_admin.ListInstanceConfigOperationsResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.list_instance_config_operations(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{parent=projects/*}/instanceConfigOperations" % client.transport._host, args[1]) - - -def test_list_instance_config_operations_rest_flattened_error(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_instance_config_operations( - spanner_instance_admin.ListInstanceConfigOperationsRequest(), - parent='parent_value', - ) - - -def test_list_instance_config_operations_rest_pager(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - #with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstanceConfigOperationsResponse( - operations=[ - operations_pb2.Operation(), - operations_pb2.Operation(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(spanner_instance_admin.ListInstanceConfigOperationsResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode('UTF-8') - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {'parent': 'projects/sample1'} - - pager = client.list_instance_config_operations(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, operations_pb2.Operation) - for i in results) - - pages = list(client.list_instance_config_operations(request=sample_request).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.ListInstancesRequest, - dict, -]) -def test_list_instances_rest(request_type): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.ListInstancesResponse( - next_page_token='next_page_token_value', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_instance_admin.ListInstancesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.list_instances(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListInstancesPager) - assert response.next_page_token == 'next_page_token_value' - - -def test_list_instances_rest_required_fields(request_type=spanner_instance_admin.ListInstancesRequest): - transport_class = transports.InstanceAdminRestTransport - - request_init = {} - request_init["parent"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_instances._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["parent"] = 'parent_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).list_instances._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("filter", "page_size", "page_token", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.ListInstancesResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner_instance_admin.ListInstancesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.list_instances(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_list_instances_rest_unset_required_fields(): - transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.list_instances._get_unset_required_fields({}) - assert set(unset_fields) == (set(("filter", "pageSize", "pageToken", )) & set(("parent", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_list_instances_rest_interceptors(null_interceptor): - transport = transports.InstanceAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), - ) - client = InstanceAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "post_list_instances") as post, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_list_instances") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_instance_admin.ListInstancesRequest.pb(spanner_instance_admin.ListInstancesRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner_instance_admin.ListInstancesResponse.to_json(spanner_instance_admin.ListInstancesResponse()) - - request = spanner_instance_admin.ListInstancesRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner_instance_admin.ListInstancesResponse() - - client.list_instances(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_list_instances_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.ListInstancesRequest): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.list_instances(request) - - -def test_list_instances_rest_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.ListInstancesResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'projects/sample1'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_instance_admin.ListInstancesResponse.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.list_instances(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{parent=projects/*}/instances" % client.transport._host, args[1]) - - -def test_list_instances_rest_flattened_error(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.list_instances( - spanner_instance_admin.ListInstancesRequest(), - parent='parent_value', - ) - - -def test_list_instances_rest_pager(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # TODO(kbandes): remove this mock unless there's a good reason for it. - #with mock.patch.object(path_template, 'transcode') as transcode: - # Set the response as a series of pages - response = ( - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - ], - next_page_token='abc', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[], - next_page_token='def', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - ], - next_page_token='ghi', - ), - spanner_instance_admin.ListInstancesResponse( - instances=[ - spanner_instance_admin.Instance(), - spanner_instance_admin.Instance(), - ], - ), - ) - # Two responses for two calls - response = response + response - - # Wrap the values into proper Response objs - response = tuple(spanner_instance_admin.ListInstancesResponse.to_json(x) for x in response) - return_values = tuple(Response() for i in response) - for return_val, response_val in zip(return_values, response): - return_val._content = response_val.encode('UTF-8') - return_val.status_code = 200 - req.side_effect = return_values - - sample_request = {'parent': 'projects/sample1'} - - pager = client.list_instances(request=sample_request) - - results = list(pager) - assert len(results) == 6 - assert all(isinstance(i, spanner_instance_admin.Instance) - for i in results) - - pages = list(client.list_instances(request=sample_request).pages) - for page_, token in zip(pages, ['abc','def','ghi', '']): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.GetInstanceRequest, - dict, -]) -def test_get_instance_rest(request_type): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.Instance( - name='name_value', - config='config_value', - display_name='display_name_value', - node_count=1070, - processing_units=1743, - state=spanner_instance_admin.Instance.State.CREATING, - endpoint_uris=['endpoint_uris_value'], - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_instance_admin.Instance.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.get_instance(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, spanner_instance_admin.Instance) - assert response.name == 'name_value' - assert response.config == 'config_value' - assert response.display_name == 'display_name_value' - assert response.node_count == 1070 - assert response.processing_units == 1743 - assert response.state == spanner_instance_admin.Instance.State.CREATING - assert response.endpoint_uris == ['endpoint_uris_value'] - - -def test_get_instance_rest_required_fields(request_type=spanner_instance_admin.GetInstanceRequest): - transport_class = transports.InstanceAdminRestTransport - - request_init = {} - request_init["name"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_instance._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["name"] = 'name_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_instance._get_unset_required_fields(jsonified_request) - # Check that path parameters and body parameters are not mixing in. - assert not set(unset_fields) - set(("field_mask", )) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == 'name_value' - - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.Instance() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "get", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = spanner_instance_admin.Instance.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.get_instance(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_get_instance_rest_unset_required_fields(): - transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.get_instance._get_unset_required_fields({}) - assert set(unset_fields) == (set(("fieldMask", )) & set(("name", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_instance_rest_interceptors(null_interceptor): - transport = transports.InstanceAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), - ) - client = InstanceAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "post_get_instance") as post, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_get_instance") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_instance_admin.GetInstanceRequest.pb(spanner_instance_admin.GetInstanceRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = spanner_instance_admin.Instance.to_json(spanner_instance_admin.Instance()) - - request = spanner_instance_admin.GetInstanceRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = spanner_instance_admin.Instance() - - client.get_instance(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_get_instance_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.GetInstanceRequest): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.get_instance(request) - - -def test_get_instance_rest_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = spanner_instance_admin.Instance() - - # get arguments that satisfy an http rule for this method - sample_request = {'name': 'projects/sample1/instances/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - name='name_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = spanner_instance_admin.Instance.pb(return_value) - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.get_instance(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{name=projects/*/instances/*}" % client.transport._host, args[1]) - - -def test_get_instance_rest_flattened_error(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_instance( - spanner_instance_admin.GetInstanceRequest(), - name='name_value', - ) - - -def test_get_instance_rest_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.CreateInstanceRequest, - dict, -]) -def test_create_instance_rest(request_type): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.create_instance(request) - - # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" - - -def test_create_instance_rest_required_fields(request_type=spanner_instance_admin.CreateInstanceRequest): - transport_class = transports.InstanceAdminRestTransport - - request_init = {} - request_init["parent"] = "" - request_init["instance_id"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_instance._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["parent"] = 'parent_value' - jsonified_request["instanceId"] = 'instance_id_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).create_instance._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "parent" in jsonified_request - assert jsonified_request["parent"] == 'parent_value' - assert "instanceId" in jsonified_request - assert jsonified_request["instanceId"] == 'instance_id_value' - - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.create_instance(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_create_instance_rest_unset_required_fields(): - transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.create_instance._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("parent", "instanceId", "instance", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_create_instance_rest_interceptors(null_interceptor): - transport = transports.InstanceAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), - ) - client = InstanceAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(operation.Operation, "_set_result_from_operation"), \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "post_create_instance") as post, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_create_instance") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_instance_admin.CreateInstanceRequest.pb(spanner_instance_admin.CreateInstanceRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) - - request = spanner_instance_admin.CreateInstanceRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - - client.create_instance(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_create_instance_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.CreateInstanceRequest): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'parent': 'projects/sample1'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.create_instance(request) - - -def test_create_instance_rest_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # get arguments that satisfy an http rule for this method - sample_request = {'parent': 'projects/sample1'} - - # get truthy value for each flattened field - mock_args = dict( - parent='parent_value', - instance_id='instance_id_value', - instance=spanner_instance_admin.Instance(name='name_value'), - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.create_instance(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{parent=projects/*}/instances" % client.transport._host, args[1]) - - -def test_create_instance_rest_flattened_error(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.create_instance( - spanner_instance_admin.CreateInstanceRequest(), - parent='parent_value', - instance_id='instance_id_value', - instance=spanner_instance_admin.Instance(name='name_value'), - ) - - -def test_create_instance_rest_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.UpdateInstanceRequest, - dict, -]) -def test_update_instance_rest(request_type): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'instance': {'name': 'projects/sample1/instances/sample2'}} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.update_instance(request) - - # Establish that the response is the type that we expect. - assert response.operation.name == "operations/spam" - - -def test_update_instance_rest_required_fields(request_type=spanner_instance_admin.UpdateInstanceRequest): - transport_class = transports.InstanceAdminRestTransport - - request_init = {} - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_instance._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).update_instance._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "patch", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.update_instance(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_update_instance_rest_unset_required_fields(): - transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.update_instance._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("instance", "fieldMask", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_update_instance_rest_interceptors(null_interceptor): - transport = transports.InstanceAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), - ) - client = InstanceAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(operation.Operation, "_set_result_from_operation"), \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "post_update_instance") as post, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_update_instance") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = spanner_instance_admin.UpdateInstanceRequest.pb(spanner_instance_admin.UpdateInstanceRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(operations_pb2.Operation()) - - request = spanner_instance_admin.UpdateInstanceRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = operations_pb2.Operation() - - client.update_instance(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_update_instance_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.UpdateInstanceRequest): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'instance': {'name': 'projects/sample1/instances/sample2'}} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.update_instance(request) - - -def test_update_instance_rest_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = operations_pb2.Operation(name='operations/spam') - - # get arguments that satisfy an http rule for this method - sample_request = {'instance': {'name': 'projects/sample1/instances/sample2'}} - - # get truthy value for each flattened field - mock_args = dict( - instance=spanner_instance_admin.Instance(name='name_value'), - field_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = json_format.MessageToJson(return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.update_instance(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{instance.name=projects/*/instances/*}" % client.transport._host, args[1]) - - -def test_update_instance_rest_flattened_error(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.update_instance( - spanner_instance_admin.UpdateInstanceRequest(), - instance=spanner_instance_admin.Instance(name='name_value'), - field_mask=field_mask_pb2.FieldMask(paths=['paths_value']), - ) - - -def test_update_instance_rest_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - spanner_instance_admin.DeleteInstanceRequest, - dict, -]) -def test_delete_instance_rest(request_type): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.delete_instance(request) - - # Establish that the response is the type that we expect. - assert response is None - - -def test_delete_instance_rest_required_fields(request_type=spanner_instance_admin.DeleteInstanceRequest): - transport_class = transports.InstanceAdminRestTransport - - request_init = {} - request_init["name"] = "" - request = request_type(**request_init) - pb_request = request_type.pb(request) - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_instance._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["name"] = 'name_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).delete_instance._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "name" in jsonified_request - assert jsonified_request["name"] == 'name_value' - - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = None - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request_type.pb(request) - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "delete", - 'query_params': pb_request, - } - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.delete_instance(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_delete_instance_rest_unset_required_fields(): - transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.delete_instance._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("name", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_delete_instance_rest_interceptors(null_interceptor): - transport = transports.InstanceAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), - ) - client = InstanceAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_delete_instance") as pre: - pre.assert_not_called() - pb_message = spanner_instance_admin.DeleteInstanceRequest.pb(spanner_instance_admin.DeleteInstanceRequest()) - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - - request = spanner_instance_admin.DeleteInstanceRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - - client.delete_instance(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - - -def test_delete_instance_rest_bad_request(transport: str = 'rest', request_type=spanner_instance_admin.DeleteInstanceRequest): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'name': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.delete_instance(request) - - -def test_delete_instance_rest_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = None - - # get arguments that satisfy an http rule for this method - sample_request = {'name': 'projects/sample1/instances/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - name='name_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - json_return_value = '' - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.delete_instance(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{name=projects/*/instances/*}" % client.transport._host, args[1]) - - -def test_delete_instance_rest_flattened_error(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.delete_instance( - spanner_instance_admin.DeleteInstanceRequest(), - name='name_value', - ) - - -def test_delete_instance_rest_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - iam_policy_pb2.SetIamPolicyRequest, - dict, -]) -def test_set_iam_policy_rest(request_type): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'resource': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy( - version=774, - etag=b'etag_blob', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.set_iam_policy(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, policy_pb2.Policy) - assert response.version == 774 - assert response.etag == b'etag_blob' - - -def test_set_iam_policy_rest_required_fields(request_type=iam_policy_pb2.SetIamPolicyRequest): - transport_class = transports.InstanceAdminRestTransport - - request_init = {} - request_init["resource"] = "" - request = request_type(**request_init) - pb_request = request - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).set_iam_policy._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["resource"] = 'resource_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).set_iam_policy._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "resource" in jsonified_request - assert jsonified_request["resource"] == 'resource_value' - - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.set_iam_policy(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_set_iam_policy_rest_unset_required_fields(): - transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.set_iam_policy._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("resource", "policy", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_set_iam_policy_rest_interceptors(null_interceptor): - transport = transports.InstanceAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), - ) - client = InstanceAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "post_set_iam_policy") as post, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_set_iam_policy") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = iam_policy_pb2.SetIamPolicyRequest() - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(policy_pb2.Policy()) - - request = iam_policy_pb2.SetIamPolicyRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = policy_pb2.Policy() - - client.set_iam_policy(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_set_iam_policy_rest_bad_request(transport: str = 'rest', request_type=iam_policy_pb2.SetIamPolicyRequest): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'resource': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.set_iam_policy(request) - - -def test_set_iam_policy_rest_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy() - - # get arguments that satisfy an http rule for this method - sample_request = {'resource': 'projects/sample1/instances/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - resource='resource_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.set_iam_policy(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{resource=projects/*/instances/*}:setIamPolicy" % client.transport._host, args[1]) - - -def test_set_iam_policy_rest_flattened_error(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.set_iam_policy( - iam_policy_pb2.SetIamPolicyRequest(), - resource='resource_value', - ) - - -def test_set_iam_policy_rest_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - iam_policy_pb2.GetIamPolicyRequest, - dict, -]) -def test_get_iam_policy_rest(request_type): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'resource': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy( - version=774, - etag=b'etag_blob', - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.get_iam_policy(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, policy_pb2.Policy) - assert response.version == 774 - assert response.etag == b'etag_blob' - - -def test_get_iam_policy_rest_required_fields(request_type=iam_policy_pb2.GetIamPolicyRequest): - transport_class = transports.InstanceAdminRestTransport - - request_init = {} - request_init["resource"] = "" - request = request_type(**request_init) - pb_request = request - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_iam_policy._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["resource"] = 'resource_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).get_iam_policy._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "resource" in jsonified_request - assert jsonified_request["resource"] == 'resource_value' - - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.get_iam_policy(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_get_iam_policy_rest_unset_required_fields(): - transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.get_iam_policy._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("resource", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_get_iam_policy_rest_interceptors(null_interceptor): - transport = transports.InstanceAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), - ) - client = InstanceAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "post_get_iam_policy") as post, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_get_iam_policy") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = iam_policy_pb2.GetIamPolicyRequest() - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(policy_pb2.Policy()) - - request = iam_policy_pb2.GetIamPolicyRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = policy_pb2.Policy() - - client.get_iam_policy(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_get_iam_policy_rest_bad_request(transport: str = 'rest', request_type=iam_policy_pb2.GetIamPolicyRequest): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'resource': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.get_iam_policy(request) - - -def test_get_iam_policy_rest_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = policy_pb2.Policy() - - # get arguments that satisfy an http rule for this method - sample_request = {'resource': 'projects/sample1/instances/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - resource='resource_value', - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.get_iam_policy(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{resource=projects/*/instances/*}:getIamPolicy" % client.transport._host, args[1]) - - -def test_get_iam_policy_rest_flattened_error(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.get_iam_policy( - iam_policy_pb2.GetIamPolicyRequest(), - resource='resource_value', - ) - - -def test_get_iam_policy_rest_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -@pytest.mark.parametrize("request_type", [ - iam_policy_pb2.TestIamPermissionsRequest, - dict, -]) -def test_test_iam_permissions_rest(request_type): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # send a request that will satisfy transcoding - request_init = {'resource': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = iam_policy_pb2.TestIamPermissionsResponse( - permissions=['permissions_value'], - ) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - response = client.test_iam_permissions(request) - - # Establish that the response is the type that we expect. - assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) - assert response.permissions == ['permissions_value'] - - -def test_test_iam_permissions_rest_required_fields(request_type=iam_policy_pb2.TestIamPermissionsRequest): - transport_class = transports.InstanceAdminRestTransport - - request_init = {} - request_init["resource"] = "" - request_init["permissions"] = "" - request = request_type(**request_init) - pb_request = request - jsonified_request = json.loads(json_format.MessageToJson( - pb_request, - including_default_value_fields=False, - use_integers_for_enums=False - )) - - # verify fields with default values are dropped - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).test_iam_permissions._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with default values are now present - - jsonified_request["resource"] = 'resource_value' - jsonified_request["permissions"] = 'permissions_value' - - unset_fields = transport_class(credentials=ga_credentials.AnonymousCredentials()).test_iam_permissions._get_unset_required_fields(jsonified_request) - jsonified_request.update(unset_fields) - - # verify required fields with non-default values are left alone - assert "resource" in jsonified_request - assert jsonified_request["resource"] == 'resource_value' - assert "permissions" in jsonified_request - assert jsonified_request["permissions"] == 'permissions_value' - - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - request = request_type(**request_init) - - # Designate an appropriate value for the returned response. - return_value = iam_policy_pb2.TestIamPermissionsResponse() - # Mock the http request call within the method and fake a response. - with mock.patch.object(Session, 'request') as req: - # We need to mock transcode() because providing default values - # for required fields will fail the real version if the http_options - # expect actual values for those fields. - with mock.patch.object(path_template, 'transcode') as transcode: - # A uri without fields and an empty body will force all the - # request fields to show up in the query_params. - pb_request = request - transcode_result = { - 'uri': 'v1/sample_method', - 'method': "post", - 'query_params': pb_request, - } - transcode_result['body'] = pb_request - transcode.return_value = transcode_result - - response_value = Response() - response_value.status_code = 200 - - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - response = client.test_iam_permissions(request) - - expected_params = [ - ('$alt', 'json;enum-encoding=int') - ] - actual_params = req.call_args.kwargs['params'] - assert expected_params == actual_params - - -def test_test_iam_permissions_rest_unset_required_fields(): - transport = transports.InstanceAdminRestTransport(credentials=ga_credentials.AnonymousCredentials) - - unset_fields = transport.test_iam_permissions._get_unset_required_fields({}) - assert set(unset_fields) == (set(()) & set(("resource", "permissions", ))) - - -@pytest.mark.parametrize("null_interceptor", [True, False]) -def test_test_iam_permissions_rest_interceptors(null_interceptor): - transport = transports.InstanceAdminRestTransport( - credentials=ga_credentials.AnonymousCredentials(), - interceptor=None if null_interceptor else transports.InstanceAdminRestInterceptor(), - ) - client = InstanceAdminClient(transport=transport) - with mock.patch.object(type(client.transport._session), "request") as req, \ - mock.patch.object(path_template, "transcode") as transcode, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "post_test_iam_permissions") as post, \ - mock.patch.object(transports.InstanceAdminRestInterceptor, "pre_test_iam_permissions") as pre: - pre.assert_not_called() - post.assert_not_called() - pb_message = iam_policy_pb2.TestIamPermissionsRequest() - transcode.return_value = { - "method": "post", - "uri": "my_uri", - "body": pb_message, - "query_params": pb_message, - } - - req.return_value = Response() - req.return_value.status_code = 200 - req.return_value.request = PreparedRequest() - req.return_value._content = json_format.MessageToJson(iam_policy_pb2.TestIamPermissionsResponse()) - - request = iam_policy_pb2.TestIamPermissionsRequest() - metadata =[ - ("key", "val"), - ("cephalopod", "squid"), - ] - pre.return_value = request, metadata - post.return_value = iam_policy_pb2.TestIamPermissionsResponse() - - client.test_iam_permissions(request, metadata=[("key", "val"), ("cephalopod", "squid"),]) - - pre.assert_called_once() - post.assert_called_once() - - -def test_test_iam_permissions_rest_bad_request(transport: str = 'rest', request_type=iam_policy_pb2.TestIamPermissionsRequest): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # send a request that will satisfy transcoding - request_init = {'resource': 'projects/sample1/instances/sample2'} - request = request_type(**request_init) - - # Mock the http request call within the method and fake a BadRequest error. - with mock.patch.object(Session, 'request') as req, pytest.raises(core_exceptions.BadRequest): - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 400 - response_value.request = Request() - req.return_value = response_value - client.test_iam_permissions(request) - - -def test_test_iam_permissions_rest_flattened(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="rest", - ) - - # Mock the http request call within the method and fake a response. - with mock.patch.object(type(client.transport._session), 'request') as req: - # Designate an appropriate value for the returned response. - return_value = iam_policy_pb2.TestIamPermissionsResponse() - - # get arguments that satisfy an http rule for this method - sample_request = {'resource': 'projects/sample1/instances/sample2'} - - # get truthy value for each flattened field - mock_args = dict( - resource='resource_value', - permissions=['permissions_value'], - ) - mock_args.update(sample_request) - - # Wrap the value into a proper Response obj - response_value = Response() - response_value.status_code = 200 - pb_return_value = return_value - json_return_value = json_format.MessageToJson(pb_return_value) - response_value._content = json_return_value.encode('UTF-8') - req.return_value = response_value - - client.test_iam_permissions(**mock_args) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(req.mock_calls) == 1 - _, args, _ = req.mock_calls[0] - assert path_template.validate("%s/v1/{resource=projects/*/instances/*}:testIamPermissions" % client.transport._host, args[1]) - - -def test_test_iam_permissions_rest_flattened_error(transport: str = 'rest'): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.test_iam_permissions( - iam_policy_pb2.TestIamPermissionsRequest(), - resource='resource_value', - permissions=['permissions_value'], - ) - - -def test_test_iam_permissions_rest_error(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest' - ) - - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.InstanceAdminGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport, - ) - - # It is an error to provide a credentials file and a transport instance. - transport = transports.InstanceAdminGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = InstanceAdminClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - - # It is an error to provide an api_key and a transport instance. - transport = transports.InstanceAdminGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - options = client_options.ClientOptions() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = InstanceAdminClient( - client_options=options, - transport=transport, - ) - - # It is an error to provide an api_key and a credential. - options = mock.Mock() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = InstanceAdminClient( - client_options=options, - credentials=ga_credentials.AnonymousCredentials() - ) - - # It is an error to provide scopes and a transport instance. - transport = transports.InstanceAdminGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = InstanceAdminClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) - - -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.InstanceAdminGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = InstanceAdminClient(transport=transport) - assert client.transport is transport - -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.InstanceAdminGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - - transport = transports.InstanceAdminGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize("transport_class", [ - transports.InstanceAdminGrpcTransport, - transports.InstanceAdminGrpcAsyncIOTransport, - transports.InstanceAdminRestTransport, -]) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() - -@pytest.mark.parametrize("transport_name", [ - "grpc", - "rest", -]) -def test_transport_kind(transport_name): - transport = InstanceAdminClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert transport.kind == transport_name - -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - assert isinstance( - client.transport, - transports.InstanceAdminGrpcTransport, - ) - -def test_instance_admin_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.InstanceAdminTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json" - ) - - -def test_instance_admin_base_transport(): - # Instantiate the base transport. - with mock.patch('google.cloud.spanner_admin_instance_v1.services.instance_admin.transports.InstanceAdminTransport.__init__') as Transport: - Transport.return_value = None - transport = transports.InstanceAdminTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - 'list_instance_configs', - 'get_instance_config', - 'create_instance_config', - 'update_instance_config', - 'delete_instance_config', - 'list_instance_config_operations', - 'list_instances', - 'get_instance', - 'create_instance', - 'update_instance', - 'delete_instance', - 'set_iam_policy', - 'get_iam_policy', - 'test_iam_permissions', - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - with pytest.raises(NotImplementedError): - transport.close() - - # Additionally, the LRO client (a property) should - # also raise NotImplementedError - with pytest.raises(NotImplementedError): - transport.operations_client - - # Catch all for all remaining methods and properties - remainder = [ - 'kind', - ] - for r in remainder: - with pytest.raises(NotImplementedError): - getattr(transport, r)() - - -def test_instance_admin_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file - with mock.patch.object(google.auth, 'load_credentials_from_file', autospec=True) as load_creds, mock.patch('google.cloud.spanner_admin_instance_v1.services.instance_admin.transports.InstanceAdminTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.InstanceAdminTransport( - credentials_file="credentials.json", - quota_project_id="octopus", - ) - load_creds.assert_called_once_with("credentials.json", - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.admin', -), - quota_project_id="octopus", - ) - - -def test_instance_admin_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, 'default', autospec=True) as adc, mock.patch('google.cloud.spanner_admin_instance_v1.services.instance_admin.transports.InstanceAdminTransport._prep_wrapped_messages') as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.InstanceAdminTransport() - adc.assert_called_once() - - -def test_instance_admin_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - InstanceAdminClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.admin', -), - quota_project_id=None, - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.InstanceAdminGrpcTransport, - transports.InstanceAdminGrpcAsyncIOTransport, - ], -) -def test_instance_admin_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=( 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/spanner.admin',), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.InstanceAdminGrpcTransport, - transports.InstanceAdminGrpcAsyncIOTransport, - transports.InstanceAdminRestTransport, - ], -) -def test_instance_admin_transport_auth_gdch_credentials(transport_class): - host = 'https://language.com' - api_audience_tests = [None, 'https://language2.com'] - api_audience_expect = [host, 'https://language2.com'] - for t, e in zip(api_audience_tests, api_audience_expect): - with mock.patch.object(google.auth, 'default', autospec=True) as adc: - gdch_mock = mock.MagicMock() - type(gdch_mock).with_gdch_audience = mock.PropertyMock(return_value=gdch_mock) - adc.return_value = (gdch_mock, None) - transport_class(host=host, api_audience=t) - gdch_mock.with_gdch_audience.assert_called_once_with( - e - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.InstanceAdminGrpcTransport, grpc_helpers), - (transports.InstanceAdminGrpcAsyncIOTransport, grpc_helpers_async) - ], -) -def test_instance_admin_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class( - quota_project_id="octopus", - scopes=["1", "2"] - ) - - create_channel.assert_called_with( - "spanner.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=( - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/spanner.admin', -), - scopes=["1", "2"], - default_host="spanner.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize("transport_class", [transports.InstanceAdminGrpcTransport, transports.InstanceAdminGrpcAsyncIOTransport]) -def test_instance_admin_grpc_transport_client_cert_source_for_mtls( - transport_class -): - cred = ga_credentials.AnonymousCredentials() - - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds - ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback - ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, - private_key=expected_key - ) - -def test_instance_admin_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() - with mock.patch("google.auth.transport.requests.AuthorizedSession.configure_mtls_channel") as mock_configure_mtls_channel: - transports.InstanceAdminRestTransport ( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback - ) - mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) - - -def test_instance_admin_rest_lro_client(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='rest', - ) - transport = client.transport - - # Ensure that we have a api-core operations client. - assert isinstance( - transport.operations_client, - operations_v1.AbstractOperationsClient, - ) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client - - -@pytest.mark.parametrize("transport_name", [ - "grpc", - "grpc_asyncio", - "rest", -]) -def test_instance_admin_host_no_port(transport_name): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='spanner.googleapis.com'), - transport=transport_name, - ) - assert client.transport._host == ( - 'spanner.googleapis.com:443' - if transport_name in ['grpc', 'grpc_asyncio'] - else 'https://spanner.googleapis.com' - ) - -@pytest.mark.parametrize("transport_name", [ - "grpc", - "grpc_asyncio", - "rest", -]) -def test_instance_admin_host_with_port(transport_name): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions(api_endpoint='spanner.googleapis.com:8000'), - transport=transport_name, - ) - assert client.transport._host == ( - 'spanner.googleapis.com:8000' - if transport_name in ['grpc', 'grpc_asyncio'] - else 'https://spanner.googleapis.com:8000' - ) - -@pytest.mark.parametrize("transport_name", [ - "rest", -]) -def test_instance_admin_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() - client1 = InstanceAdminClient( - credentials=creds1, - transport=transport_name, - ) - client2 = InstanceAdminClient( - credentials=creds2, - transport=transport_name, - ) - session1 = client1.transport.list_instance_configs._session - session2 = client2.transport.list_instance_configs._session - assert session1 != session2 - session1 = client1.transport.get_instance_config._session - session2 = client2.transport.get_instance_config._session - assert session1 != session2 - session1 = client1.transport.create_instance_config._session - session2 = client2.transport.create_instance_config._session - assert session1 != session2 - session1 = client1.transport.update_instance_config._session - session2 = client2.transport.update_instance_config._session - assert session1 != session2 - session1 = client1.transport.delete_instance_config._session - session2 = client2.transport.delete_instance_config._session - assert session1 != session2 - session1 = client1.transport.list_instance_config_operations._session - session2 = client2.transport.list_instance_config_operations._session - assert session1 != session2 - session1 = client1.transport.list_instances._session - session2 = client2.transport.list_instances._session - assert session1 != session2 - session1 = client1.transport.get_instance._session - session2 = client2.transport.get_instance._session - assert session1 != session2 - session1 = client1.transport.create_instance._session - session2 = client2.transport.create_instance._session - assert session1 != session2 - session1 = client1.transport.update_instance._session - session2 = client2.transport.update_instance._session - assert session1 != session2 - session1 = client1.transport.delete_instance._session - session2 = client2.transport.delete_instance._session - assert session1 != session2 - session1 = client1.transport.set_iam_policy._session - session2 = client2.transport.set_iam_policy._session - assert session1 != session2 - session1 = client1.transport.get_iam_policy._session - session2 = client2.transport.get_iam_policy._session - assert session1 != session2 - session1 = client1.transport.test_iam_permissions._session - session2 = client2.transport.test_iam_permissions._session - assert session1 != session2 -def test_instance_admin_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.InstanceAdminGrpcTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -def test_instance_admin_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) - - # Check that channel is used if provided. - transport = transports.InstanceAdminGrpcAsyncIOTransport( - host="squid.clam.whelk", - channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.InstanceAdminGrpcTransport, transports.InstanceAdminGrpcAsyncIOTransport]) -def test_instance_admin_transport_channel_mtls_with_client_cert_source( - transport_class -): - with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, 'default') as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() - - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred - - -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize("transport_class", [transports.InstanceAdminGrpcTransport, transports.InstanceAdminGrpcAsyncIOTransport]) -def test_instance_admin_transport_channel_mtls_with_adc( - transport_class -): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() - - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) - - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=None, - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - - -def test_instance_admin_grpc_lro_client(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc', - ) - transport = client.transport - - # Ensure that we have a api-core operations client. - assert isinstance( - transport.operations_client, - operations_v1.OperationsClient, - ) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client - - -def test_instance_admin_grpc_lro_async_client(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport='grpc_asyncio', - ) - transport = client.transport - - # Ensure that we have a api-core operations client. - assert isinstance( - transport.operations_client, - operations_v1.OperationsAsyncClient, - ) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client - - -def test_instance_path(): - project = "squid" - instance = "clam" - expected = "projects/{project}/instances/{instance}".format(project=project, instance=instance, ) - actual = InstanceAdminClient.instance_path(project, instance) - assert expected == actual - - -def test_parse_instance_path(): - expected = { - "project": "whelk", - "instance": "octopus", - } - path = InstanceAdminClient.instance_path(**expected) - - # Check that the path construction is reversible. - actual = InstanceAdminClient.parse_instance_path(path) - assert expected == actual - -def test_instance_config_path(): - project = "oyster" - instance_config = "nudibranch" - expected = "projects/{project}/instanceConfigs/{instance_config}".format(project=project, instance_config=instance_config, ) - actual = InstanceAdminClient.instance_config_path(project, instance_config) - assert expected == actual - - -def test_parse_instance_config_path(): - expected = { - "project": "cuttlefish", - "instance_config": "mussel", - } - path = InstanceAdminClient.instance_config_path(**expected) - - # Check that the path construction is reversible. - actual = InstanceAdminClient.parse_instance_config_path(path) - assert expected == actual - -def test_common_billing_account_path(): - billing_account = "winkle" - expected = "billingAccounts/{billing_account}".format(billing_account=billing_account, ) - actual = InstanceAdminClient.common_billing_account_path(billing_account) - assert expected == actual - - -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "nautilus", - } - path = InstanceAdminClient.common_billing_account_path(**expected) - - # Check that the path construction is reversible. - actual = InstanceAdminClient.parse_common_billing_account_path(path) - assert expected == actual - -def test_common_folder_path(): - folder = "scallop" - expected = "folders/{folder}".format(folder=folder, ) - actual = InstanceAdminClient.common_folder_path(folder) - assert expected == actual - - -def test_parse_common_folder_path(): - expected = { - "folder": "abalone", - } - path = InstanceAdminClient.common_folder_path(**expected) - - # Check that the path construction is reversible. - actual = InstanceAdminClient.parse_common_folder_path(path) - assert expected == actual - -def test_common_organization_path(): - organization = "squid" - expected = "organizations/{organization}".format(organization=organization, ) - actual = InstanceAdminClient.common_organization_path(organization) - assert expected == actual - - -def test_parse_common_organization_path(): - expected = { - "organization": "clam", - } - path = InstanceAdminClient.common_organization_path(**expected) - - # Check that the path construction is reversible. - actual = InstanceAdminClient.parse_common_organization_path(path) - assert expected == actual - -def test_common_project_path(): - project = "whelk" - expected = "projects/{project}".format(project=project, ) - actual = InstanceAdminClient.common_project_path(project) - assert expected == actual - - -def test_parse_common_project_path(): - expected = { - "project": "octopus", - } - path = InstanceAdminClient.common_project_path(**expected) - - # Check that the path construction is reversible. - actual = InstanceAdminClient.parse_common_project_path(path) - assert expected == actual - -def test_common_location_path(): - project = "oyster" - location = "nudibranch" - expected = "projects/{project}/locations/{location}".format(project=project, location=location, ) - actual = InstanceAdminClient.common_location_path(project, location) - assert expected == actual - - -def test_parse_common_location_path(): - expected = { - "project": "cuttlefish", - "location": "mussel", - } - path = InstanceAdminClient.common_location_path(**expected) - - # Check that the path construction is reversible. - actual = InstanceAdminClient.parse_common_location_path(path) - assert expected == actual - - -def test_client_with_default_client_info(): - client_info = gapic_v1.client_info.ClientInfo() - - with mock.patch.object(transports.InstanceAdminTransport, '_prep_wrapped_messages') as prep: - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - - with mock.patch.object(transports.InstanceAdminTransport, '_prep_wrapped_messages') as prep: - transport_class = InstanceAdminClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), - client_info=client_info, - ) - prep.assert_called_once_with(client_info) - -@pytest.mark.asyncio -async def test_transport_close_async(): - client = InstanceAdminAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc_asyncio", - ) - with mock.patch.object(type(getattr(client.transport, "grpc_channel")), "close") as close: - async with client: - close.assert_not_called() - close.assert_called_once() - - -def test_transport_close(): - transports = { - "rest": "_session", - "grpc": "_grpc_channel", - } - - for transport, close_name in transports.items(): - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - with mock.patch.object(type(getattr(client.transport, close_name)), "close") as close: - with client: - close.assert_not_called() - close.assert_called_once() - -def test_client_ctx(): - transports = [ - 'rest', - 'grpc', - ] - for transport in transports: - client = InstanceAdminClient( - credentials=ga_credentials.AnonymousCredentials(), - transport=transport - ) - # Test client calls underlying transport. - with mock.patch.object(type(client.transport), "close") as close: - close.assert_not_called() - with client: - pass - close.assert_called() - -@pytest.mark.parametrize("client_class,transport_class", [ - (InstanceAdminClient, transports.InstanceAdminGrpcTransport), - (InstanceAdminAsyncClient, transports.InstanceAdminGrpcAsyncIOTransport), -]) -def test_api_key_credentials(client_class, transport_class): - with mock.patch.object( - google.auth._default, "get_api_key_credentials", create=True - ) as get_api_key_credentials: - mock_cred = mock.Mock() - get_api_key_credentials.return_value = mock_cred - options = client_options.ClientOptions() - options.api_key = "api_key" - with mock.patch.object(transport_class, "__init__") as patched: - patched.return_value = None - client = client_class(client_options=options) - patched.assert_called_once_with( - credentials=mock_cred, - credentials_file=None, - host=client.DEFAULT_ENDPOINT, - scopes=None, - client_cert_source_for_mtls=None, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - always_use_jwt_access=True, - api_audience=None, - ) diff --git a/samples/generated_samples/snippet_metadata_google.spanner.admin.database.v1.json b/samples/generated_samples/snippet_metadata_google.spanner.admin.database.v1.json index 5562aea1b3..11932ae5e8 100644 --- a/samples/generated_samples/snippet_metadata_google.spanner.admin.database.v1.json +++ b/samples/generated_samples/snippet_metadata_google.spanner.admin.database.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-spanner-admin-database", - "version": "3.33.0" + "version": "0.1.0" }, "snippets": [ { @@ -3145,6 +3145,175 @@ } ], "title": "spanner_v1_generated_database_admin_update_database_ddl_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient", + "shortName": "DatabaseAdminAsyncClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminAsyncClient.update_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "UpdateDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest" + }, + { + "name": "database", + "type": "google.cloud.spanner_admin_database_v1.types.Database" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_database" + }, + "description": "Sample for UpdateDatabase", + "file": "spanner_v1_generated_database_admin_update_database_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateDatabase_async", + "segments": [ + { + "end": 58, + "start": 27, + "type": "FULL" + }, + { + "end": 58, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 48, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 55, + "start": 49, + "type": "REQUEST_EXECUTION" + }, + { + "end": 59, + "start": 56, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_update_database_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient", + "shortName": "DatabaseAdminClient" + }, + "fullName": "google.cloud.spanner_admin_database_v1.DatabaseAdminClient.update_database", + "method": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase", + "service": { + "fullName": "google.spanner.admin.database.v1.DatabaseAdmin", + "shortName": "DatabaseAdmin" + }, + "shortName": "UpdateDatabase" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.spanner_admin_database_v1.types.UpdateDatabaseRequest" + }, + { + "name": "database", + "type": "google.cloud.spanner_admin_database_v1.types.Database" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_database" + }, + "description": "Sample for UpdateDatabase", + "file": "spanner_v1_generated_database_admin_update_database_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "spanner_v1_generated_DatabaseAdmin_UpdateDatabase_sync", + "segments": [ + { + "end": 58, + "start": 27, + "type": "FULL" + }, + { + "end": 58, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 48, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 55, + "start": 49, + "type": "REQUEST_EXECUTION" + }, + { + "end": 59, + "start": 56, + "type": "RESPONSE_HANDLING" + } + ], + "title": "spanner_v1_generated_database_admin_update_database_sync.py" } ] } diff --git a/samples/generated_samples/snippet_metadata_google.spanner.admin.instance.v1.json b/samples/generated_samples/snippet_metadata_google.spanner.admin.instance.v1.json index ef55b568ac..9572d4d727 100644 --- a/samples/generated_samples/snippet_metadata_google.spanner.admin.instance.v1.json +++ b/samples/generated_samples/snippet_metadata_google.spanner.admin.instance.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-spanner-admin-instance", - "version": "3.33.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.spanner.v1.json b/samples/generated_samples/snippet_metadata_google.spanner.v1.json index afcec7443d..a8e8be3ae3 100644 --- a/samples/generated_samples/snippet_metadata_google.spanner.v1.json +++ b/samples/generated_samples/snippet_metadata_google.spanner.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-spanner", - "version": "3.33.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_async.py b/samples/generated_samples/spanner_v1_generated_database_admin_update_database_async.py similarity index 100% rename from owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_async.py rename to samples/generated_samples/spanner_v1_generated_database_admin_update_database_async.py diff --git a/owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_sync.py b/samples/generated_samples/spanner_v1_generated_database_admin_update_database_sync.py similarity index 100% rename from owl-bot-staging/spanner_admin_database/v1/samples/generated_samples/spanner_v1_generated_database_admin_update_database_sync.py rename to samples/generated_samples/spanner_v1_generated_database_admin_update_database_sync.py diff --git a/scripts/fixup_spanner_admin_database_v1_keywords.py b/scripts/fixup_spanner_admin_database_v1_keywords.py index ad31a48c81..b358554082 100644 --- a/scripts/fixup_spanner_admin_database_v1_keywords.py +++ b/scripts/fixup_spanner_admin_database_v1_keywords.py @@ -57,6 +57,7 @@ class spanner_admin_databaseCallTransformer(cst.CSTTransformer): 'set_iam_policy': ('resource', 'policy', 'update_mask', ), 'test_iam_permissions': ('resource', 'permissions', ), 'update_backup': ('backup', 'update_mask', ), + 'update_database': ('database', 'update_mask', ), 'update_database_ddl': ('database', 'statements', 'operation_id', ), } diff --git a/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py b/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py index bba6dcabe8..497ab9e784 100644 --- a/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py +++ b/tests/unit/gapic/spanner_admin_database_v1/test_database_admin.py @@ -1413,6 +1413,8 @@ def test_get_database(request_type, transport: str = "grpc"): version_retention_period="version_retention_period_value", default_leader="default_leader_value", database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + enable_drop_protection=True, + reconciling=True, ) response = client.get_database(request) @@ -1428,6 +1430,8 @@ def test_get_database(request_type, transport: str = "grpc"): assert response.version_retention_period == "version_retention_period_value" assert response.default_leader == "default_leader_value" assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.enable_drop_protection is True + assert response.reconciling is True def test_get_database_empty_call(): @@ -1470,6 +1474,8 @@ async def test_get_database_async( version_retention_period="version_retention_period_value", default_leader="default_leader_value", database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + enable_drop_protection=True, + reconciling=True, ) ) response = await client.get_database(request) @@ -1486,6 +1492,8 @@ async def test_get_database_async( assert response.version_retention_period == "version_retention_period_value" assert response.default_leader == "default_leader_value" assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.enable_drop_protection is True + assert response.reconciling is True @pytest.mark.asyncio @@ -1636,6 +1644,243 @@ async def test_get_database_flattened_error_async(): ) +@pytest.mark.parametrize( + "request_type", + [ + spanner_database_admin.UpdateDatabaseRequest, + dict, + ], +) +def test_update_database(request_type, transport: str = "grpc"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_database), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.update_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.UpdateDatabaseRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_database_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_database), "__call__") as call: + client.update_database() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.UpdateDatabaseRequest() + + +@pytest.mark.asyncio +async def test_update_database_async( + transport: str = "grpc_asyncio", + request_type=spanner_database_admin.UpdateDatabaseRequest, +): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_database), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.update_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == spanner_database_admin.UpdateDatabaseRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_database_async_from_dict(): + await test_update_database_async(request_type=dict) + + +def test_update_database_field_headers(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.UpdateDatabaseRequest() + + request.database.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_database), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "database.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_database_field_headers_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = spanner_database_admin.UpdateDatabaseRequest() + + request.database.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_database), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.update_database(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "database.name=name_value", + ) in kw["metadata"] + + +def test_update_database_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_database), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_database( + database=spanner_database_admin.Database(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = spanner_database_admin.Database(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_database_flattened_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_database( + spanner_database_admin.UpdateDatabaseRequest(), + database=spanner_database_admin.Database(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_database_flattened_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_database), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_database( + database=spanner_database_admin.Database(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].database + mock_val = spanner_database_admin.Database(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_database_flattened_error_async(): + client = DatabaseAdminAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_database( + spanner_database_admin.UpdateDatabaseRequest(), + database=spanner_database_admin.Database(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + @pytest.mark.parametrize( "request_type", [ @@ -6991,6 +7236,8 @@ def test_get_database_rest(request_type): version_retention_period="version_retention_period_value", default_leader="default_leader_value", database_dialect=common.DatabaseDialect.GOOGLE_STANDARD_SQL, + enable_drop_protection=True, + reconciling=True, ) # Wrap the value into a proper Response obj @@ -7010,6 +7257,8 @@ def test_get_database_rest(request_type): assert response.version_retention_period == "version_retention_period_value" assert response.default_leader == "default_leader_value" assert response.database_dialect == common.DatabaseDialect.GOOGLE_STANDARD_SQL + assert response.enable_drop_protection is True + assert response.reconciling is True def test_get_database_rest_required_fields( @@ -7242,6 +7491,357 @@ def test_get_database_rest_error(): ) +@pytest.mark.parametrize( + "request_type", + [ + spanner_database_admin.UpdateDatabaseRequest, + dict, + ], +) +def test_update_database_rest(request_type): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # send a request that will satisfy transcoding + request_init = { + "database": {"name": "projects/sample1/instances/sample2/databases/sample3"} + } + request_init["database"] = { + "name": "projects/sample1/instances/sample2/databases/sample3", + "state": 1, + "create_time": {"seconds": 751, "nanos": 543}, + "restore_info": { + "source_type": 1, + "backup_info": { + "backup": "backup_value", + "version_time": {}, + "create_time": {}, + "source_database": "source_database_value", + }, + }, + "encryption_config": {"kms_key_name": "kms_key_name_value"}, + "encryption_info": [ + { + "encryption_type": 1, + "encryption_status": { + "code": 411, + "message": "message_value", + "details": [ + { + "type_url": "type.googleapis.com/google.protobuf.Duration", + "value": b"\x08\x0c\x10\xdb\x07", + } + ], + }, + "kms_key_version": "kms_key_version_value", + } + ], + "version_retention_period": "version_retention_period_value", + "earliest_version_time": {}, + "default_leader": "default_leader_value", + "database_dialect": 1, + "enable_drop_protection": True, + "reconciling": True, + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + response = client.update_database(request) + + # Establish that the response is the type that we expect. + assert response.operation.name == "operations/spam" + + +def test_update_database_rest_required_fields( + request_type=spanner_database_admin.UpdateDatabaseRequest, +): + transport_class = transports.DatabaseAdminRestTransport + + request_init = {} + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson( + pb_request, + including_default_value_fields=False, + use_integers_for_enums=False, + ) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_database._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_database._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("update_mask",)) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "patch", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + response = client.update_database(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_update_database_rest_unset_required_fields(): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.update_database._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("updateMask",)) + & set( + ( + "database", + "updateMask", + ) + ) + ) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_database_rest_interceptors(null_interceptor): + transport = transports.DatabaseAdminRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.DatabaseAdminRestInterceptor(), + ) + client = DatabaseAdminClient(transport=transport) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.DatabaseAdminRestInterceptor, "post_update_database" + ) as post, mock.patch.object( + transports.DatabaseAdminRestInterceptor, "pre_update_database" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + pb_message = spanner_database_admin.UpdateDatabaseRequest.pb( + spanner_database_admin.UpdateDatabaseRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = Response() + req.return_value.status_code = 200 + req.return_value.request = PreparedRequest() + req.return_value._content = json_format.MessageToJson( + operations_pb2.Operation() + ) + + request = spanner_database_admin.UpdateDatabaseRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + + client.update_database( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + + +def test_update_database_rest_bad_request( + transport: str = "rest", request_type=spanner_database_admin.UpdateDatabaseRequest +): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # send a request that will satisfy transcoding + request_init = { + "database": {"name": "projects/sample1/instances/sample2/databases/sample3"} + } + request_init["database"] = { + "name": "projects/sample1/instances/sample2/databases/sample3", + "state": 1, + "create_time": {"seconds": 751, "nanos": 543}, + "restore_info": { + "source_type": 1, + "backup_info": { + "backup": "backup_value", + "version_time": {}, + "create_time": {}, + "source_database": "source_database_value", + }, + }, + "encryption_config": {"kms_key_name": "kms_key_name_value"}, + "encryption_info": [ + { + "encryption_type": 1, + "encryption_status": { + "code": 411, + "message": "message_value", + "details": [ + { + "type_url": "type.googleapis.com/google.protobuf.Duration", + "value": b"\x08\x0c\x10\xdb\x07", + } + ], + }, + "kms_key_version": "kms_key_version_value", + } + ], + "version_retention_period": "version_retention_period_value", + "earliest_version_time": {}, + "default_leader": "default_leader_value", + "database_dialect": 1, + "enable_drop_protection": True, + "reconciling": True, + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + client.update_database(request) + + +def test_update_database_rest_flattened(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = { + "database": {"name": "projects/sample1/instances/sample2/databases/sample3"} + } + + # get truthy value for each flattened field + mock_args = dict( + database=spanner_database_admin.Database(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + + client.update_database(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{database.name=projects/*/instances/*/databases/*}" + % client.transport._host, + args[1], + ) + + +def test_update_database_rest_flattened_error(transport: str = "rest"): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_database( + spanner_database_admin.UpdateDatabaseRequest(), + database=spanner_database_admin.Database(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +def test_update_database_rest_error(): + client = DatabaseAdminClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + @pytest.mark.parametrize( "request_type", [ @@ -12215,6 +12815,7 @@ def test_database_admin_base_transport(): "list_databases", "create_database", "get_database", + "update_database", "update_database_ddl", "drop_database", "get_database_ddl", @@ -12536,6 +13137,9 @@ def test_database_admin_client_transport_session_collision(transport_name): session1 = client1.transport.get_database._session session2 = client2.transport.get_database._session assert session1 != session2 + session1 = client1.transport.update_database._session + session2 = client2.transport.update_database._session + assert session1 != session2 session1 = client1.transport.update_database_ddl._session session2 = client2.transport.update_database_ddl._session assert session1 != session2